求助 vb程序编写

来源:百度知道 编辑:UC知道 时间:2024/04/29 15:01:42
将输入的成绩转换成等级制 具体方法:90为优,80-89为良,70-79为中,60-69为及格,60以下为不及格
用inputbox函数输入成绩
用msgbox函数输入结果

Private Sub Command1_Click()
Dim x As Integer
Dim msg As String
Dim answer As Long
x = InputBox("请输入成绩", "输入框")
msg = "你输入的" & x
If x >= 90 Then
msg = msg & "是优"
answer = MsgBox(msg, , "优")
End If
If 80 <= x <= 89 Then
msg = msg & "是良"
answer = MsgBox(msg, , "良")
End If
If 70 <= x <= 79 Then
msg = msg & "是中"
answer = MsgBox(msg, , "中")
End If
If 60 <= x <= 69 Then
msg = msg & "是及格"
answer = MsgBox(msg, , "及格")
End If
If x < 60 Then
msg = msg & "是不及格"
answer = MsgBox(msg, , "不及格")
End If
End Sub

这么做错在哪里

1、错误在于vb的条件表达式是非法的:例如 80 <= x <= 89 应该写成: 80 <= x and x<= 89 才成。所以修改如下(就可以正确运行):

Private Sub Command1_Click()
Dim x As Integer
Dim msg As String
Dim answer As Long
x = InputBox("请输入成绩", "输入框")
msg = "你输入的" & x
If x >= 90 Then
msg = msg & "是优"
answer = MsgBox(msg, , "优")
End If
If 80 <= x and x<= 89 Then
msg = msg & "是良"
answer = MsgBox(msg, , "良")
End If
If 70 <= x and x<= 79 Then
msg = msg & "是中"
answer = MsgBox(msg, , "中")
End If
If 60 <= x and x<= 69 Then
msg = msg & "是及格"
answer = MsgBox(msg, , "及格")
End If
If x < 60 Then
msg = msg & "是不及格"
answer = MsgBox(msg, , "不及格")
End If
End Sub

2、使用if……then……else……endif语句更简便:
Private Sub Command