Link to home
Start Free TrialLog in
Avatar of Dovberman
DovbermanFlag for United States of America

asked on

How to Pass a Control Group as a Procedure Parameter

I have a group of picture controls and command buttons on a form.  I need to pass the control groups to a Sub or Function.

This is my code:

ScanGroup me.picCards(), me.cmdPickOne

Sub ScanGroup(ppicCards() as PictureBox, pcmdPickOne() as Control)

Dim intCtr1 as integer

For intCtr1 to ppicCards.Count - 1
      If ppicCards(intctr) = pintCritical Then  
                  'Do something
                  Exit For
     End If
Next intCtr1

For intCtr1 to pcmdPickOne.Count - 1
     If pcmdPickOne(intctr) = pintCritical Then  
                  'Do something
                  Exit For
     End If
Next intCtr1

When I try to compile, I get a type mismatch error.  This comes from an incorrect parameters statement.

I can pass arrays with no problem.
What is different about control groups?
What am I doing wrong ?

Thanks,

Dovberman
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dovberman

ASKER

Your solution works fine.  The key was to refer to the control and picture box as objects.

I do use Option Explicit in all my code. Not shown in the snippet.

Thanks for the prompt reply.

Dovberman