06-07-2016 11:23 AM
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.
06-07-2016 11:38 AM
@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).
06-07-2016 11:44 AM
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!
06-07-2016 04:15 PM
I look forward to hearing this ...
Bob Schor
06-08-2016 03:45 AM - edited 06-08-2016 03:56 AM
@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.
06-08-2016 08:32 AM
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
06-10-2016 08:40 AM
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
06-10-2016 08:48 AM
There is always this thread with lots of examples of how to not use local variables.