Creating an array of control may not be defined during design time, but can be implemented easily during run time. By performing the following set of steps and pasting the code that follows, you be able to create and access the control arrays as though they were created at design time.
This example creates an array of text boxes at runtime.
- Start a new VB project.
- Place a text box on the form.
- Name the text box as txtarray
- Set the Index property to 0
- Paste the following code into the Form, and run the program.
Private Sub Form_Load() Dim i As Integer txtArray(0).text = "TextBox 0" For i = 1 To 9 Load txtArray(i) With txtArray(i) .Text = "Text Box" & i .Visible = True .Top = txtArray(i - 1).Top + 550 End With Next i End Sub
It's a great tip for text boxes or labels, but how about for buttons or other controls that fire an event? Is there a simple solution like this one for those types of controls?
-- Jeff P.
Do you have comments of your own? Let us know.