Easy random list thing --->
How do you add a list of random numbers, say from 1 to 15, into a listbox without any repeats?
It's has been doing my head in big time!
Thank you for any advice...
But please hurry, as my head is going to implode soon!
Printable View
Easy random list thing --->
How do you add a list of random numbers, say from 1 to 15, into a listbox without any repeats?
It's has been doing my head in big time!
Thank you for any advice...
But please hurry, as my head is going to implode soon!
Here you go,
just make a list on a form.. and copy this!
Code:Private Sub Form_Load()
Dim Hist(14) As Integer
Dim cHist As Integer
Dim I As Integer
Dim C As Integer
Randomize
StartOver:
I = Int(Rnd * 13.99) + 1 'Will Select 1 - 14
For C = 0 To 14
If Hist(C) = I Then GoTo StartOver
Next
Hist(cHist) = I
cHist = cHist + 1
If cHist <> 14 Then
GoTo StartOver
Else
For C = 0 To 14
List1.AddItem Hist(C)
Next
End If
End Sub
'Code improved by vBulletin Tool (Save as...)