Can any body give me the code that will create a six digit random number....and place it in a text box
The number must be random everytime the button is clicked??
I code some stuff but it says overflow!!!
Cheers
Rhys
Printable View
Can any body give me the code that will create a six digit random number....and place it in a text box
The number must be random everytime the button is clicked??
I code some stuff but it says overflow!!!
Cheers
Rhys
To get a random number between two numbers use the formula
in this case you want a random six digit number so the upper bound is 999999 and the lower bound is 100000.Code:Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Code:Text1.Text = Int((999999 - 100000 + 1) * Rnd + 100000)
I guess you're using short integers or something. Maybe try longs? If you're already doing that, then you could make 6 random numbers between 0-9 and then stick em together, and put the string in a text box. Something like this (can't remember some of it and I don't have VB here at work):
Dammit I'm rusty at this. We do C and Pascal at uni, and I haven't done this kinda thing for a while. Can't guarantee those functions are right, but try it maybe?Code:dim numstring as string
dim numbers(5) as byte
numstring = str(int(rnd * 9 + 1)) ' need at least 1 for a 6 digit number
for x = 2 to 6
numbers(x) = int(rnd * 10) 'Check syntax, I can't quite remember
numstring = numstring & str(numbers(x))
next x
text1.text = numstring
thanx I have done it now...I put the Randomize function in front of the first reply and now every time the form loads the number is different...
cheers
Rhys