发布网友 发布时间:2024-10-23 23:06
共2个回答
热心网友 时间:2024-10-23 23:12
'加入3个command、2个label、1个text控件,位置自己调整一下
Option Explicit
Private Sub Command1_Click()
If IsNumeric(Text1) Then '是否为数字
If Val(Text1) >= 0 And Val(Text1) <= 100 Then '分数范围0-100
If Val(Text1) < 60 Then
Label2 = "结果:" & "不及格"
ElseIf Val(Text1) < 75 Then
Label2 = "结果:" & "及格"
ElseIf Val(Text1) < 90 Then
Label2 = "结果:" & "良好"
Else
Label2 = "结果:" & "优秀"
End If
Else
Label2 = "结果:" & "无效的分数"
End If
Else
Label2 = "结果:" & "无效的数字"
End If
End Sub
Private Sub Command2_Click()
Text1 = ""
Label2 = "结果:"
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
Label1 = "分数:"
Text1 = ""
Label2 = "结果:"
Command1.Caption = "判定"
Command2.Caption = "清除"
Command3.Caption = "退出"
End Sub
热心网友 时间:2024-10-23 23:08
窗体上一共有三个command (1指“判定”按钮,2指“清除”按钮,3指"结束"按钮);两个文本框(1是输入成绩的,2是判别的)
Private Sub Command1_Click()
Dim a As Integer
a =Val(Text1.Text)
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
(上面的后三行代码是选中文本框1,如果不需要可以删除)
Select Case a
Case 90 To 100
Text2.Text = "优秀"
Case 75 To
Text2.Text = "良好"
Case 60 To 74
Text2.Text = "及格"
Case Is < 60
Text2.Text = "不及格"
End Select
If a < 0 Or a > 100 Then
MsgBox "输入错误,请重新输入"
End If
(这里的后三行是提示,如果输入负数或者大于100的数,显示输入错误,不需要可删除)
End Sub
Private Sub Command2_Click()
Text1.Cls
Text2.Cls
End Sub
Private Sub Command3_Click()
end
end sub