10-23-2008 05:11 PM
If I repeatedly use the decrement control of a numeric control, should I expect it to eventually arrive at the minimum value of the control? Consider the case where the minimum of a numerical control is set to 40 (integer), the increment size is set to 25, and the present value of the control is 70. Could I expect to decrement the control value to 40, or am I only going to get as close as the value 45? This latter case is was I am experiencing. Is there a way to get a decrement down to 40 (the specified minimum) without having to resort to a numerical key entry, for this can be problematic for systems using touchscreen?
I had previously posted this question to the wrong board, so this is a repost to the LabWindows/CVI board.
10-24-2008 01:42 AM
Hello Steve,
I tried what you asked and, in my opinion, that's not possible, even with extra code that programmatically changes the numeric value to its max/min when the increment/decrement amount is larger than the difference.
That's because when you cannot change the value there is no commit or val_changed events fired. Only you got is left click event and it fires even when you click the whitespace in the numeric control.
A workaround I can think of now is adding 2 small buttons next to your numeric control that directly sets the value to max/min values.
The only drawback would be spending precious UIR space for this, if you have several such numeric controls on the panel.
Well, even in that case you may put just a single max/min button and you can require the operator to choose the numeric control first and then click the max/min button to choose which one to set to maximum or minimum. You can store the last numeric control selected by capturing the 'lost focus' event.
Hope this helps.
10-24-2008 07:49 AM - edited 10-24-2008 07:50 AM
I've had this problem too. My solution is not put the limits in the UIR file at all, but rather to check them in a callback function. Here's some example code (in your case MIN_VALUE would be 40):
int CVICALLBACK ControlCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
int value;
switch (event)
{
case EVENT_VAL_CHANGED:
GetCtrlVal (panel, control, &value);
if(value > MAX_VALUE)
value = MAX_VALUE;
if(value < MIN_VALUE)
value = MIN_VALUE;
SetCtrlVal (panel, control, value);
break;
}
return 0;
}
Naturally, you'll want to set the "Range Checking" to "Ignore" for the control, or just set the limits to some really big numbers.
10-24-2008 10:25 AM
Hello Steve,
You could also try using the function GetCtrlBoundingRect in conjunction with the function GetCtrlAttribute (to get the attribute ATTR_INCDEC_WIDTH) to get the location of the increment and decrement arrows on your panel. You can then use eventData1 and 2 of the EVENT_LEFT_CLICK (which gives you the coordinates of the mouse click) to determine if the user clicked one of the increment or decrement arrows and change the value accordingly.
NickB
National Instruments