LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String indicator doesn't update event

Solved!
Go to solution

Hi all,

 

I'm filtering strings with the key down? and key repeat? events, if I type quickly the string indicator seems to update fine, typing slowly and it only updates after every second key down.

 

Why is this the case and how can I fix it?

 

VI back saved to 2015.

0 Kudos
Message 1 of 11
(2,657 Views)

When the key down event fires, the control has not received the new value yet. You always get the previous string when a new key down event occurs.

Message 2 of 11
(2,628 Views)

Maybe instead you could use the "Value change" event for the string, and then on the string properties in the right-click menu choose "Update value while typing" so that you do get the most current value for the string (the event data includes the old and the new value for each event, so even if the event queue is lagging you're fine) AND it triggers on each change.

 

One thing you'll catch doing this that you won't via the key up and down events is that if someone does a clipboard operation (cut/copy/paste) you get the event trigger as well, unlike the way you are doing it now which won't trigger if someone uses the mouse to paste something in.

Message 3 of 11
(2,608 Views)

@altenbach wrote:

When the key down event fires, the control has not received the new value yet. You always get the previous string when a new key down event occurs.

What do you think about calling the keyboard down event from user32.dll to press an extra key that will be discarded? Is there any downsides to doing this? Can you think of any other ways to do it?

0 Kudos
Message 4 of 11
(2,572 Views)

@Kyle97330 wrote:

Maybe instead you could use the "Value change" event for the string, and then on the string properties in the right-click menu choose "Update value while typing" so that you do get the most current value for the string (the event data includes the old and the new value for each event, so even if the event queue is lagging you're fine) AND it triggers on each change.

 

One thing you'll catch doing this that you won't via the key up and down events is that if someone does a clipboard operation (cut/copy/paste) you get the event trigger as well, unlike the way you are doing it now which won't trigger if someone uses the mouse to paste something in.


Using the value change event will make things more difficult sure I can compare strings but its not as easy as just discarding the wrong character. Unless I'm missing something?

0 Kudos
Message 5 of 11
(2,568 Views)
Solution
Accepted by OA1

Would this work for you?

 

AeroSoul_0-1671452371605.png

 

Basically the same as yours, but it's on value change event instead of key down.

The second select is for when you delete the last character and string should be empty.

 

Message 6 of 11
(2,479 Views)

@OA1 wrote:

Using the value change event will make things more difficult sure I can compare strings but its not as easy as just discarding the wrong character. Unless I'm missing something?


Do you want to build a text input box that automatically filters the user input and discards invalid input?

 

In that case, use the "Key pressed?" filter event. The event gives you the key that was pressed. You can check if the key is valid. If it is invalid: On the right side of the event structure is an output for discaring the event. If you discard the event, the character will not be entered in the string control.

Message 7 of 11
(2,472 Views)

That's his example, yes.

Message 8 of 11
(2,467 Views)

@AeroSoul wrote:

That's his example, yes.


Ah, I see - I got confused by the description. Usually I can't open the attached VI, but this one was back-converted far enough. I should have checked.

 

The control already gets filtered, so maybe adding a "value changed" event that just copies the value form the control to the indicator would be enough?

0 Kudos
Message 9 of 11
(2,454 Views)

@AeroSoul wrote:

Would this work for you?

 

AeroSoul_0-1671452371605.png

 

Basically the same as yours, but it's on value change event instead of key down.

The second select is for when you delete the last character and string should be empty.

 


This works great, I had to adapt it to my use case, but thank you.

Message 10 of 11
(2,435 Views)