select-case的用法

发布网友 发布时间:2022-04-22 08:16

我来回答

3个回答

热心网友 时间:2023-07-19 11:30

Private Sub Command1_Click()
Dim cj As Single
cj = val(Text1.text)
Select Case cj
Case is<60,is>0

Text2.Text = "成绩不合格"

Text1.Text = ""

Text1.setfocus
Case is>60,is<70
Text2.text="成绩差"
Text1.Text = ""

Text1.setfocus
Case is>70,is<79
Text2.Text = "成绩中等"
Text1.Text = ""
Text1.setfocus
Case is>80,is<

Text2.Text = "成绩优秀"

Text1.Text = ""

Text1.setfocus
Case is>90,is<100
Text2.Text = "成绩很优秀"
Text1.Text = ""

Text1.setfocus
Case Else
MsgBox "数据错误"
Text1.text=""
End Select
End Sub
说明一下:case is就是相当于select case 的表达式...case is>10就是cj>10的意思...
刚稍微修正了下

热心网友 时间:2023-07-19 11:31

Option Explicit

Private Sub Command1_Click()
If Not IsNumeric(Me.Text1.Text) Then
MsgBox "数据错误"
On Error Resume Next
Me.Text1.SetFocus
Else
If CDbl(Me.Text1.Text) < 0 Or CDbl(Me.Text1.Text) > 100 Then
MsgBox "数据错误"
On Error Resume Next
Me.Text1.SetFocus
Else
Dim score As Double
Dim sRet As String
score = CDbl(Me.Text1.Text)
Select Case score
Case Is >= 90:
sRet = "优"
Case Is >= 80:
sRet = "良"
Case Is >= 70:
sRet = "中"
Case Is >= 60:
sRet = "差"
Case Else
sRet = "不及格"
End Select
Me.Text2.Text = sRet
End If
End If
End Sub

热心网友 时间:2023-07-19 11:31

Private Sub Command2_Click()
On Error Resume Next
s = ""
Select Case Val(Text1.Text)
Case Is > 100, Is < 0
s = "数据错误"
Text1.Text = ""
Case Is < 60
s = "不及格"
Case Is < 70
s = "差"
Case Is < 80
s = "中"
Case Is < 90
s = "良"
Case Else
s = "优"
End Select
MsgBox s
End Sub

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com