这是个根据分数给出评价的程序,代码如下:
Private Sub Command1_Click()
Dim a As Single
a = Val(Text1.Text)
If a > 100 Or a < 0 Then
MsgBox ("invalid!")
End If
If a = 100 Then
MsgBox ("terrific!")
End If
If 90 <= a < 100 Then
MsgBox ("good!")
End If
If 75 <= a < 90 Then
MsgBox ("Not bad")
End If
If 60 <= a < 75 Then
MsgBox ("you can be better!")
End If
If a < 60 Then
MsgBox ("come on")
End If
End Sub
运行后按确认对话框会乱跳,请问该如何解决(本人新手一枚),谢谢!
之前一个朋友的问题,我分享一下正确的代码。
计算机语言的表达式与数学表达式有区别的.如你的
If 90 <= a < 100 Then
正确的是
If 90 <= a and a< 100 Then
改好的程序
Private Sub Command1_Click()
Dim a As Single
a = Val(Text1.Text)
If a > 100 Or a < 0 Then
MsgBox ("invalid!")
End If
If a = 100 Then
MsgBox ("terrific!")
End If
If 90 <= a And a < 100 Then
MsgBox ("good!")
End If
If 75 <= a And a < 90 Then
MsgBox ("Not bad")
End If
If 60 <= a And a < 75 Then
MsgBox ("you can be better!")
End If
If a < 60 Then
MsgBox ("come on")
End If
End Sub