Valhalla Legends Forums Archive | Visual Basic Programming | Kinda like 'With'

AuthorMessageTime
111787
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

May 24, 2005, 8:33 PM
Networks
[quote author=111787 link=topic=11691.msg113622#msg113622 date=1116966838]
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


[/quote]

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.
May 24, 2005, 9:53 PM
JoeTheOdd
I get it. Nope.

[code]Text1.BackColor = vbWhite
Form1.BackColor = vbWhite
Label1.BackColor = vbWhite[/code]

Welcome, Nate, to Valhalla Legends forums!
May 24, 2005, 10:36 PM
111787
Its got to be possible, everything is possible.
May 24, 2005, 11:07 PM
UserLoser.
[quote author=Joe[x86] link=topic=11691.msg113634#msg113634 date=1116974163]
I get it. Nope.
[/quote]

[code]
    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
[/code]

You could also go further.

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

etc.
May 24, 2005, 11:31 PM
111787
Very much thanks, this is now what i have so far.  I put the error i get in as a comment.

[code]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[/code]
May 25, 2005, 12:22 AM
R.a.B.B.i.T
[quote author=111787 link=topic=11691.msg113622#msg113622 date=1116966838]
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


[/quote]Text1.BackColor = Form1.BackColor = Label1.BackColor = vbBlack
May 25, 2005, 11:00 PM

Search