LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you use local variables?

There is nothing wrong with local variables. They are a legitimate way  to manage certain UI related tasks (after all, they point to a front panel object!).

 

Most typically, they are used to programatically update front panel controls (e.g. to change the values based on the values of other controls, load values from a ini file on startup, etc.)

 

The focus is really the connection with the front panel. Local variables should not be used for all the things that should stay exclusively on the diagram, e.g. to "store" intermediary values of calculations using a local variable of a hidden control.

Message 11 of 18
(2,921 Views)

@Alexander_Sobolev wrote:

http://forums.ni.com/t5/LabVIEW/LabVIEW-proverbs/td-p/178657/page/22

 

The same applies to locals I think...

 


Since you brough that into the mix, I might as well give a shameless plug or two: A Look At Race Conditions

 

Also, for those who are coming to NI Week this year, I will be speaking on this subject (technically global variables, but same principles apply).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 12 of 18
(2,914 Views)

Great discussion so far -- you've all brought up some interesting points regarding local variables that I hadn't yet considered!

 

Feel free to keep posting up examples and use cases!

0 Kudos
Message 13 of 18
(2,908 Views)

I look forward to hearing this ...

 

Bob Schor

0 Kudos
Message 14 of 18
(2,873 Views)

@drjdpowell wrote:

@Bob_Schor wrote:

But then I thought, "This looks like putting a Max on a Control and coercing it to not get too big".


That only works in simple cases, where nothing else can affect the item of interest except the control.  In more complex cases, particularly once one has started to get separation between 'User Interface' and 'Business Model', and maybe have multiple UI components, it becomes much more valuable (and simpler) to have the UI 'view' the 'model'.


Here's a 6 minute youtube video on this that I did last year: The Controller-Model-View Principle.  I use a local variable at 3:20.

 

It's in the context of intercomunicating message-handling loops (Messenger Library), but the principle is widely applicable for when one thing uses another thing.  Such as when application code uses a 'driver', or a database, or software uses hardware.  

Message 15 of 18
(2,834 Views)

Very interesting video (I'm convinced of the utility of using Local Variables in this example).  Now that I know these videos are here, I'm likely to avail myself of more of them!  Thanks for posting.

 

Bob Schor

0 Kudos
Message 16 of 18
(2,810 Views)

Typically in an event structure where there's no risk of race conditions. If it's a simpler VI i can use Locals if i need information in several event cases. If it gets a little more complicated it gets bundled in a cluster and thrown around.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 17 of 18
(2,740 Views)

There is always this thread with lots of examples of how to not use local variables.

Message 18 of 18
(2,737 Views)