LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to declare a global variables that can be passed to other VI's?

I would like to use a variable that i can set the value and use it in a different VI. Any suggestions? Thanks
0 Kudos
Message 1 of 3
(2,939 Views)
Hello Papish,

in despite of the fact that purists doesn't like it, Global Variable exists in LabVIEW.
Just place a global variable from the Block Diagram palette => Structures => Global Variable, double click on it. Put on the front panel all controls you want. Then save it (like you does it for a VI).
Global Variable looks like a VI, but without block diagram.
To use it , right click on your variable in the block diagram,=> "select item" that you want to read or write.

Just be careful if you want to write it from several VIs at the same time: you may have to block the access (with a semaphore for example)during this operation, as you would have to do it if you would like to write data in a file from several VIs at the same time.
0 Kudos
Message 2 of 3
(2,939 Views)
The best approach is to use what is often referred to as a functional global or LV2 style global. A functional global is essentially a non-reentrant vi with a single cycle loop containing data in unititialized shift registers. There is a read case and a write case within the vi. The primary advantage of the LV2 global over regular global variables is that you don't have to worry about synchronization of the code. Since the vi is not reentrant, you cannot be reading from and writing to the global at the same time. A good functional global example can be found at:

http://sine.ni.com/apps/we/niepd_web_display.DISPLAY_EPD4?p_guid=B45EACE3DB4956A4E034080020E74861&p_node=174821&p_submitted=N&p_rank=&p_answer=&p_source=External
Message 3 of 3
(2,939 Views)