12-22-2016 11:50 AM
Is it possible to limit the number of times an event in an event structure can be called? For example, if I have an event called "Initialize", I only want that event to be ran once. After this Initialize button has been pressed, is it possible to prevent it from going into this event if the user presses the button a second time?
Solved! Go to Solution.
12-22-2016 11:58 AM - edited 12-22-2016 12:01 PM
You may want to look at dynamic event registration.
http://forums.ni.com/t5/LabVIEW/Nugget-of-the-week-Dynamic-event-registration/td-p/508407
12-22-2016 12:04 PM
You can also keep track of the number of times an event has been triggered, and use a case structure to not execute the code in the event case if that counter is too high.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
12-22-2016 12:18 PM
It's trivial to do this. In the initialize event, disable the initialize button with the "disabled and greyed out" input to the appropriate property node. Then, the button can't be pressed and you won't trigger the event again. If things in the application change such that you'd want to use it again, same property node with "enabled" as the input. Prior to your code running, set up a property node to enable it so that your user always has access to it when the VI starts.
12-22-2016 12:31 PM
@natasftw wrote:
Then, the button can't be pressed and you won't trigger the event again.
This assumes that the event is a "value changed" event. I have seen plenty of beginner code using "mouse down" events for buttons and these would still trigger, even if the button is disabled. Just a warning. 😄
12-22-2016 12:41 PM
Fair. Let's make a modification that results in a still trivial solution.
1) Check the event to ensure it's a value change event. If not, change to value change event. If so, do nothing.
2) Continue to prior solution
12-23-2016 09:20 AM
Thanks so much! Very easy solution.