LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding new global variables

Solved!
Go to solution

I'm modifying some code that uses a several global variables located in a global vi folder. I'd like to add some more variables and potentially modify what exists and have them be located in the same globals vi. I can easily add a variable of the same type by copying and pasting a variable of the same type on the globals vi front panel, but I'm not sure to add variables of different types.

 

This post comes closest: http://forums.ni.com/t5/LabVIEW/how-to-associate-existing-global-variables/m-p/1079535/highlight/tru... but I didn't understand this line: 

  • Add FP items (there can be multiple items in a global variable VI)

 

I've read some of the warnings against using global variables as it may cause race conditions / lead to general unreadability. I'm curious to what is recommended if the global variables are used as constants that are set at the very beginning of the program. In general, my LabVIEW code gets pretty unreadable if I have lots of wires for all these constants. Is there something better?

 

Thanks!

Kristen

0 Kudos
Message 1 of 3
(2,483 Views)
Solution
Accepted by topic author kllurie

Hello kllurie,

 

The scenario you mentioned (using globals to replace duplicate constants) is probably the best use case for them- the issues with race conditions etc. arise when they're being used to stream data or in multiple writer scenarios.  Readability is perhaps a concern, as it's not immediately obvious what might be reading from or writing to a global when a wire would suffice.

 

As for modifying the globals vi, all you should need to do is drop front panel objects from the Controls Palette (right-click).

 

Regards,

 

 

Tom L.
0 Kudos
Message 2 of 3
(2,476 Views)

Oh! That was really simple. 

 

I appreciate the information on the best practice useage of globals.

 

Thanks!

Kristen

0 Kudos
Message 3 of 3
(2,470 Views)