03-26-2019 02:49 AM
Hi
I have a boolean control (Switch when pressed) in the FP and handled the value change event for the same.
While the VI is running, If I click the boolean and then press Ctrl+Z then it triggers the value change event.
Is there any way to discard this event change?
03-26-2019 03:03 AM
Hi Padmanaban,
While the VI is running, If I click the boolean and then press Ctrl+Z then it triggers the value change event.
Does it handle that event before or after you press Ctrl-Z?
In case "after": why does your VI don't handle the value change event instantly?
In case "before": how do you want to undo an already handled event?
- When you need an Undo feature in your software you need to implement it on your own!
- When there can be problems due to misguided user input you need to prevent the user from such inputs! So yu better create a kind of "Do you really want to handle that event?" dialog before executing that "value change" event…
03-26-2019 03:18 AM
There's a couple of ways which work after a quick test. One option is to create a custom run-time menu which doesn't include any Ctrl+Z / Undo shortcut. For example a simple menu with a File -> Exit command will work. If you do this, you need to handle the custom menu option (Exit) with an event structure.
Another option is to capture the Key Down? filter event on the VI, and discard the key press when Ctrl+Z is pressed. In this example the code checks if Ctrl is being pressed while the z key (scan code 44) is pressed. If so, the key press is discarded and LabVIEW never processes it.
03-26-2019 04:32 AM
Hi GerdW,
Thanks a lot for the reply. Actually, the value change event is triggered after the Keydown event.
Also, I'm using some other controls in the GUI like String etc which requires undo option to undo their typed texts. So, I cannot discard the respective key-down event directly.
03-26-2019 04:48 AM
03-26-2019 08:42 PM - edited 03-26-2019 08:55 PM
Keeping undo functionality while ignoring only Boolean changes is tricky, but still doable.
One workaround is to separate all of your boolean controls into a separate VI, and insert that VI into a sub panel on your main interface. This way when Ctrl+Z is pressed on the main VI, the sub panel VI will not receive the Key Down event. Any value change events for the booleans can then be communicated back to your main VI with a User Event.
The more complete solution would be to manage an undo history within your application, separate to that of LabVIEW. Every value change event (and corresponding control ref) could be stored in a queue, and when Ctrl+Z is pressed, you step back through the queue and reverse each value change. There will no doubt be corner cases which need handling and is extra effort, but this way will let you filter any value changes on buttons / booleans.
Edit: Very quick and dirty sub panel example attached. Run ignore_ctrlz.vi, then click the boolean in the sub panel and type some text in the string control. When pressing Ctrl+Z, the boolean value change won't be undone, only the changes on the string.