Passing Control Arrays to Sub-Procedures 
Author Message
 Passing Control Arrays to Sub-Procedures

Hey ppl,

This may sound stupid, but I cannot remember how to pass a control array to
a sub-procedure in VB.  Could someone post an example of the Sub definition
and proc call please?  It would be appreciated.

Jud.



Mon, 04 Feb 2002 03:00:00 GMT  
 Passing Control Arrays to Sub-Procedures
It is very simple:
Argument(0)=1
Argument(1)=5
Argument(2)=2
Argument(3)=9
Test Argument()

Sub Test(Argument())
For I=0 to 3
    Debug.Print Argument(I)
Next I
End Sub

Etienne Charland

Quote:

> Hey ppl,

> This may sound stupid, but I cannot remember how to pass a control array to
> a sub-procedure in VB.  Could someone post an example of the Sub definition
> and proc call please?  It would be appreciated.

> Jud.



Mon, 04 Feb 2002 03:00:00 GMT  
 Passing Control Arrays to Sub-Procedures
Jud,

You need to use a variant as the control array argument in the subprocedure
or function header.

As an example, place some textboxes on a form.  The textboxes should all be
members of a control array.  Add a command button to the form.  In the
command button's click event, call a subprocedure named PrintText and pass
the subprocedure the control array of textboxes:

Private Sub Command1_Click()

    PrintText Text1()

End Sub

Create a subprocedure named PrintText that can accept the control array:

Private Sub PrintText(myControlArray As Variant)

Inside the subprocedure, loop through all the controls in the array,
displaying the text for each control in a message box:

    Dim counter As Long

    For counter = myControlArray.lbound To myControlArray.ubound
        MsgBox myControlArray(counter).Text
    Next counter

Hope this helps,

Kerry Moorman

Quote:

>Hey ppl,

>This may sound stupid, but I cannot remember how to pass a control array to
>a sub-procedure in VB.  Could someone post an example of the Sub definition
>and proc call please?  It would be appreciated.

>Jud.



Mon, 04 Feb 2002 03:00:00 GMT  
 Passing Control Arrays to Sub-Procedures
Etienne,

But the question was how to pass a control array to a subprocedure, not an
array.  To pass a control array, the argument in the subprocedure or
function header needs to be a variant.

Hope this helps,

Kerry Moorman

Quote:

>It is very simple:
>Argument(0)=1
>Argument(1)=5
>Argument(2)=2
>Argument(3)=9
>Test Argument()

>Sub Test(Argument())
>For I=0 to 3
>    Debug.Print Argument(I)
>Next I
>End Sub

>Etienne Charland


>> Hey ppl,

>> This may sound stupid, but I cannot remember how to pass a control array
to
>> a sub-procedure in VB.  Could someone post an example of the Sub
definition
>> and proc call please?  It would be appreciated.

>> Jud.



Mon, 04 Feb 2002 03:00:00 GMT  
 Passing Control Arrays to Sub-Procedures
Thanks for all the suggestions guys/gals, You have given me enough to work
with.

Jud

;+)



Mon, 04 Feb 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Passing an array to a Sub procedure

2. passing arrays to Sub procedures?

3. Passing control arrays to subs

4. Q: Passing first (original) element of a control array to a SUB

5. Help how to pass control arrays to sub ??

6. How to pass control arrays to subs

7. Passing an Array of Controls to a Sub

8. Pass control array to sub/function ?

9. Passing Control Array to a SUB/FUNCTION

10. Passing a control array to a procedure

11. Passing control arrays to procedures

12. How to pass a control array to a procedure or function

 

 
Powered by phpBB® Forum Software