|
-
Apr 12th, 2000, 05:13 PM
#1
Thread Starter
Junior Member
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
-
Apr 12th, 2000, 05:26 PM
#2
Fanatic Member
To get a random number between two numbers use the formula
Code:
Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
in this case you want a random six digit number so the upper bound is 999999 and the lower bound is 100000.
Code:
Text1.Text = Int((999999 - 100000 + 1) * Rnd + 100000)
Iain, thats with an i by the way!
-
Apr 12th, 2000, 05:40 PM
#3
Frenzied Member
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):
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
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?
Harry.
"From one thing, know ten thousand things."
-
Apr 12th, 2000, 06:06 PM
#4
Thread Starter
Junior Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|