From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Detect user input and increase a counter ( Using event structure or etc)

Hi guys,

 

I was trying to solve a problem by doing a program where the program will increment a counter if the user has input a number. I could not use the vi " Value has changed" as if user inserts a same number consecutively ( Ex: 1st iteration : 5 , 2nd iteration : 5), the "value has changed" vi will return a false value and cause the counter not to increment. Hence, I tried to use dynamic user events but it did not work as I wanted. Currently, the counter increases infinitely even when the x value is not changed. I have tried to look online for more info on this but could not get much help for this kind of user events. Hope you guys can have a look in the VI as attached and help me.

 

p.s : I would like to try to solve this problem using event structure, but I would welcome other solutions as well.

 

Thanks.

 

0 Kudos
Message 1 of 13
(1,839 Views)

As a first step, simplify. You have 90% too much code. You don't need any dynamic events, waits, local variables, references, etc.

Create two events: one for the stop button (value changed) and one for the x input. (You need to decide how to complete an entry. You could add an OK button or e.g. detect a key-down on the enter button, etc. You can do the count and the sum in the same event case, right?)

 

I would use a shift register for the two count. This way you can keep the indicators before the event structure so they update before the event even fires, giving you the zero count at the start. 

 

 

0 Kudos
Message 2 of 13
(1,807 Views)

See if this can give you some ideas...

 

Message 3 of 13
(1,799 Views)

 Great solution, it does work as I wanted to. However, I was wondering whether is it possible that I want to achieve that using dynamic events? I know it might be more complex but I would like to learn to use the dynamic events for this kind of problems where it requires another event to take place when user inputs a value.

0 Kudos
Message 4 of 13
(1,769 Views)

Raja@Labview wrote:

...where it requires another event to take place when user inputs a value.


I don't even understand what you mean by that, but I seriously doubt that dynamic events are the solution.

0 Kudos
Message 5 of 13
(1,754 Views)

Oh, I meant I wanted to create a dynamic event where another program/ event is triggered when user inputs a value into a numeric control.

0 Kudos
Message 6 of 13
(1,742 Views)

Raja@Labview wrote:

Oh, I meant I wanted to create a dynamic event where another program/ event is triggered when user inputs a value into a numeric control.


Dynamic events or user events? User events are dynamic events, but dynamic events are not user events per se.

 

Triggered from another program? That won't work.

0 Kudos
Message 7 of 13
(1,721 Views)

User event I mean. I would like another event to run when user inserts a value into a numeric control.

0 Kudos
Message 8 of 13
(1,692 Views)

Raja@Labview wrote:

User event I mean. I would like another event to run when user inserts a value into a numeric control.


You are still no making any sense. What is "insert"?

 

You can have as much code in any event case you want and you can even have the same event case triggered by multiple different events. (To programmatically fire an event, you can use a signaling value property (not recommended) which fires an event even if the value does not change.)

 

Please take a step back and explain the workflow you are expecting from the user. What does the operator do and what should happen in response?

 

As a beginner, never tell us HOW you want to do somethings, just WHAT you want to do. Big difference!

0 Kudos
Message 9 of 13
(1,683 Views)

Raja@Labview wrote:

User event I mean. I would like another event to run when user inserts a value into a numeric control.


Here's a quick one...

 

So the user presses a button, the event triggers a user event.

0 Kudos
Message 10 of 13
(1,656 Views)