select-case的用法
要求在text1输入数据范围为【0,100】,若输入数据不在范围内,则提示“数据错误”后重新输入,若数据有效,则将判断等级在text2中输出(优,良,中,差,不及格)...
要求在text1输入数据范围为【0,100】,若输入数据不在范围内,则提示“数据错误”后重新输入,若数据有效,则将判断等级在text2中输出(优,良,中,差,不及格)
展开
3个回答
展开全部
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<89
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的意思...
刚稍微修正了下
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<89
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的意思...
刚稍微修正了下
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询