|
-
Feb 19th, 2013, 12:27 PM
#1
Thread Starter
New Member
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
-
Feb 19th, 2013, 12:36 PM
#2
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 -
-
Feb 19th, 2013, 12:41 PM
#3
Re: 6 digit Incremental Number
 Originally Posted by stanav
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.
-
Feb 19th, 2013, 02:46 PM
#4
Thread Starter
New Member
Re: 6 digit Incremental Number
 Originally Posted by dbasnett
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...
-
Feb 19th, 2013, 03:07 PM
#5
Re: 6 digit Incremental Number
 Originally Posted by TJJC88
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 -
-
Feb 19th, 2013, 03:10 PM
#6
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
 
-
Feb 19th, 2013, 03:12 PM
#7
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!
-
Feb 19th, 2013, 04:36 PM
#8
Thread Starter
New Member
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.
-
Feb 19th, 2013, 04:56 PM
#9
Re: 6 digit Incremental Number
 Originally Posted by TJJC88
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|