HI ...
I have 4 lbl`s in array and i need to insert to them
numbers from 0 to 3
And I want each time the numbers will appear in
diffrent lbl`s
and i dont want that one number will appear twice ..
10x in advance ...
Printable View
HI ...
I have 4 lbl`s in array and i need to insert to them
numbers from 0 to 3
And I want each time the numbers will appear in
diffrent lbl`s
and i dont want that one number will appear twice ..
10x in advance ...
Code:Dim intRandom As Integer
Dim colLabelIndex As New Collection
Dim intValue As Integer
' Make sure the order is different every time the numbers
' are generated
Randomize
' Ignore duplicate entries when the indexes are generated below
On Error Resume Next
' Create a collection of values from 0 to 3 which will be used as
' the indexes for the Label1 control array
Do Until colLabelIndex.Count = 4
intRandom = Int(4 * Rnd)
' CStr(intRandom) is the index TO THE COLLECTION and it must be unique. So
' if you are trying to add a duplicate, an error is generated which is
' ignored because of the On Error Resume Next statement
colLabelIndex.Add intRandom, CStr(intRandom)
Loop
' Write to the labels
For intValue = 0 To 4
Label1(colLabelIndex(intValue)) = intValue
Next