10-18-2013 05:06 AM
问题:
LabWindows/CVI 9.0 使用String组件作编辑框使用,如何限制字符输入,比如输入除数字外的字符时提示错误或者禁止输入非数字字符。
Primary Software: LabWindows/CVI Development Systems>>Base Package
Primary Software Version: 9.0
Primary Software Fixed Version: N/A
Secondary Software: N/A
|
Problem:
When i use String as edit object to input some numbers,how can i do that limit the data input only is Number? thank you!
Solved! Go to Solution.
10-18-2013 09:11 PM
Problem:
LabWindows / CVI 9.0
Components for using the String edit box to use, how to limit character input, such as input characters in addition to numbers when an error or prohibit the import non-numeric characters.
i am sorry about that my English just so so. thank you.
10-19-2013 03:08 AM
Hi,
to my knowledge there is no possibility to limit input to certain characters. The 'workaround' could be to use the callback function with either the EVENT_VAL_CHANGED or the EVENT_KEYPRESS event, read the string (using GetCtrlVal), analyze it and correct it according to your criteria, and redisplay the modified string on the control.
10-20-2013 07:56 PM
Thanks for your advice, I have solved the problem.
int CVICALLBACK StringCallback (int panel, int control, int event,
void * callbackData, int eventData1, int eventData2) {
int key; / / The character being pressed.
switch (event) {
case EVENT_KEYPRESS:
/ / Get the pressed character.
if ((key = GetKeyPressEventCharacter (eventData2)) == 0) break;
/ / If a digit (0 to 9) is pressed, swallow the keypress.
if (!isdigit (key))
SetKeyPressEventKey (eventData2, 0, 0, 0, 0, 0);
break;
}
return 0;
}
10-21-2013 12:10 AM
Thank you for posting your solution - it may help others!