LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop while loops inside a case structure

I have a tab control on the front panel.  On the block diagram is a main while loop around everything.  Inside the while loop is a case structure that changes the case for each tab.   Inside each case is a while loop that continually runs whatever I want to be doing while I am on that tab.  The problem is that when I press another tab, the while loop for the previous tab remains running, and I can't seem to get it to stop automatically.  I tried wiring the state of the tab control to an equal statement so that when the tab changed, the result would be false (not equal to the previous tab).  It doesn not work.  Any suggestions?  Is there an event that fires when I leave a tab and go to another tab?
 
 
0 Kudos
Message 1 of 17
(10,560 Views)
It doesn't stop because the condition (in this case the value of the tab control) that controls the loop never changes. You may be changing the tab on the front panel, but the loop only sees the original value since you are tunneling the value into the loop. The loop terminal sees the value of the tunnel as it was at the start of the loop. Changing the value outside the while loop will have no effect since you still inside the loop. If you turn on highlighting you will see this. To do what you want you have to read the value of the tab control inside the loop though either a local variable or a property node.

Now, as to whether this is the best way to do it I can't say because I don't know what you're trying to accomplish overall - this seems to be the early part of the program. For instance, what are you trying to accomplish with that XOR operation?
0 Kudos
Message 2 of 17
(10,544 Views)

Thanks smercurio,  The XOR merely flashes the LED (boolean) on the front panel to see if it is being scanned.  It changes state each time the loop is executed.  Just for troubleshooting.

Each case statement has a while loop in it, which is kept running by the state of the tab control.  Perhaps this is not the best architecture scheme to use for this, but I would like to select a tab, and then continually run a while loop only while I am in that case .  If I had Ver. 8.5 (waiting - said to be sent on the 10th), I could perhaps use a state machine for this.  There should be a way in 8.2.1 though.  One question:  Is there an event fired when I enter or leave a case?  I could perhaps use that to stop the while loop from running.  Another question:  When you enter a new case, when does the while loop start to be scanned.  Why does it continue to be scanned when I go to another case?  What automatic ways are there to automatically stop the while loop when I leave the case it is in?

 

Thanks again.

0 Kudos
Message 3 of 17
(10,529 Views)
Moving to 8.5 is not going to fix the basic misunderstanding you have about data flow. And you can implement a state machine in any version of LabVIEW. It is not something new. A while loop in LabVIEW (or any other programming language), will continue running until the correct condition is passed to it's termination terminal. You have no way of doing that. Something has to be inside the while loop to read a changing condition. The state of the tab control is outside the while loop the way you have it now.
0 Kudos
Message 4 of 17
(10,527 Views)
Here's a picture that hopefully will help you understand while loops and dataflow.
 

Message Edited by Dennis Knutson on 10-05-2007 12:57 PM

0 Kudos
Message 5 of 17
(10,515 Views)
The second loop in Dennis' reply will stop after one iteration if Stop 2 is true before the VI is run.

Lynn
Message 6 of 17
(10,494 Views)
Oops. Thanks, I should have made that clearer. Run once or an infinite loop.
0 Kudos
Message 7 of 17
(10,489 Views)

Thanks everyone for the help!  I guess I didn't make myself clear, and used a poor example.  I understand about the dataflow.  I am attaching an example of what I need to do.  There is one primary application While loop.  On the Front Panel is one big Tab Control.  On one of the pages (in the example - page 2) there is a stop button to stop the entire application.  This works OK as shown.  My real problem is stopping the multiple while loops that are in each case statement as I leave the case and go to another case (ie. select a different tab page).  I need to do this automatically without using a push button.  The 'or' as shown using the property value for the Tab Select does not work correctly.  If I change tab pages, the while loop for the previous page continues and does not stop.  I think this is because it never sees the value of the tab change, so doesn't know to stop.  This is why I was wondering if there is an event that fires when I leave a tab page.  Maybe this is not a good architecture for this.  I am open to suggestions.  I just started using LabVIEW about 3 months ago, so am still learning.

  

0 Kudos
Message 8 of 17
(10,454 Views)
Based on the modified example you posted I can't replicate what you're seeing. I wrote up a small VI to do what you explained, and the loops stopped whenever I changed tabs. Attached is the sample VI I wrote. Can you run it and see what happens?
0 Kudos
Message 9 of 17
(10,442 Views)

smercurio,

Your loop test works OK.  I see that my actual program is hanging up on one page called the "documentation" page.  Here I can select from an array of .pdf files to view.  The viewing, and selection works fine.   However; the program hangs like it is waiting on the event structure to process something.  I thought that if there were no events, that it ignored the event structure, and kept the while loop going waiting for an event.  I am sure you can tell me right away what my data dependency is that is causing me trouble, but with my lack of experience, I can't see it.  Let me know what you think.  The LED says it is stlll on the document page, but the tabs show I am on another page.  The Tab Select input is still "document", and I am not updating the 'seconds' on the clock  (in the main application while loop) either.

Thanks 

0 Kudos
Message 10 of 17
(10,416 Views)