abennett10
asked on
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!
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!
ASKER
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.
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.
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
select max(printer_number_field) as maxnum from table
then po01palp & dataset("maxnum")+1 will be your printer name
ASKER
Is it possible for you to write that sql query out so I can see exactly how the syntax should look ?
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!