Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Apr 24, 2001

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 Integer
Dim NewLabel As Label
Dim 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
Andreas Hillqvist
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap