[RESOLVED] Passing Control Arrays
I have these five Sets of control arrays:
lblComponent() (0to3)
lblTheme() (0to2)
lblClock() (0to1)
lblClickWheel (only 1)
lblContacts() (0to1)
These are menu items, and I am moving these items from right to left and vice versa, so basically I am just using the Left, Right, Width and Visible properties. I am using a timer to move the items.
What I want to know is that is there any possible method to pass these control arrays (i.e their names, and the upper bound values). It would be a lot easier for me to be able to pass these control arrays and it would save me a lot of repetitive coding.
Thanx for your help in advance
Re: Passing Control Arrays
Do you want to pass the actual control arrays or just "their names, and the upper bound values"?
Re: Passing Control Arrays
If it's the former then you can perhaps build on this.
VB Code:
Private Sub Command1_Click()
MySub Text1 ' a control array
End Sub
Public Sub MySub(CtlArray As Variant)
MsgBox CtlArray.Count
End Sub
Re: Passing Control Arrays
I've always used Variant as MartinLiss showed.
Re: Passing Control Arrays
I want to pass the control arrays itself... Heres An Example
VB Code:
Private Sub tmrTimer_Timer()
Call Procedure(send all the members of a certain control array)
End Sub
Public Sub Procedure(lblLabel As Label)' Recieve All The Members of the Array
Dim intCount As Integer
For intCount = 1 to X 'The Upper Bound Value
lblLabel(intCount).Left = lblLabel.Left - 507
Next intCount
End Sub
The timer gets enabled when a command button is clicked.
The Question is, how do I send the name of the array and the number of members in the array. And how do I recieve it?
Re: Passing Control Arrays
Oh I actually used your procedure Martin and it worked out fine. I just added the following line to get the upperbound value
VB Code:
Dim intUB As Integer
intUB = CtlArray.Count - 1
Thanx a lot.
Re: [RESOLVED] Passing Control Arrays
You can also pass it as a String:
VB Code:
Option Explicit
Private Sub Command1_Click()
MySub "Label1" 'control array name...
End Sub
Private Sub MySub(sControl As String)
Dim N As Long
For N = Me.Controls(sControl).LBound To Me.Controls(sControl).UBound
Me.Controls(sControl)(N).Caption = N 'or something...
Next N
End Sub
Re: [RESOLVED] Passing Control Arrays
I would pass the control array As Object rather than As Variant