Posts: 18
Threads: 4
Joined: Aug 2012
Reputation:
0
i just wanna ask how to code an auto-numbering?
lets just say it start at 000000 and then if you add another the counter add by 1.. how can i do that? and how
to know where the counter stops? so that it doesnt back to 000000.
Posts: 1,006
Threads: 111
Joined: Jul 2010
Reputation:
1
Are you trying to add 1 to a variable? To a textbox text field? To a label?
Posts: 18
Threads: 4
Joined: Aug 2012
Reputation:
0
im trying to add 1 in the variable.
let say.. the last added value is 10003 and then if
i add another entry the data or code should know that the last added value is 10003 so that when i added another entry the variable counter should be 10004..
Posts: 1,006
Threads: 111
Joined: Jul 2010
Reputation:
1
Well, first of all, you would need an integer variable to keep track of the number, so we can do this with something like this:
[code2=vbnet]Private Counter As Integer = 0[/code2]
Then, Every time we need to increment the variable, we can do so with:
[code2=vbnet]Counter += 1[/code2]
However, when we display the variable to the user, we would like it to be in the proper format. Since your number is 6 characters long, we pad left by 6 characters and fill any empty spots with 0s. Like so,
[code2=vbnet]Dim cString As String
cString = Counter.ToString.PadLeft(6, "0"c)[/code2]
Hopefully this helps.