LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save a Global Variable programmatically

Hello,

Is it possible to save a Global variable vi programmatically?
I would like the next time my vi starts to restore the values saved at last
execution.
I could solve the problem by saving a file instead of a Global variable,
but I would like to know if it's possible to do it by using Global
variables.

Thanks
0 Kudos
Message 1 of 2
(3,562 Views)
I believe that it is possible to save your global values by invoking Make Current Values Default and then using the Save method with VI server. However, that approach will not work on a compiled executable. I'll leave it to someone else to lecture you on why you should mostly avoid global variables.

A good approach is to use a functional global (sometimes called a LabVIEW 2-style global). It consists of a subVI with a case structure inside a while loop with an uninitialized shift register. Create a typedef for all of your variables or just the ones you want to access with this subVI. Drop the typedef on the front panel twice, once as a control and once as an indicator. Create an enumerated type control with options such as Read, Write, Load, Save, etc.
The enum is wired to the case selector. The Read case simply contains a wire across to each node of the shift register. The write case takes the data control in and routes it to the right side of the shift register. The Load and Save cases contain (config) file operations. You get the picture. Look at www.openg.org for some good utilities for saving data structures to config files.

Daniel L. Press
PrimeTest Corp.
www.primetest.com
0 Kudos
Message 2 of 2
(3,561 Views)