-
Apr 21st, 2012, 01:09 AM
#1
Thread Starter
New Member
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.
-
Apr 21st, 2012, 10:12 AM
#2
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
-
Apr 21st, 2012, 03:01 PM
#3
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
-
Apr 21st, 2012, 07:35 PM
#4
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.
-
Apr 23rd, 2012, 04:02 PM
#5
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.
-
Apr 23rd, 2012, 07:14 PM
#6
Re: How to generate numbers is sequential order
Originally Posted by jmsrickland
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|