random number generator

11-21-2001, 12:13 PM
how can u set a random value to your variables?

11-21-2001, 12:54 PM
have a lok in the tutors corner for a tutorial by billsoo about random numbers

11-21-2001, 01:29 PM
Try this code. It will put a number between 1 and 6 into the variable myInt.

Dim myInt as Integer

Randomize 'You only need to put this in your code once
myInt = int(rnd()*6)+1

11-21-2001, 01:55 PM
Actually, that will put a number between 1 and 7 in the variable... Here is a function I posted in another thread:<pre><font color=blue>Public Function</font color=blue> RndNumber(iLower <font color=blue>As Double</font color=blue>, iUpper <font color=blue>As Double</font color=blue>) <font color=blue>As Double</font color=blue>
RndNumber = (Rnd * (iUpper - iLower)) + iLower
<font color=blue>End Function</font color=blue></pre>

11-21-2001, 04:04 PM
That's a pretty useful function. Also, to generate numbers from, say, 10 to 100, you would do something like

<pre>Private Sub Command1_Click()
MsgBox Rnd * 90 + 10
End Sub </pre>


11-21-2001, 04:08 PM
That's exactly what Volteface's code does?!?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum