[RESOLVED] Newbie Question on Controls and variables
Hail to All,
Ok here is what I am doing. lets say I have 10 picture controls on my form. I know I can create an array of the control but I was just wondering if this is possible.
I have 10 picture boxes. Picture1-Picture10. Could I put them in a loop somehow such as.
For I = 1 to 10
Picture(i).backcolor = X
Next I
Or
for I = 1 to 10
PicControl = "Picture"
PicControl = PicControl + I
PicControl.backcolor = X
Next I
Is there some way to do it this way? without having to create the array that it would but the value of the variable
Thanks for all your help.
Mythos44
Re: Newbie Question on Controls and variables
You will need to use controls collection but controls arrays are much easier to manage (disregard all math stuff - did it for a fun):
VB Code:
Private Sub Command1_Click()
Dim i As Integer
On Error Resume Next
For i = 1 To 3
Controls("Picture" & i).BackColor = Sqr(i * 777 ^ 3)
Next i
End Sub
'OR
Private Sub Command1_Click()
Dim ctl As Control, i As Integer
On Error Resume Next
For Each ctl In Me.Controls
If TypeOf ctl Is PictureBox Then
ctl.BackColor = Sqr(i * 777 ^ 3)
End If
i = i + 1
Next ctl
End Sub
Re: Newbie Question on Controls and variables
Thank you very much that worked great.
Re: Newbie Question on Controls and variables
OK, you're welcome! :wave: