Need help Generating numbers in sequential order from 01 to 99

Posted on 2005-04-22
Last Modified: 2010-04-23
Okay, here goes.....I apologize if this does not come out right.

I am creating a 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!
Question by:abennett10
    LVL 18

    Expert Comment

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

    Author Comment

    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.
    LVL 10

    Expert Comment

    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

    Author Comment

    Is it possible for you to write that sql query out so I can see exactly how the syntax should look ?
    LVL 10

    Expert Comment

    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

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

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

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

    LVL 10

    Accepted Solution

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

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

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now