LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Referencing variable from the outside of while loop

Hi,

 

I'm trying to referencing the values in a while loop from the outside of the loop. In my case, I have a start button (boolean) with "Switch until released" action inside of the while loop. Then, if I press the "start" button, I'd like to run another sub VI which is outside of the loop.

I've tried local variable and reference of the value, but it doesn't work. Can anyone help me out of this?

Fyi, I attached my prototype.

 

Thanks in advance.

 

Jay

 

test.JPG

0 Kudos
Message 1 of 5
(3,200 Views)

First, you have to understand the concept of dataflow.  A piece of code will execute once all of the inputs to it are available.  What you have is a classic race condition.

 

The upper part of your code is completely independent of you lower part.  The lower part will run simultaneously with the upper part.  Once the lower part of the code is done running, it will be done forever because there is no code such as a while loop to keep it running.  As a result, the lower part of the code will probably have the value of whatever that Value 2 boolean is at the start of the program, because the code inside the loop hasn't executed quite yet.  Even if you have that Start button pressed before you start the VI, it is likely the Value 2 will be read as False before the Start has a chance to pass the true value to Value 2.

 

What is it you are trying to do with this code?  (I have no idea what your Start to Start2 is supposed to be doing.  It is in your screenshot but not in your VI at all.)

 

I would recommend looking at the online LabVIEW tutorials to learn more about how to program in LabVIEW
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours
Message Edited by Ravens Fan on 09-15-2009 07:37 PM
Message 2 of 5
(3,197 Views)

Of coures, I understand the concept of dataflow. The simple code was just concept to demonstrate what I'm tring to do. My current VI is too complicated at this stage, so if someone want to understand its logic, it's gonna be time-consuming. There are case and sequence structures so those two things are not going to run simultaneously. I'm not an expert on this and don't have knowledge as much as you do. But what you just write here makes me feel so bad.

 

Thank you for your reply, though.

 

Jay

Message 3 of 5
(3,191 Views)

Hey Jay, dont feel bad at all.  Ravens Fan has helped many of us before when we are in your situation. I am sure his direct talk is only meant to help.  We may have not known the whole picture of your VI.  From the picture posted, the change of the state of "start" will only be seen by the while loop which was continuesouly pulling its value.  The case structure outside will not see this change as it is already completed. You may want to consider a state machine type of structure, or use function globals to pass values of controls.

 

 

Message 4 of 5
(3,176 Views)

Thank you, Brayan.

 

Best,

Jay

0 Kudos
Message 5 of 5
(3,173 Views)