LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I setup an event structure that sends text when user presses "Return" button?

Solved!
Go to solution

I am new to Event Structure programming.  I am trying to set up a program that causes the contents of a string control to be processed when the user presses the Return key within after typing into the string control.  I think (hope!) that this is simple, I just cannot figure out how to do it.

 

Basically, I'd like to take the attached VI and modify such that the user can send the "String In" control value to the "String Out" indicator by either pressing the "Return" key or by pressing the "Send String" button.


Any help would be greatly appreciated.

 

 

Forbes Black
Lapsed CLAD, LV 5 - LV 2022 (Yeah, I'm that old...)
0 Kudos
Message 1 of 11
(3,191 Views)

Hi,

 

Please find the attached VI where i have added your requirement

 

I have added following things:

1. In the same send string boolean event i have added the value change event for string in control

2. Right click the control and i have enabled the limit to single line.

 

Hope i think this will help

Message 2 of 11
(3,183 Views)

Thanks!!  It looks like you did not have to do anything to specifically tell the program to look for the "Return" button.  It appears that the default trigger for "Change Value" on a string is when the return key is pressed, yes?

Forbes Black
Lapsed CLAD, LV 5 - LV 2022 (Yeah, I'm that old...)
0 Kudos
Message 4 of 11
(3,167 Views)
Solution
Accepted by topic author diarmaede

This example doesn't have anything to do with the RETURN key specifically.  It simply fires whenever the value of either control changes.  If you click outside the text box or on a different control the value still changes and the event still fires.  This is often the desired behaviour so if it works in your application you're good to go.

 

You CAN respond ONLY to a particular key if you want.  Set your event to respond to "This VI" >> Key DOWN.  Then, read the VKey input on the left side of the event structure and compare it to RETURN (for example).  The boolean output of the compare gets wired to a case structure with your code to be executed inside.  You can also wire VKey directly to a case structure and execute different code based on which key was last pressed.

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
Message 5 of 11
(3,160 Views)

i enabled "limit to single line" option. if it's not enabled, if you press enter it won't work.

0 Kudos
Message 6 of 11
(3,159 Views)

 


@prabubharathi wrote:

i enabled "limit to single line" option. if it's not enabled, if you press enter it won't work.


Again, the event structure is NOT responding to the ENTER key.  It is responding to the fact the the value inside the control has changed.  If you don't actually change the value in the control first, the ENTER key will not fire the event no matter how many times you press it.  If that doesn't matter to the OP, great.  If it does, they will have to use the Key Down event, read the VKey and respond to it.

 

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 7 of 11
(3,153 Views)

OK, that worked.  I had to find the property to update the string while I was typing, but once I got there, it worked.  Oh, and I had to figure out that you meant "Key Down?" instead of just "Key Down," but that's only because I am such a gumby.  Thanks for all your help!

Forbes Black
Lapsed CLAD, LV 5 - LV 2022 (Yeah, I'm that old...)
0 Kudos
Message 8 of 11
(3,137 Views)

And thank you, prabubharathi, as well.  Your solution was not exactly what I needed here, but it was a good one which I am sure I will use in the future.

Forbes Black
Lapsed CLAD, LV 5 - LV 2022 (Yeah, I'm that old...)
0 Kudos
Message 9 of 11
(3,134 Views)

 


@diarmaede wrote:

OK, that worked.  I had to find the property to update the string while I was typing, but once I got there, it worked.  Oh, and I had to figure out that you meant "Key Down?" instead of just "Key Down," but that's only because I am such a gumby.  Thanks for all your help!


 'Key Down' (green arrow glyph) should be correct.  'Key Down?' (red glyph) is a filter event which explains why your indicator wasn't updating without extra coding.  That's what filter events do, they fire the event but filter the normal effects of changing a control.  The filter events are a more advanced concept (used mostly for ignoring something like a panel close so that shutdown code runs first, or swapping the effects of the left and right mouse buttons).  There are some good examples available.

 

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 10 of 11
(3,123 Views)