always1210
asked on
No Duplicate records VB 6.0
What statement can I use so duplicate numbers wont show up in labels
Private Sub Command1_Click(Index As Integer)
Label12.Caption = Int((Rnd * 39) + 1)
Label14.Caption = Int((Rnd * 39) + 1)
Label15.Caption = Int((Rnd * 39) + 1)
Label16.Caption = Int((Rnd * 39) + 1)
Label17.Caption = Int((Rnd * 39) + 1)
Beep
End Sub
Thanks
Private Sub Command1_Click(Index As Integer)
Label12.Caption = Int((Rnd * 39) + 1)
Label14.Caption = Int((Rnd * 39) + 1)
Label15.Caption = Int((Rnd * 39) + 1)
Label16.Caption = Int((Rnd * 39) + 1)
Label17.Caption = Int((Rnd * 39) + 1)
Beep
End Sub
Thanks
Put Randomize in your form load event or some place else.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In order to make sure your labels all have different random numbers in them, which I think is what you want, try this:
Dim array(39) as integer
Dim i as integer
Dim swap as integer
Dim temp as integer
for i = 1 to 39
array(i) = i
next i
for i = 1 to 39
swap = int(rnd * 39) + 1
temp = array(swap)
array(swap) = array(i)
array(i) = temp
next i
You then fill the labels from the first few elements of array(), which should be randomised. If you want to increase the randomisation, run the second loop more than once (e.g. enclose it in another FOR...NEXT loop). This method guarantees you won't get duplicate numbers in your captions.
Dim array(39) as integer
Dim i as integer
Dim swap as integer
Dim temp as integer
for i = 1 to 39
array(i) = i
next i
for i = 1 to 39
swap = int(rnd * 39) + 1
temp = array(swap)
array(swap) = array(i)
array(i) = temp
next i
You then fill the labels from the first few elements of array(), which should be randomised. If you want to increase the randomisation, run the second loop more than once (e.g. enclose it in another FOR...NEXT loop). This method guarantees you won't get duplicate numbers in your captions.
Or a startup: Use the Randomize statement !
RoverM