Computing.Net > Forums > Programming > Incrementing variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Incrementing variables

Reply to Message Icon

Name: terry_dz
Date: July 31, 2005 at 22:39:48 Pacific
OS: Microsoft Windows XP Prof
CPU/Ram: 1.8 GHz 128MB RAM
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: wizard-fred
Date: August 1, 2005 at 03:22:58 Pacific
Reply:

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?


0

Response Number 2
Name: terry_dz
Date: August 3, 2005 at 00:51:20 Pacific
Reply:

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


0

Response Number 3
Name: wizard-fred
Date: August 3, 2005 at 01:31:39 Pacific
Reply:

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.


0

Response Number 4
Name: terry_dz
Date: August 3, 2005 at 23:51:06 Pacific
Reply:

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


0

Response Number 5
Name: wizard-fred
Date: August 4, 2005 at 00:16:19 Pacific
Reply:

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).


0

Related Posts

See More



Response Number 6
Name: terry_dz
Date: August 15, 2005 at 22:22:21 Pacific
Reply:

Thanks a lot. I managed to do that. :)

Terry


0

Sponsored Link
Ads by Google
Reply to Message Icon

Variable from a file? can NT batch send key con...



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Incrementing variables

Visual Basic.NET increment variable www.computing.net/answers/programming/visual-basicnet-increment-variable/17031.html

another basic variable www.computing.net/answers/programming/another-basic-variable/18204.html

increment variable in batch files www.computing.net/answers/programming/increment-variable-in-batch-files/18213.html