菜鸟问一个很简单的VB问题

来源:百度知道 编辑:UC知道 时间:2024/06/16 13:51:00
首先窗体里有text1 和 command1

Private Sub Command1_Click()
If IsNumeric(Text1.Text) = False Then
MsgBox "请输入数字"
End If
Dim a As Long
a = Text1.Text

If a <= 100 Then
Select Case a
Case Is >= 90
MsgBox "a"
Case Is >= 80
MsgBox "b"
Case Is >= 70
MsgBox "c"
Case Is >= 60
MsgBox "d"
Case Is >= 0
MsgBox "no pass"
Case Is < 0
MsgBox "min"
End Select
Else
MsgBox "max"
End If
End Sub

我想在text1.text输入非数值的字时按确定弹出“请输入数值”
但是按下去以后使能弹除“请输入数值 ”但是关掉对话框后还是出错
提示 类型不匹配 请问怎样才能不出错能 就是别弹出类型不匹配
最好给我解释一下为什么
谢谢!!!
为什么要 exit sub 请给我解释一下好吗 谢谢了

我觉得:
第一,dim a 就好。应为dim a As long的话就是说 a必须是-9 quintillion 到 +9quintillion(18个0)。所以当使用者输入非数值的咚咚,那就会给你带来麻烦!
第二,dim 放在前面比较好...
第三,exit sub是另外一个解决方法。
就是说执行第一句后就跳出,不然会继续下一个if

就是说:[开]if isnumeric(text1.text)...end if>>>dim a as long....text>>>if a<=100 then...end if end sub>>[完]

<<<<<开>>>>>>>
Private Sub Command1_Click()
Dim a
a = Text1.Text
If IsNumeric(Text1.Text) = False Then
MsgBox("请输入数字")
ElseIf a <= 100 Then
Select Case a
Case Is >= 90
MsgBox("a")
Case Is >= 80
MsgBox("b")
Case Is >= 70
MsgBox("c")
Case Is >= 60
MsgBox("d")
Case Is