Acces control thru variable
Posted: 2002-06-01
By: ArchiveBot
Viewed: 69
Filed Under:
No attachments for this post
Be able to access multiple controls which require the same task with minimal code. Basically I wanted to be able to access controls without having to write numerous bits and peices to reach multiple controls with multiple forms and could not find what I needed so I decided to post. Here you are creating 2 control arrays with labels and all the code will demonstrate is randomly changeing the color of a randomly selected label.
This is my first post so if a bit lame hope you at least find it usefull.
Original Author: James Travis
Inputs
You need to create a form with the following items.
Timer1 Set Interval = 1000
Label1 (0 - 7) Control Array
Label2 (0 - 7) Control Array
Returns
None.
Side Effects
None.
Code
Private Sub Timer1_Timer()
Dim CtrlName As String, CtrlIdx As Integer
Dim ClrSlct As Integer, ClrSlcted As Long
Dim LblRow As Integer
Randomize
CtrlIdx = Rnd * 7
Randomize
ClrSlct = Rnd * 3
Select Case ClrSlct
Case 0
ClrSlcted = &HFF00& 'Green
Case 1
ClrSlcted = &HFF& 'Red
Case 2
ClrSlcted = &HFF0000 'Blue
Case 3
ClrSlcted = &HFFFF& 'Yellow
End Select
Randomize
LblRow = (Rnd * 1) + 1
CtrlName = "Label" & LblRow
Form1.Controls(CtrlName).Item(CtrlIdx).BackColor = ClrSlcted
End Sub
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.