LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Numeric EVENT_VAL_CHANGED

It appears that numerics are not sent the EVENT_VAL_CHANGED message when the user changes the text in the box. I created a simple uir with a numeric, led, and exit button with the below code:

#include
#include
#include "numeric.h"

static int panelHandle;

int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
if (InitCVIRTE (hInstance, 0, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "numeric.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}

int CVICALLBACK OnNumeric (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
SetCtrlVal(panel, PANEL_LED, 1) ;
switch (event)
{
case EVENT_VAL_CHANGED:
SetCtrlVal(panel, PANEL_LED, 1) ;
break;
case EVENT_COMMIT:
SetCtrlVal(panel, PANEL_LED, 0) ;
break;
}
return 0;
}

int CVICALLBACK onbutton (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}


The light never turns on when I am changing the value of the numeric by typing numbers in it. It does turn on when I change the value using the incr/decr arrows. The control mode is set to hot.

Is this
a. Me missing something
b. suppossed to work this way
c. error

What I need to do is detect when the user has typed a new number in the numeric and update things accordingly.

As a side note the EVENT_VAL_CHANGED message is sent to text boxes and the user types text into them, I would think that the Numerics should work the same way.
0 Kudos
Message 1 of 9
(5,088 Views)
ooops the SetCtrlVal(panel, PANEL_LED, 1) ; above the switch statement in the OnNumeric callback was placed there by copy and paste error it is not actually a part of the test code, I pasted it in on accident, but I still am wondering about the behavior of a numeric and the EVENT_VAL_CHANGED message.
0 Kudos
Message 2 of 9
(5,083 Views)
I just tried this myself and see what your refering to. Basically though its supposed to work this way. When typing in (or changing) a number in a numeric control the EVENT_VAL_CHANGED event will not fire until a commit happens (either hitting return while in the control or shifting focus to another control).

Havnt tried it yet but a combination of EVENT_KEYPRESS and EVENT_VAL_CHANGED so be what your looking to do...
0 Kudos
Message 3 of 9
(5,079 Views)
You're right that the Textbox and Numeric controls fire EVENT_VAL_CHANGED differently: Textbox fires EVENT_VAL_CHANGED on any edits, but Numeric does it only after an action that will fire an EVENT_COMMIT (as Chaos says). Numeric fires EVENT_VAL_CHANGED prior to EVENT_COMMIT, but only after the action that will generate EVENT_COMMIT.

There is limited usefullness in knowing that a number is changing until the user has commited the change. For example, you have a loop counter on the user interface. The value is currently 1000 and the user wants to change it to 200. The user clicks in the numeric at the start of the number 1000, then enters 200, then Delete 4 times. What number do you want to react to? 21000? 201000? 2001000? 200000? 20000? 2000? 200?

As Chaos says, you can use EVENT_KEYPRESS to detect if any key was pressed. You can then use GetKeyPressEventVirtualKey (eventData2) or GetKeyPressEventCharacter or GetKeyPressEventModifiers to see what key was pressed.
0 Kudos
Message 4 of 9
(5,072 Views)
Ahhh but the problem with EVENT_KEYPRESS is that it is fired before the numeric is updated (correct me if I am wrong) so it would be difficult to know the state of the Numerice ie. where the user is entering the number (at the end, at the begining, etc..), I guess the way to go at is to just use a text box and parse out the numbers for myself.
0 Kudos
Message 5 of 9
(5,067 Views)
GetCtrlVal() will see the new value in a textbox even before EVENT_COMMIT.
Just as long as you know that the user may not be done entering the number, using a Textbox instead of a numeric sounds like a good way to go if you need to see the number as it's being entered. That will put some additional data validation on you: if you're expecting a number, you need to verify that there aren't any alpha or special characters.
0 Kudos
Message 6 of 9
(5,067 Views)
Hello all,

You can use the PostDeferredCall function to get around the fact that the EVENT_KEYPRESS is fired before the UIR control is updated with the keypress value.

Check on the following example program which shows how to use this function - disregard the fact that this example is for table controls (it works with numeric controls as well).
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 7 of 9
(5,051 Views)
Is there PostCallBack function of LV?
0 Kudos
Message 8 of 9
(4,849 Views)

Hello,

 


I’m not exactly sure why you would need this function in LabVIEW, or what behavior you are after in your VI.  If possible, could you post a more detailed question with what type of system you are trying to create, and re-post the question to the LabVIEW discussion board for us to take a look at?

 


Thanks, and have a great day-

Travis M
LabVIEW R&D
National Instruments
0 Kudos
Message 9 of 9
(4,817 Views)