devxlogo

Use a Variable When Loading Controls in A Control Array

Use a Variable When Loading Controls in A Control Array

Using a variable when loading a control in a control array simplifies the code and makes it run faster.
Example:
1) Create a new standard EXE project.
2) Add a Label to Form1.
3) Set the Index property of Label1 to 0.
4) Add a CommandButton to Form1.
5) Insert the following lines of code into Form1:

 Private Sub Command1_Click()Dim I As IntegerDim NewLabel As LabelDim LastLabel As Label    Set LastLabel = Label1(0)    For I = 1 To 9        Set NewLabel = Label1(I)        Load NewLabel        NewLabel.Move LastLabel.Left + LastLabel.Height, LastLabel.Top + LastLabel.Height        NewLabel.Visible = True        Set LastLabel = NewLabel    Next    End Sub

size=3>

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist