LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

LabWindows/CVI String组件 如何限制字符输入

Solved!
Go to solution

问题:

       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!

0 Kudos
Message 1 of 5
(5,105 Views)

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.Smiley Embarassed

0 Kudos
Message 2 of 5
(5,077 Views)
Solution
Accepted by topic author GD.Huang

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.

Message 3 of 5
(5,068 Views)

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;
}

Message 4 of 5
(5,055 Views)

Thank you for posting your solution - it may help others!

0 Kudos
Message 5 of 5
(5,049 Views)