‎06-16-2010 03:38 AM
I'm prototyping some electronics and temporarily need a while loop inside an event structure in order to run some code within the structure multiple times when the go button is pressed. I know it's poor programming to add a loop inside the structure, but I want to leave it running for a while without user input.
At the same time I'd like to be able to break out of the loop and use other buttons inside that event case, but no other controls inside the event structure appear to activate the case, I assume because the structure is associated with the original go button. How can I get around this?
Thanks
‎06-16-2010 03:57 AM
grahamwebb wrote:[...] I know it's poor programming to add a loop inside the structure, [...]
That's not necessarily poor programming. It is if you stack to a depth of more than 5 or 6 (that's the recommended depest nesting).
Nevertheless, you should never use possibly unlimited code execution within an event structure.
The solution you are looking for is called Producer/Consumer (Event Based) and can be found in the Template Browser (File >> New).
hope this helps,
Norbert
‎06-16-2010 04:55 AM
Hi!
A similar question has been posted here:
http://forums.ni.com/ni/board/message?board.id=170&message.id=504959
Hope this helps,
Marco
‎06-16-2010 05:28 AM
Thanks all, I can see how the producer/consumer with events design pattern would help, but I already have a substantial amount of code in the program to change the structure.
Once inside an event is it not possible to escape using user input?
‎06-16-2010 06:37 AM
‎06-16-2010 07:02 AM
hi! GerdW!
I think that, even if you choose not to lock the front panel,
in order to process the next event the while loop has to be finished.
In the end, IMO, the best choice is be toseparate the user interaction loop and the elaboration loop.
‎06-16-2010 07:12 AM
‎06-16-2010 07:14 AM
grahamwebb wrote:Thanks all, I can see how the producer/consumer with events design pattern would help, but I already have a substantial amount of code in the program to change the structure.
It may be worth your while to implement the solution proposed by Norbert regardless of the fact that youmay have substantial code written already. Even if you invest a day doing so. The Producer/Consumer (Event Based) will save you lots of time and grief in the future. Well worth the investment in time now to do it right.
‎06-16-2010 07:37 AM
I think GerdW has it.
I've also set the while loop to continue if true and the push button switches when released, the event is a value change, which seems to do the trick!
Thank you