|
-
Nov 13th, 2002, 10:45 PM
#1
Thread Starter
New Member
This should be easy
i got 16 labels in a control array from 1 to 16, and i want the numbers 1 to 16 apear randomly in each one without any repetitions.
Could anyone help me do this? i always end up having a few empty labels and i dont know how to fix this.
-
Nov 13th, 2002, 10:57 PM
#2
Frenzied Member
this should work:
VB Code:
Private Sub Command1_Click()
Randomize
For i = Label1.LBound To Label1.UBound
Label1(i).Caption = "" 'empty all captions
Next
For i = Label1.LBound To Label1.UBound
ReRnd:
TempIndex = Round(Rnd * Label1.UBound) 'new random nr
If Label1(TempIndex).Caption = "" Then 'if caption is empty
Label1(TempIndex).Caption = i + 1 'fill it with nr
Else
GoTo ReRnd 'if caption is already filled, get a new label
End If
Next
End Sub
-
Nov 15th, 2002, 11:56 PM
#3
Frenzied Member
oh....your array is from 1-16....then you have to change the line
Label1(TempIndex).Caption = i + 1
to
Label1(TempIndex).Caption = i
-
Nov 15th, 2002, 11:59 PM
#4
Frenzied Member
oh, and you also have to change the line:
TempIndex = Round(Rnd * Label1.UBound)
to
TempIndex = Round(Rnd * (Label1.UBound - 1)) + 1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|