10-25-2013 06:17 PM
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:
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
Solved! Go to Solution.
10-25-2013 06:49 PM
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,
10-25-2013 07:27 PM
Oh! That was really simple.
I appreciate the information on the best practice useage of globals.
Thanks!
Kristen