请看例程: Private Sub txtHeight_Validate(Cancel As Boolean) With Me.txtHeight If Not IsNumeric(.Text) Then MsgBox "不是一个合法的数字,请重新输入!", vbInformation Cancel = True Call txtHeight_GotFocus ElseIf CSng(.Text) < Module1.Hmin Or CSng(.Text) > Module1.Hmax Then MsgBox "水位必须界于 " & CStr(Module1.Hmin) & " ~ " & CStr(Module1.Hmax) & " 之间,请重新输入!", vbInformation Cancel = True Call txtHeight_GotFocus End If End With End Sub
If IsNumeric(TextBox1.Text) Then MsgBox "Is number" End If
if trim(text1.text)<>"" then if not isnumeric(text1.text) then msgbox "请输入数值型数据!",48,"提示" text1.setfocus end if end if
Private Sub txtHeight_Validate(Cancel As Boolean)
With Me.txtHeight
If Not IsNumeric(.Text) Then
MsgBox "不是一个合法的数字,请重新输入!", vbInformation
Cancel = True
Call txtHeight_GotFocus
ElseIf CSng(.Text) < Module1.Hmin Or CSng(.Text) > Module1.Hmax Then
MsgBox "水位必须界于 " & CStr(Module1.Hmin) & " ~ " & CStr(Module1.Hmax) & " 之间,请重新输入!", vbInformation
Cancel = True
Call txtHeight_GotFocus
End If
End With
End Sub
MsgBox "Is number"
End If
if not isnumeric(text1.text) then
msgbox "请输入数值型数据!",48,"提示"
text1.setfocus
end if
end if