Results 1 to 6 of 6

Thread: How to generate numbers is sequential order

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2012
    Posts
    2

    How to generate numbers is sequential order

    Hi there guys, i need a code in Visual Basic 6 for a form which allows me to auto generate numbers in sequential order starting from 1 then 2 then 3 then 4 etc.

    Sorry if this was a repeated question but i'm new here and i need it for a job in my work.

    Thanks alot.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: How to generate numbers is sequential order

    Welcome to VBForums

    Thread moved from the 'CodeBank VB6' forum (which is for you to post working code examples, not questions) to the 'VB6 and earlier' forum

  3. #3
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: How to generate numbers is sequential order

    RPG

    At its most basic level, you could use a loop

    Code:
    Dim nBeg as Integer
    Dim nEnd as Integer
    Dim nSeq as Integer
    ' 1. define scope
    nBeg = 1
    nEnd = 4    
    ' 2. generate the sequential numbers
    For ii = nBeg to nEnd
        nSeq = nSeq + 1
    Next ii
    When nSeq is Dim'd, it's value is 0 (or more precisely, Empty).
    Thus, each iteration through the loop will increment its value by 1
    and produce the series ... 1 2 3 4

    Did you need something more "advanced"?

    Spoo

  4. #4
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: How to generate numbers is sequential order

    Build a form with a command button and a label. Then apply this code:
    Code:
    Dim MyNum As Long
    Private Sub Command1_Click()
    MyNum = MyNum + 1
    Label1.Caption = MyNum
    End Sub
    You can press the command button a couple of billion times or so.
    Doctor Ed

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to generate numbers is sequential order

    Code Doc, no offense, but the OP indicated to auto generate but your method requires user intervention.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: How to generate numbers is sequential order

    Quote Originally Posted by jmsrickland View Post
    Code Doc, no offense, but the OP indicated to auto generate but your method requires user intervention.
    Whoops! Sorry, I guess I missed the term, "Auto". OP did not indicate how fast he wanted the numbers to appear, nor did he say how many that he wanted to see.

    So, let's modify the code by adding a timer and let the computer show the sequential numbers with no intervention:
    Code:
    Dim MyNum As Long
    Private Sub Command1_Click()
    MyNum = MyNum + 1
    Label1.Caption = MyNum
    End Sub
    
    Private Sub Form_Load()
    Timer1.Interval = 200
    End Sub
    
    Private Sub Timer1_Timer()
    Command1.Value = True
    End Sub
    Cheers!
    Doctor Ed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width