LabVIEW

cancel
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?

 

Thanks 

0 Kudos
Message 1 of 15
(11,792 Views)

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.

 

 

*************************************************
CLD
*************************************************
0 Kudos
Message 2 of 15
(11,780 Views)

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 GetVals.vi at the beginning of the VI, it will retrieve the last values and make them current.  Place SetVals.vi 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.

 

Caveats:

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
(11,757 Views)

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?

 

Thanks,

0 Kudos
Message 4 of 15
(11,750 Views)

Here is an article on how to create INI file.

*************************************************
CLD
*************************************************
0 Kudos
Message 5 of 15
(11,746 Views)

Darin,

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.

 

 

Thanks,

0 Kudos
Message 6 of 15
(11,733 Views)

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.

 

Thanks,

0 Kudos
Message 7 of 15
(11,730 Views)

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.

Regards
Guru (CLA)
0 Kudos
Message 8 of 15
(11,722 Views)

 


@ossoo wrote:

Darin,

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.

 

 

Thanks,


 

 

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:

 

TaggingSnippet.png

 

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
(11,717 Views)

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.

 

Thanks,

0 Kudos
Message 10 of 15
(11,660 Views)