LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Clear a string control when Enter is pressed

Solved!
Go to solution

My goal is to be able to type into a string control and then press the enter key on the keyboard to "execute" what I typed and clear the control. This seemed like a no-brainer and I wrote the code below:

VI_IMG.PNG

The other case is simply default and nothing happens. To my surprise I cannot clear the control in this way, I have also tried invoking the reinitialize to default method. I only seem to be able to clear the string with either of those options outside the while loop.

 

Shouldn't this work? I feel like I'm missing something simple because it's such a straightforward paradigm.

I have attached my code below. I would love to hear any suggestion and to know why this doesn't work.

 

Thank you in advance

0 Kudos
Message 1 of 24
(5,201 Views)

Have your case structure handle the "Return" and "Enter" keys in the same case.  They are separate keys and register differently.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 24
(5,193 Views)

Thank you, good catch. I have an indicator showing me that the "Return" case was executing as expected but the string did not clear. As added assurance, I checked the case "Return","Enter" and got the same results. Any Ideas?

0 Kudos
Message 3 of 24
(5,183 Views)
Solution
Accepted by topic author Brandon.Baxter

Just played around some more and I think I understand the problem now.  The problem is that the value stored in the input is not really updated until after the Key Down event.  So your writing to the local variable is being overridden but the underlying code that detects the value change.  You can see this more clearly if you add an indicator inside of the event case to show what the input value is when that event case is called.

 

The workaround I found was to set the input control to "update value while typing".


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 24
(5,173 Views)

Set string control to 'Limit to Single Line'

 

EDIT: Nevermind.  Not consistent.

0 Kudos
Message 5 of 24
(5,172 Views)

@crossrulz wrote:

 

The workaround I found was to set the input control to "update value while typing".


I could only get it to work using both 'Update Value While Typing' and ' Limit to Single Line' together

0 Kudos
Message 6 of 24
(5,160 Views)

oh, that's tricky. At first I was using a the notify "key down?" event and thought was getting over written which is why I switched to the "Key Down" event instead. do you think this would be classed as unintentional behavior?

 

Also thank you for the workaround, it even works for the "key down?" event

0 Kudos
Message 7 of 24
(5,157 Views)

i think i missed the original point of the discussion and my idea leads to the same issues.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 24
(5,155 Views)

Hello Bill, I like the "Key Down?" event because you can discard the character an append whatever you want as an end, like a sync word for example

0 Kudos
Message 9 of 24
(5,146 Views)

@Brandon.Baxter wrote:

do you think this would be classed as unintentional behavior?


I would not.  I would be tempted to call it a documentation issue.  But I have not dived into the LabVIEW help to see if this order of event execution is anywhere in there.  If not, definitely an issue.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 24
(5,141 Views)