Easiest way to generate a 6 digit random number

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

    Accepted Solution

    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 17

    Author Comment

    by:John Gates
    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    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…

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now