Results 1 to 10 of 10

Thread: How do you pass an array of controls to a function?

  1. #1

    Thread Starter
    New Member Xenomech's Avatar
    Join Date
    Oct 2002
    Location
    Winnipeg, MB
    Posts
    8

    How do you pass an array of controls to a function?

    I don't recall ever having to do this before, but I'm trying to pass an array of optionbuttons to a function and I can't get it to work. Maybe I'm just retarded, but could someone please post the appropriate syntax for this? Thanks.

  2. #2
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Sadly you'll need to pass the array in as a variant:

    VB Code:
    1. Public Function TheFunction(Byval OptionButtons As Variant)
    2.  ' Hope and pray that the Variant is the array you're looking for
    3.  ' Error handling would be a good thing to have here
    4.  
    5.  OptionButtons(0).Value = True
    6. End Function
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  3. #3

    Thread Starter
    New Member Xenomech's Avatar
    Join Date
    Oct 2002
    Location
    Winnipeg, MB
    Posts
    8
    Sick. The one thing I didn't try.

  4. #4
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Except don't pass it ByVal (use ByRef instead)

  5. #5
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    You may also pass an Index.
    Roy

  6. #6
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    whats wrong with...

    VB Code:
    1. Private Sub F(OptionButtons() As OptionButton)
    2. End Sub
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  7. #7
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    That won't work because VB will expect an parameter to be passed (which can be done when you want to deal with the whole array).

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    If you want to pass your array ByRef you don't have to explicitly code that. ByRef is the default.

  9. #9
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Originally posted by Hack
    If you want to pass your array ByRef you don't have to explicitly code that. ByRef is the default.
    I know. But it's good practice to explicitly state what you're doing.

  10. #10
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Not necessary.
    Roy

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