11-13-2007 10:29 AM
11-13-2007 10:32 AM
I personally try not to use either. if I need to I will use the Local Variables and do it at a bare minimum in my code. instead of Global variables I create Functional Global variables and use them instead of the LV supplied Global Variables
this might help:
http://zone.ni.com/devzone/cda/epd/p/id/3124
11-13-2007 10:32 AM
11-13-2007 10:36 AM
11-13-2007 10:44 AM
11-13-2007 10:48 AM
If you want to create a lot of trouble for yourself and any programmer who maintains your code, then you should use many local and global variables.
If you want to create code that's efficient and easily maintained, use wires. You can of course, write horrible (messy) code with wires too. But at least you won't waste time troubleshooting "race" conditions that are nearly impossible to find.
There are many style guides and other resources on this website. Look for them, and spend a little time planning your code. Your code will be cleaner, run faster, and easier to fix.
I've written LabVIEW code for about 10 years and never used a global variable. I use "functional globals" defined in state machines with controlled access. Sometimes locals are unavoidable and sometimes globals are useful. That's why LabVIEW has them. But they should be used as part of an overall plan. "Planning to use globals or locals" is not a plan by my definition.
11-13-2007 11:02 AM
blue silver wrote:
I want to use variables instead of wires , which one you suggest , local or global variables? and why ?
... it's an evil cycle!. 🙂
Why do you think you need local and global variables?
If you "want" to use them, you are probably misguided. Typically, you should only use them if you "need" to! 😄 There are legitimate uses for them.
11-13-2007 11:05 AM - edited 11-13-2007 11:05 AM
Here is a way to have local variables in wires. Use a cluster to hold all your local variables, then use Unbundle to read them and Bundle to write to them.

11-13-2007 11:16 AM
Tbob,
This is a useful techniques, but you should not call any of it "local variables". That term is already taken! 😄
11-13-2007 03:29 PM