LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question about local variable in LabVIEW

Solved!
Go to solution

I'm a new bie to LabVIEW.

I have a question about local variable in LabView.

I tried to stop a for loop by local variable but the value of loop counter is different with my expected value.

I think the loop to stop at 6 but it stopped at 7.

Could anyone help me? 

Download All
0 Kudos
Message 1 of 5
(2,572 Views)
Solution
Accepted by gongsx

That sounds exactly like a race condition.  You have know control over whether the terminal of the control is read first or the local variable is written to first.

 

Try running your code with Highlight Execution on.

 

In your code what will usually happen is that the control terminal is read and the value is false.  Then other code will execute allowing the value to be written to the local variable.  Let's say in a particular loop iteration, it is gets set to True.  But the control terminal value has already been read as false, so the loop iterates again.  Next iteration the control terminal is read and then it sees the True and will force the loop to stop no matter what happens in the rest of the loop.

 

So, why are you using a local variable instead of just sending the wire to the stop terminal?

Message 2 of 5
(2,556 Views)

Thanks for your quick answer.

 

I have tried Highlight Execution and found the control terminal was read first and written later by local variable as you said.

There is no special reason for using a local variable instead of just sending the wire to the stop terminal.

It's just because I'm a new bie to LabVIew and think using local varible will have the same result.

 

Thank you very much.

0 Kudos
Message 3 of 5
(2,548 Views)

Since you are new to LabVIEW, make sure you take some tutorials if you haven't already done so.

LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

 

For more information about local variables read Why some people say Local Variables are bad...

0 Kudos
Message 4 of 5
(2,539 Views)

LabVIEW is a dataflow language and as such a wire is not the same as local variables. LabVIEW also supports parallel processing which is a benefit of dataflow. Essentially, any node (primitive such as an add, a structure such as a case statement or loop, or a subVI as well as others) can be executed as soon as all of its inputs have been satisfied. Local variables break dataflow by allowing a single item to be accessed at the same time in two places at the same time. Local variables also creates copies of the data where a single wire will not. When writing code in LabVIEW you should really try to learn and understand data flow and use it within your code.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 5
(2,536 Views)