if not isnumeric(text1.text) then msgbox "error" end if
使用数据类型转换函数,如Val()/cdate()/clng(),请查帮助
不好意思错了 if not IsNumber(text1.text) then msgbox "error" end if
假设界面上有一个txtLong的文本框,用来输入整数; 在txtLong的KeyPress事件中写: Private Sub txtLong_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 48 To 57 Case Else KeyAscii = 0 end select End Sub然后用CLng(Val(txtLong.Text))就可以取得整数,即有效数据
If Not IsNumeric(Text2.Text) Then MsgBox "4%$" End If 这个试过了
验证数据的合法性要自己写验证的相关代码 例如: If Not IsNumeric(Text2.Text) Then MsgBox "不是數字" End If
其实有个方法,就是让用户只能输入数值型的数据,下面就是只能输入整数和小数Private Sub txt_A1_063_KeyPress(KeyAscii As Integer) Dim intCount As Integer '只能输入0--9和小数点 If KeyAscii <> vbKeyReturn And _ Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) And _ KeyAscii <> 46 Then KeyAscii = 0 Exit Sub End If '只能有一个小数点 If KeyAscii = 46 Then intCount = InStr(CStr(txt_A1_063.Text), ".") If intCount > 0 Then KeyAscii = 0 Exit Sub End If End If End Sub
msgbox "error"
end if
if not IsNumber(text1.text) then
msgbox "error"
end if
在txtLong的KeyPress事件中写:
Private Sub txtLong_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57
Case Else
KeyAscii = 0
end select
End Sub然后用CLng(Val(txtLong.Text))就可以取得整数,即有效数据
MsgBox "4%$"
End If
这个试过了
例如:
If Not IsNumeric(Text2.Text) Then
MsgBox "不是數字"
End If
Dim intCount As Integer
'只能输入0--9和小数点
If KeyAscii <> vbKeyReturn And _
Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) And _
KeyAscii <> 46 Then
KeyAscii = 0
Exit Sub
End If
'只能有一个小数点
If KeyAscii = 46 Then
intCount = InStr(CStr(txt_A1_063.Text), ".")
If intCount > 0 Then
KeyAscii = 0
Exit Sub
End If
End If
End Sub
'日期型判断:isdate(text1.text)