Jump to content

Local Variable: Difference between revisions

From LabVIEW Wiki
Ederson (talk | contribs)
No edit summary
Ederson (talk | contribs)
Line 16: Line 16:
Using ''Local Variables'' breaks data flow execution. It is useful when it is not possible to pass data through wires, like parallel processes. In this case, the use of ''Local variables'' can be a solution. However, you should be careful when using this resource because it can generate unexpected behavior when you write values in multiple places in your code.  
Using ''Local Variables'' breaks data flow execution. It is useful when it is not possible to pass data through wires, like parallel processes. In this case, the use of ''Local variables'' can be a solution. However, you should be careful when using this resource because it can generate unexpected behavior when you write values in multiple places in your code.  
A good rule to follow when you use ''Local Variable'' is: ''One Write, Multiple Reads''.
A good rule to follow when you use ''Local Variable'' is: ''One Write, Multiple Reads''.
Example of avoiding Local Variables:
If you have a State Machine design pattern and lots of Local Variables being read and written through the Cases is: ''Change local variables instances for a wire using a Shift Register to update the value when is necessary''. See the picture below:
[[File:Local2.png|thumb|left|891x367px]]


== History ==
== History ==

Revision as of 23:14, 25 July 2023

Object information
Owning palette(s) Structures palette
Type Function
Requires Basic Development Environment
Icon

Use Local Variables to read or write to one of the Controls or Indicators on the Front Panel of a VI.

Usage

Stopping both parallel loops using the same Stop Button.

It is necessary to change Stop Button Control mechanical action from Latch... to Switch...

Best practice

Using Local Variables breaks data flow execution. It is useful when it is not possible to pass data through wires, like parallel processes. In this case, the use of Local variables can be a solution. However, you should be careful when using this resource because it can generate unexpected behavior when you write values in multiple places in your code. A good rule to follow when you use Local Variable is: One Write, Multiple Reads.

Example of avoiding Local Variables: If you have a State Machine design pattern and lots of Local Variables being read and written through the Cases is: Change local variables instances for a wire using a Shift Register to update the value when is necessary. See the picture below:

History

Version Change(s)
LabVIEW 2018 More info to come.

See Also

https://labviewwiki.org/wiki/Race_condition

External Links