469,950 Members | 1,547 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

How can I generate Random numbers in a form

I would like to create a form where by clicking some where in the form it will generate a alphanumeric sequence. I want to generate random PIN numbers preceeded with specific letters. An example would be BW6666 or BW1234. Can anyone help?
Jun 14 '07 #1
3 4995
NeoPa
32,233 Expert Mod 16PB
Does the random part need to be a fixed length of four digits?
Jul 4 '07 #2
JKing
1,206 Expert 1GB
Here's a neat and somewhat simple way to achieve your desired results. Using some VBA you can easily generate a string in your format of BW0000.

Expand|Select|Wrap|Line Numbers
  1. Dim strPin As String
  2. Dim i As Integer
  3.  
  4. strPin = "BW"
  5.  
  6. 'Set seed
  7. Call Randomize
  8.  
  9. For i = 1 To 4
  10.    strPin = strPin & Int(10 * Rnd)
  11. Next
  12.  
Simply loops 4 times adding a random number between 0 and 9 to the string. Out of curiousity what is this going to be used for?
Jul 4 '07 #3
NeoPa
32,233 Expert Mod 16PB
Does the random part need to be a fixed length of four digits?
Assuming so, simply use :
Expand|Select|Wrap|Line Numbers
  1. 'BW' & Right(Format(Rnd() * 10000, '0000'), 4)
The Right(X, 4) bit is to ensure that a Rnd() value so close to 1 will not produce 10,000.
Jul 5 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Laphan | last post: by
6 posts views Thread by comp.lang.php | last post: by
12 posts views Thread by Jim Michaels | last post: by
9 posts views Thread by MyInfoStation | last post: by
15 posts views Thread by Orchid | last post: by
6 posts views Thread by Anamika | last post: by
20 posts views Thread by jjmillertime | last post: by
24 posts views Thread by pereges | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.