11-04-2016 04:52 AM
Hi,
How can I save the current value in Shift Register automaticly even if the application will be canceled.
The number is incrementing by 1 with every iteration and it has to continue also after canceling the program and starting it again. (f.e. for the firs time i want to save number 3, after cancel and running the program again it will continue with number 4,5...)
Thank you for your help
Solved! Go to Solution.
11-04-2016 05:02 AM - edited 11-04-2016 05:03 AM
Hi Alex,
How can I save the current value in Shift Register automaticly even if the application will be canceled.
The value will be saved in the shift register as long as the VI stays in memory. You can "cancel" the app as often as you want - as long as the VI stays in memory…
When the VI will get removed from memory you need to store the value in a file and load it when starting your app again - as any other app has to do too!
On your image: BMP files are banned from the forum for a good reason: their size! And it doesn't get converted to JPG by just renaming the file suffix! Use a tool to convert such images to REAL JPG or PNG formats! (Conversion to PNG reduces filesize from 271kB to 3kB!)
11-04-2016 05:17 AM
@GerdW wrote:
Hi Alex,
How can I save the current value in Shift Register automaticly even if the application will be canceled.
The value will be saved in the shift register as long as the VI stays in memory. You can "cancel" the app as often as you want - as long as the VI stays in memory…
[...]
Just for clarification purpose: Gerd's sentence refers to UNinitialized shift registers.
To be more exact: Gerd's sentence holds true for any shift register. However, before starting the loop interations, an initialized shift register will get a well-defined value whereas the UNinitialized shift register proceeds with the value written to it in the last execution.
In the hope to prevent confusions,
Norbert
11-04-2016 05:31 AM
I thought that using Shift register will save the latest value always if there is no inicialization as you mention in the first sentence but dont.
After cancelling the app it always start from 0 again.
Is then the storing and loading the value from the file the only option?
Its a banal code but i cant solve this small problem
11-04-2016 05:47 AM - edited 11-04-2016 05:48 AM
Hi Alex,
Is then the storing and loading the value from the file the only option?
When you want to store data for the next run of your executable you need to use some storage that will last: files are the perfect items to do so…
(You could use the Windows registry too, if this is easier for you.)
Its a banal code but i cant solve this small problem
Define a file path, read the file content, increment a counter, store the new value in the same file:
11-04-2016 05:49 AM
@Aleeex07 wrote:
[...]
After cancelling the app it always start from 0 again.
[...]
What does that sentence mean? You have a single VI with close to no code. I wouldn't call that VI an "app". So what is your "app" and what is "cancelling"?
Norbert
PS: Loading the VI in LV, running it (ctrl+r) and repeating to run the VI (again ctrl+r) increases the value as expected. You must NOT close the VI between runs.
11-04-2016 06:27 AM
For specification this is just a small part of code. The purpose of this is to save this number to the database as an ID because i´d like to insert a new row with this ID(myincrementingnumber) as a primary key to an existing table and at the same time create a new table with the same ID (the same number).
So each time a press a button (save to DB) some data with the incrementing ID number will be saved in a table and also one new table (table1 will be created)
When I push a button for the second time that will insert data to a second row (ID 2) and create a new table (table2).
Cancelling I mean close the whole application and after the next opening and running the vi it has to continue (ID3...table3)..
11-04-2016 07:19 AM
If this is a primary key in a database... why don't you use a database auto-incremented value and read that out for usage in the relating table?
Norbert
11-04-2016 07:38 AM
I´ve tried to set the auto-increment in DB, but when i access and insert rows to DB from labview, the ID numbers arent incrementing. The ID numbers are random, so I try to solve this problem only through Labview.
11-04-2016 07:47 AM
Auto-increment is a feature of the database. If the database provides that feature, it is a configuration setting of the table.
It seems that your primary key of the table is "Random ID or passed by parameter when writing a new record".
If you stick to that configuration (or the database does not support auto-incrementation), you have to create the counter with LV.
There are two professional options:
a) Read out the number of records of the primary table and use this as counter
b) Keep the counter 'backed up' in an external file just like Gerd proposed
Norbert