Showing results for 
Search instead for 
Did you mean: 

How to make a VI remember the latest control value?

The VI have a lot of numeric controls.


After you close the VI and re-open again, all the controls goes to the default value. I need to let the VI remember the latest value. Then the next time you re-open the VI, it shows the value when you close last time. How to do this?



0 Kudos
Message 1 of 15

The first approach can be to programatically set the value of the control as default value before closing the VI.

Secondly you can save the value of the controls in a INI file and then read it when the VI is opened again.

See if this post helps.



0 Kudos
Message 2 of 15

I do not do this that often, but here is a simplified pair of VIs I use to accomplish this task in a quick and dirty manner.  The problem with using the DefaultValues method is that the VI must be in Edit mode, so a VI can't do this to itself.  You can, however, read and write user tags so I use those.  Place at the beginning of the VI, it will retrieve the last values and make them current.  Place at the very end of the VI, this reads the current values, sets a tag containing those values and saves the VI.  Now these values can be retrieved the next time the VI is run.



Latching Booleans are not saved.

In this simple version I do all controls and indicators, potential for bloat if you have huge graphs, arrays, etc.  Easy modification, but I am trying to keep it simple.

The VI is saved when you run it, therefore any changes you make will be committed by running.  You have been warned.

I believe certain datatypes are not permitted as Tag Values, not a problem in most cases, and troublemakers should be ignored.


INI files are certainly a viable option, for my own use I prefer everything to be contained in the VI file.



Download All
Message 3 of 15

Sorry, I don't know how to save to a INI file. I never used this function before. Could you please give me some guide?



0 Kudos
Message 4 of 15

Here is an article on how to create INI file.

0 Kudos
Message 5 of 15


I do not quite understand these two VI. Do I need to modify it? Or just put one at the beginning and the other at the end. It seems dosen't work.




0 Kudos
Message 6 of 15

Hi Ivrat,

I have hundreds of numeric controls. By using this INI file, I need to write every value by using Write Key.Vi and read every value by using Read Key.Vi. Is that right? Like write and read one by one?


Is there a sinple way to this? Since the "Make current Value defaut" can not program. It can only be acheived manully in edit mode.



0 Kudos
Message 7 of 15

i would suggest to create a VI that will get the all the controls/indicators present in the FP (use the FP  method and list all the available controls) and based on the Label or caption (since you know which are all the control values that needs to be set to the required values) write the values to a simple file (may be by creating a cluster and then writing to a temp file) .


While loading the vi, read the same file and use the set control property to set the values for these controls.

Guru (CLA)
0 Kudos
Message 8 of 15


@ossoo wrote:


I do not quite understand these two VI. Do I need to modify it? Or just put one at the beginning and the other at the end. It seems dosen't work.






To see how these VIs work, just place them as is in a VI (make sure it is saved, will not work for unsaved VIs).


For example:




You can run the attached file, while it is running change the control values, then stop the VI.  While stopped, change the values again, and when you run, notice the previous values are restored.  (If you use the snippet above, save the VI first)

0 Kudos
Message 9 of 15

Hi Darin,

It seems doesn't work in my VI. I attached my VI in the attachment. Could you please help take a look?


I can not understand with your VI - GetValue and Set Value. If you can put some description, I'll appreciate a lot.



0 Kudos
Message 10 of 15