Private Sub Text1_KeyPress(KeyAscii As Integer)
    Key = Chr(KeyAscii)
    Select Case KeyAscii
        Case 48 To 57
            n = Val(Left(Text1.Text, Text1.SelStart) + Key + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1))
            If n > MaxSenvalue Or n < MaxSenvalue Then
                KeyAscii = 0
            End If
        Case 8
        
        Case Else
            KeyAscii = 0
    End Select
End Sub利用ASCII码值判断

解决方案 »

  1.   

    对了。用IsNumericDim MyVar, MyCheck
    MyVar = "53"   ' 指定值。
    MyCheck = IsNumeric(MyVar)   ' 返回 True。MyVar = "459.95"   ' 指定值。
    MyCheck = IsNumeric(MyVar)   ' 返回 True。MyVar = "45 Help"   ' 指定值。
    MyCheck = IsNumeric(MyVar)   ' 返回 False。
      

  2.   

    IsNumeric函数对于小数和负数也返回True,请注意.
      

  3.   

    那就请用 Int 判断一下吧
    如果 Number=Int(Number) 那一般就没有小数点了
      

  4.   

    还有 你就用 
    Abs判断 是否为有没有负号
      

  5.   

    dim strValid as String    strValid="0123456789"    for i=1 to len(txtNumber.text)
            If InStr(strValid, mid(txtNumber.text,i,1)) = 0 Then
              'MsgBox "不是数字"
            End If
        next i