Results 1 to 9 of 9

Thread: 6 digit Incremental Number

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    9

    6 digit Incremental Number

    Hi,

    I'm creating a form which spits out a .csv file which is then sent to the printer.

    I want to output a job number which increments everytime anyone presses the export button.

    The GUID is the only unique reference I can come up with which is not suitable.

    does anyone have any suggestions?

    Thanks

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: 6 digit Incremental Number

    Well, to increment a value you need to know what the value is originally, right? Thus, you will need to save that value somewhere that you can retrieve back. One way to do this is to store the latest value in my.settings.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: 6 digit Incremental Number

    Quote Originally Posted by stanav View Post
    Well, to increment a value you need to know what the value is originally, right? Thus, you will need to save that value somewhere that you can retrieve back. One way to do this is to store the latest value in my.settings.
    This assumes that the program is used on one computer only.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    9

    Re: 6 digit Incremental Number

    Quote Originally Posted by dbasnett View Post
    This assumes that the program is used on one computer only.
    this program will be used on multiple machines at the same time which makes it tricky...

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: 6 digit Incremental Number

    Quote Originally Posted by TJJC88 View Post
    this program will be used on multiple machines at the same time which makes it tricky...
    Then you will need a database (which is overkill to store a single value) or some kind of application/service to keep track of the value. A web service? Or a server application?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,039

    Re: 6 digit Incremental Number

    It makes it very tricky, as any such variable would be subject to race conditions. If you put the variable in a database, or even just a central file (if you need less security), then you would have to make sure that every process locked the record, read out the value, incremented the value, wrote in the new value, then unlocked the record.

    One thing you could do with a database would be to just write the correct kind of update statement that has a WHERE clause that updates only the record that has the value that you read from the database. Unfortunately, you'd get an exception if the record had been changed by a different process while you were updating it in the current process. Therefore, you'd have to trap the exception to catch the race condition, which is less than ideal.
    My usual boring signature: Nothing

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: 6 digit Incremental Number

    Then you'll need a datasource at network or web level.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    9

    Re: 6 digit Incremental Number

    I'm happy to use a central file which stores the number but don't know how to do it.

  9. #9
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: 6 digit Incremental Number

    Quote Originally Posted by TJJC88 View Post
    I'm happy to use a central file which stores the number but don't know how to do it.
    Without some control mechanism, you'd run into what known as race conditions. For example, the current value in the file is 1. Machine A reads that value in and before it can increment the value to 2 and saves it back, machine B reads in the value which is still 1. Now, both A and B has the updated value as 2 while it should've been 3... So using a central file alone won't provide you a reliable way to maintain the value accurately. Now, let's say you build a separate helper program that manages this value. Only this helper program has access to the file. The other program instances have to ask this helper program for the value when they need it. And since the helper program knows exactly when it gives out a number, it knows exactly when to increment the value.... This approach seems to work, but how do my program talks to this helper program? Well, the same way chat applications do... But wait, that is complicated to code and my program may not be able to connect to the helper program from home because I don't have a vpn.... Well, make the helper program accessible via the internet then... And now we're looking at building a web service...
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width