VB程序找错

来源:百度知道 编辑:UC知道 时间:2024/05/16 17:20:01
Option Explicit

Private Sub Command1_Click()
Dim x%
If IsNumeric(x) Or x > 100 Or x < 0 Then '非数字、大于100或小于0 则报错
Text2 = "输入出错!"
ElseIf x >= 90 Then
Text2 = "优"
ElseIf x < 90 And x >= 80 Then Text2 = "良"
ElseIf x >= 70 Then Text2 = "中"
ElseIf x >= 60 Then Text2 = "及格"
ElseIf x < 60 Then
Text2 = "不及格"
Select Case x
Case 90 To 100
Text2 = "优"
Case 80 To 89
Text2 = "良"
Case 70 To 79
Text2 = "中"
Case 60 To 69
Text2 = "及格"
Case 0 To 59
Text2 = "不及格"
End Select
End If
End Sub

Private Sub Text1_GotFocus()
Text1 = ""
Text2 = ""
End Sub

为什么我无乱打什么都会出现“输入错误”而不是预设的

Private Sub Command1_Click()
Dim x%
x = Val(Text1.Text)
If IsNumeric(x) Or x > 100 Or x < 0 Then
Text2 = "输入出错!"
End If
Select Case x
Case 90 To 100
Text2 = "优"
Case 80 To 89
Text2 = "良"
Case 70 To 79
Text2 = "中"
Case 60 To 69
Text2 = "及格"
Case 0 To 59
Text2 = "不及格"
End Select
End Sub

Private Sub Text1_GotFocus()
Text1 = ""
Text2 = ""
End Sub

此为正解,试试吧。

If IsNumeric(x) = False Or x > 100 Or x < 0 Then '非数字、大于100或小于0 则报错
Text2 = "输入出错!"
ElseIf x >= 90 Then
Text2 = "优"
ElseIf x < 90 And x >= 80 Then Text2 = "良"
ElseIf x >= 70 Then Text2 = "中"
ElseIf x >= 60 Then Text2