Results 1 to 4 of 4

Thread: [RESOLVED] Newbie Question on Controls and variables

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    Resolved [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
    Last edited by Hack; Jan 16th, 2007 at 09:22 AM. Reason: Added [RESOLVED] to thread title and green "resolved" checkmark

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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:
    1. Private Sub Command1_Click()
    2. Dim i As Integer
    3.  
    4. On Error Resume Next
    5.  
    6.     For i = 1 To 3
    7.         Controls("Picture" & i).BackColor = Sqr(i * 777 ^ 3)
    8.     Next i
    9.  
    10. End Sub
    11.  
    12. 'OR
    13.  
    14. Private Sub Command1_Click()
    15. Dim ctl As Control, i As Integer
    16.  
    17. On Error Resume Next
    18.  
    19.     For Each ctl In Me.Controls
    20.         If TypeOf ctl Is PictureBox Then
    21.             ctl.BackColor = Sqr(i * 777 ^ 3)
    22.         End If
    23.         i = i + 1
    24.     Next ctl
    25.  
    26. End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    Re: Newbie Question on Controls and variables

    Thank you very much that worked great.

  4. #4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width