Private Sub txtFields_KeyPress(Index As Integer, KeyAscii As Integer) If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0 End Sub我上面的程序是只允许输入数字和backspace的例子,楼主修改一下就可以了,用google搜索一下正负号的ascii
在keypress实践中:if (keyascii > asc("0") and keyascii() < asc("9")) or keyascii = asc("+") or keyascii = Asc("-") then '正确的代码 else keyascii = 0 end if
Private Sub Text1_Change() If Not ValidateNumeric(Text1.Text) ThenText1.Text = ""End If End Sub Private Function ValidateNumeric(strText As String) As BooleanValidateNumeric = CBool(strText = "" Or strText = "-" Or strText = "+" Or strText = "." Or IsNumeric(strText))End Function
或許這樣比搜索的速度更快.請指點!Private Sub Text2_KeyPress(KeyAscii As Integer) msgbox KeyAscii End Sub
忘说清楚了 我写的是这样的形式: If Text1(i) = "" Then msg = MsgBox("数据为空将默认为零,是否继续?", 3 + 32 + 0, "数据检查") end if 就是说已经输入数据了,在进行下一步的前检查一下 请哪位大侠照这样的语句,写一段输入非数字字符弹出提示框的语句 谢谢!!!
if isnumeric(trim(text1(i).text))=false then msgbox "请输入数字" end iflike this??
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0
End Sub我上面的程序是只允许输入数字和backspace的例子,楼主修改一下就可以了,用google搜索一下正负号的ascii
'正确的代码
else
keyascii = 0
end if
If Not ValidateNumeric(Text1.Text) ThenText1.Text = ""End If
End Sub
Private Function ValidateNumeric(strText As String) As BooleanValidateNumeric = CBool(strText = "" Or strText = "-" Or strText = "+" Or strText = "." Or IsNumeric(strText))End Function
msgbox KeyAscii
End Sub
我写的是这样的形式:
If Text1(i) = "" Then
msg = MsgBox("数据为空将默认为零,是否继续?", 3 + 32 + 0, "数据检查")
end if
就是说已经输入数据了,在进行下一步的前检查一下
请哪位大侠照这样的语句,写一段输入非数字字符弹出提示框的语句
谢谢!!!
msgbox "请输入数字"
end iflike this??