From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Local variable writing to control

I am working on a user interface where I would like to load some settings from a configuration file and write them to some front panel controls when the program starts.  I would also like to be able to edit the settings and then write them back to the config file.  I can get everything to work great by grabbing my settings and then writing them to local variables of my controls.  This is done outside of my main while loop when the program starts.  I then use my controls to edit and save them back to the config file.  I guess I don't really have a problem, but I keeping reading on here that local variables are bad and that you should avoid using them.  Is there a better way to do this without using local variables?
0 Kudos
Message 1 of 19
(4,197 Views)
That's a perfectly legitimate use of local variables.
Message 2 of 19
(4,196 Views)

Dennis Knutson wrote:
That's a perfectly legitimate use of local variables.

 

... because it sounds like you are limiting your use of locals to an initial start-up state where thre is no possiblility of a parallel thread attempting to write to the same objects.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 3 of 19
(4,164 Views)

secr1973 wrote:
I guess I don't really have a problem, but I keeping reading on here that local variables are bad and that you should avoid using them.  Is there a better way to do this without using local variables?

That's from the local variable "purist" crowd. Local variables, like every other programming construct, has its intended use, and can be abused. Just like every other type of programming construct. Believe me when I tell you we've seen while loops abused. Like newspapers, don't believe everything you read. Smiley Wink

 

I'm surprised someone from that crowd hasn't chimed in to say "Use property nodes!".  Smiley Very Happy

 

 

Message 4 of 19
(4,148 Views)


secr1973 wrote:
I guess I don't really have a problem, but I keeping reading on here that local variables are bad and that you should avoid using them.  Is there a better way to do this without using local variables?

That's from the local variable "purist" crowd. Local variables, like every other programming construct, has its intended use, and can be abused. Just like every other type of programming construct. Believe me when I tell you we've seen while loops abused. Like newspapers, don't believe everything you read. :smileywink:

 

I'm surprised someone from that crowd hasn't chimed in to say "Use property nodes!".  :smileyvery-happy:

 


 

I think I would say it is kind of like drinking. If you drink a lot you can become an alcoholic and bad things can happen. If you drink responsibly then everything should be ok.

 

Just my thought

 

Tim
GHSP
0 Kudos
Message 5 of 19
(4,142 Views)

smercurio_fc wrote:

secr1973 wrote:
I guess I don't really have a problem, but I keeping reading on here that local variables are bad and that you should avoid using them.  Is there a better way to do this without using local variables?

That's from the local variable "purist" crowd. Local variables, like every other programming construct, has its intended use, and can be abused. Just like every other type of programming construct. Believe me when I tell you we've seen while loops abused. Like newspapers, don't believe everything you read. Smiley Wink

 

I'm surprised someone from that crowd hasn't chimed in to say "Use property nodes!".  Smiley Very Happy

 

 


After two Knight and a Knight-in-waiting approve it who's going to argue?

 

Who?

 

My alter-ego!

 

Property nodes are the method I use most often becuase I can push the initialize operations down into a sub-VI and keep my GUI code cleaner.

 

The VI labled "Init" in this diagram illustrates what I typically do.

 

Use_subVIs.PNG

 

Done alter-ego-ing!

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 19
(4,140 Views)

I've kept quiet because of my reputation with Local Variables...

 

So I'll be Ben's Super-Alter-Ego and dare to say:  "you can also use Property Nodes".  However, if you do not abuse the use of the Local Variable, I will close my eyes and admit that they are probably more efficient than the Property Node (that's what I read from people on the "inside".

 

I tend to stay away from both property nodes and Locals by using shift registers.  Of course, the top of the structure does have many wires running across it..  Cluster wires, of course..  😉

0 Kudos
Message 7 of 19
(4,109 Views)

How would you use shift registers Ray?  He want to update the initial values of the controls at startup, from a file, then be able to modify those control values and save them to a file.

 

 

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 8 of 19
(4,102 Views)

Hi Putnam,

 

Ooops,...  sorry.  I wasn't suggesting that he should use a shift register.  I was saying that I use shift registers over Locals.

 

I will do an example and post it to illustrate what I mean.  😉

0 Kudos
Message 9 of 19
(4,047 Views)

Local variables are far more efficient than property nodes.  Why?  Property nodes are typically synchronous.  The node returns when the task is complete.  In this case, the front panel control must be fully updated and rendered.  You can make this more efficient for multiple changes by deferring panel updates, but you still need a full update of the front panel pieces you change.  Local variables, on the other hand, write their values to a transfer buffer.  The front panel is updated at it's next regularly scheduled time, but the variable does not block execution.  If you write to the variable several times before the front panel is updated, the transfer buffer is updated, not the actual front panel.  The front panel always gets your latest update.  As a result of this, local variables are about three orders of magnitude faster than property nodes when setting a value.  I always use local variables when I can for this purpose.  However, when you have a complex GUI, it is often nice to be able to encapsulate pieces of behavior in a subVI.  Like Ben, I then use property nodes.

 

Local variables are powerful.  You can use that power to help or to hurt...

Message 10 of 19
(4,036 Views)