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: 

Is it possible to use key down event to stop a while loop?

Hi,

As the subject says, it is possible to use a key down event (wired to the stop terminal) to stop a while loop from running? More specifically, I need to use the "S" and "L" buttons to do this.

All feedback is much appreciated!

Thanks.

0 Kudos
Message 1 of 8
(3,064 Views)
Message Edited by Ravens Fan on 03-22-2009 10:14 PM
Message 2 of 8
(3,060 Views)
Spot on! Excellent, thanks for that.
0 Kudos
Message 3 of 8
(3,057 Views)

I'm having trouble using a key down event to stop a while loop.

I am using the structure in the attached picture.

I want the VI to display a random picture (first frame of the flat sequence) and then wait a certain amount of time (second frame of the flat sequence). I want this process to repeat until the spacebar is pressed (the event structure with a key down event) which terminates the while loop.

For some reason, instead of doing this the structure displays a random picture, waits for a keystroke and once it is pressed it then waits and the VI stops after. If I completely remove the event structure, and just have the while loop on Continue If True, the picture generation and wait work fine so I figure the problem has something to do with the event structure.

Any help is always appreciated!

0 Kudos
Message 4 of 8
(2,940 Views)

Your event structure blocks the loop from spinning. The loop cannot repeat until everything in it has completed and your event structure only completes if a key is pressed. Think dataflow!

 

Try execution highlighting for debugging.

 

Quick solution: make the event structure transparent by adding a timeout case and wiring a reasonable value to the timeout terminal.

 

Not much more can be said. Your VI image is incomprehensible because things are hidden and/or unlabeled. Also some things make very little sense. Why don't you attach the actual VI instead of a picture? It would be much easier for us to debug!

Message 5 of 8
(2,929 Views)

Attached is the VI (it is run as a subVI in another program).

 

Sorry about the lack of information.

0 Kudos
Message 6 of 8
(2,912 Views)

Hi KTG,

 

here's a vi with cleanup and additions as mentioned before...

 

Have a live outside - it's Easter Smiley Wink

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 8
(2,890 Views)

Thanks GerdW!

I've only been using Labview ~5 months with no background in any sort of computer programming so any help I get is more than appreciated!

0 Kudos
Message 8 of 8
(2,852 Views)