From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Create a prompt that allows the user to decide whether an event executes or not

Solved!
Go to solution

Hello!

 

I cannot figure out how to make the following function work:

I want an "Are You Sure?" prompt to pop up when a user wants to stop the program.

 

The attached vi works if you select yes to the prompt and then click anywhere on the screen (besides the buttons). But one shouldn't need to click on the screen again after answering the prompt. And there's many ways to break the program.

 

Any help is appreciated.

Thank you!

0 Kudos
Message 1 of 6
(2,980 Views)
Solution
Accepted by topic author johndoe108

This is happening becuase you are actioning it on a mouse down event and then opening a modal dialogue which takes focus away from the main window. The value changed event doesn't get fired until the main window receives focus again (would almost say that's a bit of a bug in LabVIEW, but yeah....).

 

To overcome this I would place generate the dialogue on the value changed event and remove the mouse down event handler completely. This has the added benefit of allowing the keyboard to activate the button as well when activated by the keyboard after being selected with the tab key.

LabVIEW_2019-01-07_17-49-43.png

 

 



Using LV2018 32 bit

Highly recommended open source screen capture software (useful for bug reports).

https://getsharex.com/
Message 2 of 6
(2,954 Views)
Solution
Accepted by topic author johndoe108

Windows already has an "exit program" button in the form of an [X] in the upper right corner. That's what users expect to use, so don't define your own non-standard way.

 

Simply use a "panel close?" Filtering event and "discard" depending on the outcome of the dialog.

Message 3 of 6
(2,941 Views)

The above is for the specific question of conditionally exiting the program.

 

In the more general case, place the dialog followed by a case structure inside the event case and leave the false case empty/wired across.

0 Kudos
Message 4 of 6
(2,932 Views)

Now I understand why I was getting that odd behavior. Matt's solution worked for me for the general case. Altenbach's solution worked for me for specifically exiting the program.

 

Thank you both for your responses! I appreciate it! @matt.baker @altenbach 

 

0 Kudos
Message 5 of 6
(2,925 Views)

@altenbach wrote:

 

Simply use a "panel close?" Filtering event and "discard" depending on the outcome of the dialog.


See also my 2018 NI-Week presentation.

0 Kudos
Message 6 of 6
(2,890 Views)