[RESOLVED] I need to add a random number BETWEEN 10 - 30 to a List?
I need to add a random number BETWEEN 10 - 30 to a List?
How would I do this?
Re: I need to add a random number BETWEEN 10 - 30 to a List?
Randomize a value between 0 - 20 and add ten, then include this value into the listbox.
List1.AddItem (Fix(Rnd * 21) + 10)
Re: I need to add a random number BETWEEN 10 - 30 to a List?
You could try this.
VB Code:
Private Function RandomNum(ByVal Lowest As Long, ByVal Highest As Long) As Long
RandomNum = Int((Highest - Lowest) * Rnd + Lowest)
End Function
Private Sub Command1_Click()
list1.AddItem CStr(RandomNum(10, 30))
End Sub
Private Sub Form_Load()
Randomize
End Sub
Didn't test it but it should work.
Re: I need to add a random number BETWEEN 10 - 30 to a List?
Quote:
Originally Posted by Merri
Randomize a value between 0 - 20 and add ten, then include this value into the listbox.
List1.AddItem (Fix(Rnd * 21) + 10)
Yea or you could just do that. :o