We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Easiest way to generate a 6 digit random number

Medium Priority
413 Views
Last Modified: 2010-04-07
Looking for the easiest way to do this in vb6, thanks 8)
Comment
Watch Question

Commented:
Put a Text box and a command button on a form.  Paste following code into command button click.

Private Sub Command1_Click()
    Randomize (Rnd)
    Text1.Text = Format(Int(Rnd * 1000000), "000000")
End Sub

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
John Gates, CISSPLead IT Security Analyst, Global Threat Management
CERTIFIED EXPERT

Author

Commented:
I did some other things as the same numbers kept coming up in order...

Private Sub Command1_Click()
Dim k As Variant
Dim l As Variant
Dim dRandNumFull As Variant
Dim dRandNumDisplay As Variant
Dim i As Variant


For i = 1 To 1000

           Randomize (rnd)
             
            k = Date * Time * 10
                         
           dRandNumFull = Format(Int(k * rnd), "000000")
           
           dRandNumDisplay = dRandNumFull
           
          'MsgBox dRandNumDisplay
           
         Text1.Text = Text1.Text & dRandNumDisplay & vbCrLf

Next
         
           
End Sub

This gave the desired result!
Thanks for your help!!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.