Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: 111787 on May 24, 2005, 03:33 PM

Title: Kinda like 'With'
Post by: 111787 on May 24, 2005, 03:33 PM
Any way to set a common Property to the same thing for a bunch of objects?

Example(I know this is not going to work but it is the easiest way of representing my inquiry)

With BackColor = vbWhite
text1
form1
label1
End With

Title: Re: Kinda like 'With'
Post by: Networks on May 24, 2005, 04:53 PM
Quote from: 111787 on May 24, 2005, 03:33 PM
Any way to set a common Property to the same thing for a bunch of objects?

Example(I know this is not going to work but it is the easiest way of representing my inquiry)

With BackColor = vbWhite
text1
form1
label1
End With



I don't think you can do that specfically but you can always loop through all the controls you want and place some error handling and set the backcolor to the ones you want or all to white. Or specfify which ones you don't want to change.
Title: Re: Kinda like 'With'
Post by: Joe[x86] on May 24, 2005, 05:36 PM
I get it. Nope.

Text1.BackColor = vbWhite
Form1.BackColor = vbWhite
Label1.BackColor = vbWhite


Welcome, Nate, to Valhalla Legends forums!
Title: Re: Kinda like 'With'
Post by: 111787 on May 24, 2005, 06:07 PM
Its got to be possible, everything is possible.
Title: Re: Kinda like 'With'
Post by: UserLoser. on May 24, 2005, 06:31 PM
Quote from: Joex86] link=topic=11691.msg113634#msg113634 date=1116974163]
I get it. Nope.


    Dim C As Control
    Dim F As Form
    For Each F In Forms
        F.BackColor = vbBlack
        For Each C In F
            C.BackColor = vbBlack
        Next C
    Next F
    Set C = Nothing
    Set F = Nothing


You could also go further.


            If (TypeOf C Is TextBox) Then
                C.BackColor = vbBlack
            ElseIf (TypeOf C Is Label) Then
                C.BackColor = vbRed
            End If


etc.
Title: Re: Kinda like 'With'
Post by: 111787 on May 24, 2005, 07:22 PM
Very much thanks, this is now what i have so far.  I put the error i get in as a comment.

Public Sub CommonProp(cpForm As Form, _
cpProperty As Variant, _
cpConstant As Variant, _
ParamArray cpObjects() As Variant)

    Dim C As Control
    Dim F As Form
    Dim x As Integer
   
    For Each F In Forms
        If F = cpForm Then          'Type Mismatch
            For Each C In F
                For x = LBound(cpObjects) To UBound(cpObjects)
                    If C.Name = cpObjects(x) Then
                        C.cpProperty = cpConstant      'I doubt that will work
                    End If
                Next x
            Next C
        End If
    Next F
   
    Set C = Nothing
    Set F = Nothing
   
End Sub

Title: Re: Kinda like 'With'
Post by: R.a.B.B.i.T on May 25, 2005, 06:00 PM
Quote from: 111787 on May 24, 2005, 03:33 PM
Any way to set a common Property to the same thing for a bunch of objects?

Example(I know this is not going to work but it is the easiest way of representing my inquiry)

With BackColor = vbWhite
text1
form1
label1
End With


Text1.BackColor = Form1.BackColor = Label1.BackColor = vbBlack