How do you generate random numbers?

leroyw
08-30-2009, 06:05 PM
Ive got one button and one textbox. Whats the code so when you click the button a random number appears in the textbox?

one2fight4
08-30-2009, 06:48 PM
I think this is what your looking for :)


Private Sub Command1_Click()
Dim UpperLimit As Integer
Dim LowerLimit As Integer
UpperLimit = 100
LowerLimit = 1
Text1.Text = Rnd * (UpperLimit - LowerLimit) + LowerLimit
End Sub

fisolofee
08-30-2009, 08:30 PM
Don't forget to add "Randomize" at the beginning of your code, or else the same seed will be used to generate the random numbers, giving you the same set of results every time you run the program.

one2fight4
08-30-2009, 08:53 PM
Don't forget to add "Randomize" at the beginning of your code, or else the same seed will be used to generate the random numbers, giving you the same set of results every time you run the program.

whoops, forgot about that :eek:

add this to your Form_Load()


Randomize

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum