如何在一个文本框中限定只输入数字
我试过很多种方法,可是它把控制键也掩盖了

解决方案 »

  1.   

    在keypress里加入下面的代码   If KeyAscii > 57 Or KeyAscii < 48 Then
          If KeyAscii <> 8 Then
             KeyAscii = 0
          End If
       End If
      

  2.   

    Function IsNum(KeyAscii As Integer) As Boolean
        Select Case KeyAscii
            Case 48 To 57  '"0~9"
                IsNum = True
            Case 8        'BackSpace key
                IsNum = True
            Case Else
                KeyAscii = False
        End Select
    End Function
      

  3.   

    Function Fun_只能输入0到9(KeyAscii As Integer) As Integer
        
        If (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> 3 And KeyAscii <> 22 And KeyAscii <> 24 And KeyAscii <> 26 Then
           Fun_只能输入0到9 = 0
           MsgBox "此处只能输入0到9的数字!", , "系统提示"
        Else
           Fun_只能输入0到9 = KeyAscii
        End IfEnd Function
      

  4.   

    在keypress里加入下面的代码   If KeyAscii > 57 Or KeyAscii < 48 Then
          If KeyAscii <> 8 Then
             KeyAscii = 0
          End If
       End If