如果在文本中输入的不是数字,就提示他输入数字?代码?

解决方案 »

  1.   

    if not isnumeric(text1.text) then
       text1.selstart=0
       text1.sellength=len(text1.text)
       msgbox "请输入数字"
    end if
      

  2.   

    If Not IsNumeric(text1.Text) Then
       '不是数字
    elseend if
      

  3.   

    在文本的事件KEYPRESS中if (kyascii>asc("9") or keascii<asc("0")) and keyascii<>13 then
       msgbox "你输入的不是数字!"
       exit sub
    end if
      

  4.   

    晕,放在Textbox的change事件中,或者放在按钮中也可以,具体看你对程序功能的要求了,如果需要限制非数字的输入,得另写代码
      

  5.   

    呵呵,谢谢提醒。
    可以放在LostFocus或按确定按钮时提示.
      

  6.   

    这个是限制输入非数字类型的Private Function CheckInput(KeyAscii As Integer)
    If KeyAscii = 8 Or KeyAscii = 9 Or (KeyAscii > 47 And KeyAscii < 58) Then
    Else
       KeyAscii = 0
    End If
    CheckInput = KeyAscii
    End Function
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    KeyAscii = CheckInput(KeyAscii)
    End Sub
      

  7.   

    ryuginka(除了我谁敢用真名:刘银华)
    =================================
    放在keypress中不够,因为复制粘贴该事件不会发生
      

  8.   

    那丢Change里面就好了..错了就返回原值.....
    我是最慢的.呵呵..