Problem solve Get help with specific problems with your technologies, process and projects.

Create control array in a flash

This tip provides steps and code to create and access control arrays.

View member feedback to this tip.

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.

  1. Start a new VB project.
  2. Place a text box on the form.
  3. Name the text box as txtarray
  4. Set the Index property to 0
  5. Paste the following code into the Form, and run the program.


Code:

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


MEMBER FEEDBACK TO THIS TIP

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.


Dig Deeper on Win Development Resources

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

TheServerSide.com

Close