• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Need help Generating numbers in sequential order from 01 to 99

Okay, here goes.....I apologize if this does not come out right.

I am creating a vb.net application that needs to auto-generate a name with a number on the end (po01palpXX)

XX-being the number that it must generate. The name represents a printer name for inventory purposes.

So everytime the submit button is pushed for a new inventory entry the printer name must generate a new number ie...01, then 02, then 03 etc.

Please help me!
0
abennett10
Asked:
abennett10
1 Solution
 
mdouganCommented:
Hi abennett10,

Does it have to keep the sequence number between one time you run the program and the next, or just while running the program once?

The key point being that if you need to maintain the sequence number from one day to the next or one session to the next, then you need to store the latest number somewhere... if you have a database handy, that's always a good place to store the number, otherwise, you can store it in a file either locally on the computer running your program... or, if that same program is run on multiple machines then it needs to be in a file that can be read by any machine on the network....
Cheers!
0
 
abennett10Author Commented:
Thanks for the Reply!

The sequence needs to keep the number between one time I run the program and the next and it will be stored in an Access database.
0
 
gangwischCommented:
you should just run a query on the access database saying:
select max(printer_number_field) as maxnum from table
then po01palp & dataset("maxnum")+1 will be your printer name
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
abennett10Author Commented:
Is it possible for you to write that sql query out so I can see exactly how the syntax should look ?
0
 
NetworkArchitekCommented:
Well, actually gangwisch's query is as simple as it needs to be. So just quickly, if your table is PRINTERS and the field with the number in it (I hope that you are storing the number as PK in its own field and the name in a different field in the same table) as a field caled "PRINT_NUM," then you can do something like this.

dim oCmd As OleDBCommand = New OleDBCommand ... '' yada yada, make the connection
oCmd.CommandText = "SELECT MAX(PRINT_NUM) FROM PRINTERS"

dim dr as OleDBDatareader = oCmd.ExecuteNonQuery()
oConn.open() '' Assume that is your connection name
dr.Read()

dim nextNum as integer =  CType(dr(PRINT_NUM), Integer)
oConn.Close()

'' I would probably seperate the name and the number with a dash so you don't need to worry about silly stuff but that's just  me. I would do it like:

dim strPrinterEntry =  "po01palp" & "-" & nextNum

Well, this is kind of pseudo-code, general idea, but I think it is somewhat clear. Hope this helps.

0
 
NetworkArchitekCommented:
well of course as Gangwisch pointed out my line should be changed to this:

dim nextNum as integer =  CType(dr(PRINT_NUM), Integer) + 1
 
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now