Make your own free website on Tripod.com

Generate Random Numbers

'Add 1 CommandButton and 1 TextBox to your form.
'Insert the following code to your form:

Private Sub Command1_Click()
Dim MyNumber As Integer
Randomize
'This Example will generate random number between 1 and 10.
'If you want to generate random number between 1 and 100, replace the '10' below
'with '100'.
'Explanation: (X * Rnd) generate random number between 0 and X-1.
'So if you place '+1' after the '(X * Rnd)' (like in the sample below),
'it will generate number between 0+1 to X-1+1. In other words: between 1 to X.

MyNumber = (10 * Rnd) + 1
Text1.Text = MyNumber
End Sub

Go Back