Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Easiest way to generate a 6 digit random number

Posted on 2006-04-26
Medium Priority
Last Modified: 2010-04-07
Looking for the easiest way to do this in vb6, thanks 8)
Question by:John Gates, CISSP

Accepted Solution

frankd earned 2000 total points
ID: 16545691
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
LVL 18

Author Comment

by:John Gates, CISSP
ID: 16546097
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

End Sub

This gave the desired result!
Thanks for your help!!

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question