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码值判断
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码值判断
MyVar = "53" ' 指定值。
MyCheck = IsNumeric(MyVar) ' 返回 True。MyVar = "459.95" ' 指定值。
MyCheck = IsNumeric(MyVar) ' 返回 True。MyVar = "45 Help" ' 指定值。
MyCheck = IsNumeric(MyVar) ' 返回 False。
如果 Number=Int(Number) 那一般就没有小数点了
Abs判断 是否为有没有负号
If InStr(strValid, mid(txtNumber.text,i,1)) = 0 Then
'MsgBox "不是数字"
End If
next i