LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FOR loop wont update Local Variable

Solved!
Go to solution

I am newer to labview, and i cant wrap my head around why a local variable wont update in code if it updates on the dashboard. Anything im missing?

0 Kudos
Message 1 of 3
(3,352 Views)
What do you mean by update in code? If the value is not being updated on the block diagram it won't update the front panel (not dashboard).

You would benefit from going through the online tutorials.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 3
(3,349 Views)
Solution
Accepted by topic author Taco.Dust

Let's assume you are talking about the "Cell state" local variable. The terminal updates every 500ms in the small upper loop, The local variable just points to that indicator and thus updates equally.

 

The problem is "dataflow" and you need to get familiar with the concept!

 

Once the while loop starts, the local variable is read and the inner FOR loop starts. Most likely the local variable is read way before it gets updated in the little FOR loop, thus most likely returns a stale value on the first iteration of the while loop. Now the small FOR loop continues to iterate twice a second for about five seconds. Only after the FOR loop (and everything else inside the while loop) has completed, the while loop will go to the next iteration, at which time the local variable gets read once again, this time with the last value from the very last FOR loop itereation of  the previous iteration of the while loop.

 

In summary, the local variable updates just fine, it's just that the code does not get around reading the new value most of the time.

 

Your VI is also full of potential race conditions caused by the overuse of local variable. You need to enforce proper execution order by eliminating the local variables. 

 

So what's the solution? Hard to tell without knowing what the VI is supposed to do. Most likely you need to eliminate the inner FOR loop and use the outer WHILE loop for everything.

Message 3 of 3
(3,331 Views)