LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Limiting Number of Times an Event can be Called

Solved!
Go to solution

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?

0 Kudos
Message 1 of 7
(3,948 Views)
Message 2 of 7
(3,941 Views)

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.  

Message 3 of 7
(3,932 Views)
Solution
Accepted by topic author _natalie_

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.

Message 4 of 7
(3,921 Views)

@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. 😄

 

Message 5 of 7
(3,911 Views)

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

Message 6 of 7
(3,902 Views)

Thanks so much!  Very easy solution.

0 Kudos
Message 7 of 7
(3,835 Views)