Results 1 to 4 of 4

Thread: [RESOLVED] Pass Control Array into Sub

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    169

    Resolved [RESOLVED] Pass Control Array into Sub

    Hi, I'm making my own Subroutine where I'm passing in a control array of pictureboxes but I'm lost as to how to do it. The picturebox name will change, I have many control arrays of pictureboxes on my form. I thought something like this.

    Code:
    Sub MySub(ByRef picBox1() as PictureBox)
        'Code
    End Sub
    and calling it like this:

    Code:
    For X = 1 to 4
        Call MySub(picBox1(X))
    Next X
    But that doesn't work...Anyone know how to do this?

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Pass Control Array into Sub

    the problem is, you are passing in a SINGLE picturebox.. not the array

    but i cant remember how to make the sub accept it.. unless its a variant

    VB Code:
    1. Sub MySub(pbx1 As Variant)
    2.     For x = 0 To pbx1.ubound
    3.         Debug.Print pbx1(x).Index
    4.     Next
    5. End Sub
    6.  
    7. Private Sub Command1_Click()
    8.     MySub Picture1
    9. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    169

    Re: Pass Control Array into Sub

    Thanks, that worked great!

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