From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

How to stop While Loop in Event Structure with same button?

Solved!
Go to solution

 

Hello,

 

I have a problem. I want to use one control to activate an event in a event structure, and the same control to terminate a while loop in that event.

It is possible to use 2 controls to do this, but I need it to be only one.

 

Thank you 🙂 

Message Edited by Heinen on 02-19-2009 06:16 AM
Message Edited by Heinen on 02-19-2009 06:20 AM
--------------------------------
The Enrichment Center is required to remind you that you will be baked, and then there will be cake.

Message 1 of 11
(18,915 Views)

Looking at your (rather small) screenshot, i think you are just starting with event driven programming. Please take a look into this link. Esp. figure 1 shows the default usage of termination.

Having a while loop within an event is not recommended since it can lead to "abnormal program behaviour". Maybe you should rather look into the producer/consumer (event based) design pattern which is part of the templates installed with LV. You can find it using the template browser (File >> New).

 

hope this helps,

Norbert 

 

[Edit]: You enlarged the screenshot to a proper size 😉 

Message Edited by Norbert B on 02-19-2009 06:23 AM
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 11
(18,907 Views)

Hello and thank you for your reply.

 

I'm not new to event based programming. Using While Loops in Event Structures is perfectly fine, as long you prevent other events to fire wenn the While Loop is running.

Producer/Consumer is not  a good choice for my application due to the stacking of data that occurs.  

 

I just want to know if this is possible to do this with only one control.

 

Thx 🙂 

--------------------------------
The Enrichment Center is required to remind you that you will be baked, and then there will be cake.

0 Kudos
Message 3 of 11
(18,878 Views)

It surely is possible to solve with one control. But you have to work around many pitfalls in order to get this to work:

- Disable "Lock front panel until the event case for this event completes" for the button-hit event. This could introduce some odd behaviour to the rest of your application.

- Make sure that the button has the desired behaviour. Please note that if the button value change is from false -> true, the while loop will immediatly terminate.

- Moving the button out of the appropriate event case creates the "visual update pitfall". Therefore, you have to ensure values/graphics fit to your need.

 

hope this helps,

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 4 of 11
(18,875 Views)
Solution
Accepted by topic author SectorEffector

You should NEVER place while loops inside event cases, and there is never a need to do so. Think about it: All you need to do is spin some code. You can easily use the outer while loop for everything. Simply place the inner loop code (without the inner loop) inside the timeout case and manipulate the timeout between a finite wait and infinity (-1), depending on the state of the boolean.

 

Here's a very simple example (LV 8.0)

 

 

Message Edited by altenbach on 02-19-2009 07:05 AM
Message 5 of 11
(18,861 Views)

Wow Altenbach! That is absolutely brilliant!!!! 🙂 NICE!

 

Thanx you so much! 

--------------------------------
The Enrichment Center is required to remind you that you will be baked, and then there will be cake.

Message 6 of 11
(18,851 Views)

Hello,

I have a bit different problem.

I have a tab control, with several buttons on different pages.

In the current situation, we can talk about two pages, where one page ("Settings") in the Image, has a START and EXIT button, while second page ("Wait") has an EXIT button.

 

In a while loop, I have event structure, which handles events of the START and EXIT buttons of the Settings page. This is fine. But I also want to control the Exit button of the Wait page.

The control works like this:

When I click on Start in the Settings page, the front panel shows Wait page and attempts to connect to a datasocket server on the remote computer. If the user wants to stop this process, he can click on Exit on Wait page too. But, this doesn't give any immediate effect. On the even of Start button, the front panel is not locked, so the user can actually click the Exit button on the next page when it's visible. But it's of no immediate effect. Means, what the LabVIEW does is, finishes the execution of event in Start button's click, and while this executes, it doesn't consider the Exit button's refreshed value (shown in Red circle in the block diagram).

 

Simple question: Is there any way to check the updated (latest/live) value of a control during some event's execution? Or if I write an Event "Value Changed" for the Exit button and pass it to some variable. Is it the only solution?

 

Thanks ahead.

Vaibhav
0 Kudos
Message 7 of 11
(18,658 Views)

Vaibhav wrote:

I have a bit different problem.


Then please (!!!!) start a new thread. This thread already has a marked solution, so adding to it with a new and unrelated question is not a good idea.

 

Could you also attach some real code. Debugging pictures is very tedious. 😉

Message Edited by altenbach on 04-20-2009 10:02 AM
Message 8 of 11
(18,648 Views)

Hi altenbach!

Sorry for this. I also believe in not posting something in a wrong place. But I felt this discussion somewhat in the same category. And the main reason to do this is that earlier, upon creating a new thread, I didn't get much attention to the problem, and here atleast I get some direct attention of people who participated in the thread.

 

Anyways, I have created a new thread for the query.

http://forums.ni.com/ni/board/message?board.id=170&thread.id=403219

 

Thanks for the concern.

Vaibhav
Message 9 of 11
(18,615 Views)

 

Wow Altenbach! That is absolutely brilliant!!!! Smiley Happy NICE!

Thank you so much!

 

I got the solution for my requirement.

 

once again

Thank you so much!

 

Regards,

Hari

0 Kudos
Message 10 of 11
(17,039 Views)