Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hey guys
I am having a problem with incrementing an invoice number in Visual Basic 6. The number has to automatically increment everytime the user clicks the new button and everytime the form loads. The invoice number is in the format 00/00000 . Is there any way i can do this without linking to a database?
Terry

Yes, create a file with either the last used or next to be used invoice number. Read the file, increment the number, use the number, save the number, or read, use, increment, save. Whichever method is the most convenient. Usually the data is eventually stored in a database, so why not use it as the last used?

Hi wizard-fred
The problem I have is loading data when the form opens. I would like to know how to load the last saved data on form load. I have already tried the method you suggested but I couldn't get the number to increment because it is in the format 00/00000. Everytime i try incrementing it, it goes to a whole number. The code i used is:
Private Sub cmdnew_Click()
Text1.Text = Val(Text1.Text) + 1
End Sub
Terry

In this case the number is actually stored as a string (two parts with delimiter).
Text1.Text = LEFT$(Text1.Text,3) + RIGHT$(STR$(VAL(RIGHT$(Text1.Text,5) + 1) + 100000), 5)The example assumes only the value of right 5 characters are incremented. The left 2 characters could be incremented by different rules.
Break The String Into 2 Parts
Save The left 3 character string.
Convert the right 5 characters to numeric
Add 1 to make the new number
Since we want 5 characters we need leading zero fill, so we add 100,000.
Convert to a string of the 5 rightmost characters.
Add the right string to the previously saved 3 character string.There may also be ways using a format$ or print using string.

Thanks. That worked wonderfully. However i still need a way to increment it on form load. I'm sorry but I'm a real noob in Visual Basic :)
Terry

Make it a routine called only on form load or when you need another. You might need a flag to keep track of the program mode you're in (add (need new number), change (no need for new number), delete (how do you handle deleted/voided entries), inquire/display (no change).

![]() |
Variable from a file?
|
can NT batch send key con...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |