LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

In Edit Numeric, how can I get the value of number I just entered?

I am using the GetCtrlVal() to try to get the float type data I entered into the Edit Numeric box after I hit enter. However it is getting a previous value stored not what is displayed.
0 Kudos
Message 1 of 4
(2,795 Views)
What callback are you in and what EVENT are you trapping when you call GetCtrlVal()?
Here are some of the problems trapping the Enter key in the callback for a numeric control.
EVENT_KEYPRESS happens before EVENT_VAL_CHANGED which happens before EVENT_COMMIT.
If the number isn't changed and enter is pressed, only KEYPRESS is generated, no COMMIT.
When KEYPRESS traps Enter, the control value hasn't been updated yet.
Instead of trying to trap the Enter key in the callback to the numeric control, try something like this.
1. Place a command button (e.g. labeled ENTER or OK) on your user interface.
2. In the callback for the command button under EVENT_COMMIT, call GetCtrlVal() on the numeric and process it.
3. Make the Enter the shortcut key for the command button.
In the UI editor window, double-click on the command button. In the Shortcit Key section, leave the Modifier Key set to None and set the Key to Enter.
4. If you want, in the callback for the command button, call SetActiveCtrl() to give the focus back to the numeric.
5. You can even hide the command button if you don't want it to be displayed on your user interface. In the UI editor window, double-click on the numeric control. In the section labeled Control Settings, select Initially Hidden.
Message 2 of 4
(2,795 Views)
Unaware of the sequence of the EVENT_*. Unlike VisualBasic where I would look for the Enter keypress value, all I had to do in this case is call GetCtrlVal() in the event == EVENT_COMMIT
Thanks-
0 Kudos
Message 3 of 4
(2,795 Views)
Just remember: if the number is not changed and Enter is pressed, no COMMIT is generated: only a KEYPRESS is generated. If you want to handle Enter being pressed multiple times with the same number in the numeric, you may want to consider adding a command button as I described earlier.
0 Kudos
Message 4 of 4
(2,795 Views)