LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does Ctrl-P restart a While loop?

Solved!
Go to solution

I am exploring (= teaching myself) how key codes are captured by the Event structure.  I built a simple test routine (see below) that has a 1 second timeout that increments each tick (allowing the program to exit after 30 seconds) and a Key Down? filter that shows me what happens when I type various keys.

 

When I first ran it, I didn't have the Discard? terminal wired, and noticed that ^Q popped up a "Quit?" dialog, while ^P popped up a "Print Screen" dialog.  I'd wanted to "capture" these keystrokes for "Quit" and "Pause".  I then wired "True" to the terminal, and no additional dialog box popped up (as expected).

 

However, I noticed that typing ^P had the effect of restarting my While loop (there's an indicator, not visible here, inside the Timer event that shows the current count, 1, 2, 3, ..., and when I type ^P, it resets to 1 and starts counting again).  I'm guessing that the entire program is restarted, but was not aware of this behavior!

 

Two questions.  First, is this documented, and if so, where can I read about the "intended" actions of this keystroke?  Second, is there a way to "turn off" this behavior and have ^P be treated as just a combination of keys, whose effect is "discarded" by the Event loop?

 

Bob Schor

Explore Keys.png

0 Kudos
Message 1 of 4
(3,025 Views)
Solution
Accepted by topic author Bob_Schor
Your indicator is being reset because you did not wire the shift register through the key down event. There is no way that the program is restarting.
Message 2 of 4
(3,020 Views)

Duh -- of course!  Here I was looking for something complicated, and it was a silly error ...  Thanks for keeping me humble!

 

BS

0 Kudos
Message 3 of 4
(3,013 Views)

Mistakes like this can be avoided by unchecking the "Use default if unwired" checkbox when right clicking on the blue terminal on the right side of the event structure.  Unchecking will remove the small white box within the blue one.  I think the default is to have this box checked.  Unchecking will force you to wire to the terminal in each case of a case structure or event structure, or you VI will be broken.

 

Of course there are times when using default if unwired is perfectly OK.  So far, the only time I have ever used "use default if unwired" was when I put in a boolean in a case or event structure to stop a while loop, where the boolean was only in the "exit" case.  If not in the exit case, I use the default, which is False, so the loop continues.

 

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 4
(2,947 Views)