Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing an array into a module subprocedure

Status
Not open for further replies.

STPMB

Programmer
Sep 13, 2002
28
0
0
US
Hello,

I am having trouble passing a control array into a sub procedure contained in a module. I am getting a combile error 'ByRef argument type mismatch error.

I have code similar to below.

In the main form:
DIM modmanfields(7) as Control
Call subprocedure(arg1,arg2,arg3) 'where arg2 is the array being passed into the subprocedure.

in the subprocedure module:
the subprocedure is defined as
Public sub(arg1, arg2 as Containedcontrols, arg3)

Appreciate any comments.

 
that wroks fine now I am having trouble loading the array with the control name. When i use the set command with the control name the array is being filled with the control value not the actual name. What's the method used to load the array with a control name so that the subprocedure knows the parm is a control.
 
If you want the arg2 paramater to be an array of controls, then you need to load the CONTROLS into the array and not the NAME of the controls. So do something like this. This will list out the names of each control on the form.

Private Sub cmdDoit_Click()

Dim s() As Control
Dim n As Integer
Dim sControl As Control

n = 0
For Each sControl In Me.Controls
ReDim Preserve s(n)
Set s(n) = sControl
n = n + 1
Next

Debug.Print Me.Controls.Count
Call ShowIt(s())

End Sub


Sub ShowIt(s() As Control)

Dim n As Integer

For n = LBound(s) To UBound(s)
Debug.Print s(n).Name
Next

End Sub

This should give you an idea of how to do what you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top