In vb programs there are often controls arrays
such as command1(0),command1(1), command1(2)
and some code which reacts to specific index:
sub command1_click(index as integer)
if index =1 then
do something
else
do something else
end if
end sub
Ok I am looking for the way to create such controls array in VBA, to use
these kind of VB code in VBA projects .
I have tried to name a control command1(0) but it is not a valid name
how can I proceed to create these command(n) controls ?
Thank you for your knowledge
best regards
Howard Kaikow - 26 Feb 2005 10:48 GMT
VBA does not support control arrays.

Signature
http://www.standards.com/; See Howard Kaikow's web site.
>
> In vb programs there are often controls arrays
[quoted text clipped - 18 lines]
> Thank you for your knowledge
> best regards
Helmut Weber - 26 Feb 2005 13:37 GMT
Hi Herve,
this is an example for a workaraound
for creating arrays of controls, here for checkboxes:
Private Sub UserForm_Initialize()
' Count Optionbuttons
Dim oCnt As Control
Dim iCnt As Integer
For Each oCnt In Me.Controls
If TypeOf oCnt Is MSForms.OptionButton Then
iOpt = iOpt + 1
End If
Next
' create array of optionbuttons
ReDim ArrOpt(iOpt) As OptionButton
' assign each optionbutton
For Each oCnt In Me.Controls
If TypeOf oCnt Is MSForms.OptionButton Then
iCnt = iCnt + 1
Set ArrOpt(iCnt) = oCnt
' setting caption for testing
ArrOpt(iCnt).Caption = Format(iCnt, "Opt- 00")
End If
Next
End Sub
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Note, that the "for each loop" over all controls,
seemably, processes them in the order they were created.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Helmut Weber - 26 Feb 2005 13:53 GMT
<gr>
... example for optionsbuttons ...
of course
HW