用vb编写这样一个程序:text输入一个成绩然后回车在text显示等级(如优... 20
用vb编写这样一个程序:text输入一个成绩然后回车在text显示等级(如优良等),如果输入成绩无效则Msg提示错误,且提示错误3次后提示输入3次非法,自动关闭程序tex...
用vb编写这样一个程序:text输入一个成绩然后回车在text显示等级(如优良等),如果输入成绩无效则Msg提示错误,且提示错误3次后提示输入3次非法,自动关闭程序
text1显示输入的成绩,text2显示等级 展开
text1显示输入的成绩,text2显示等级 展开
2个回答
展开全部
你这样程序想法不友好啊!
1. TEXT1输入成绩,不合格,不理它,;;归于-1;
2. 自动循环, 直到输入合法,,,
3. 3次错误,友好提示一下
这样才是王道啊
----------------------------------------------------------------
Public errN As Integer
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If ((KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13) Then
KeyAscii = 0
End If
If KeyAscii = 13 And Text1 <> "" Then
DoErr
End If
End Sub
Sub DoErr()
If Val(Text1.Text) < 0 Or Val(Text1.Text) > 100 Then
Text1.Text = ""
Text2.Text = "输入有误"
errN = errN + 1
Else
errN = 0
DoOk
End If
If errN = 3 Then
MsgBox ("成绩只能是[0-100]的整数")
errN = 0
End If
End Sub
Sub DoOk()
Dim b As Integer
Text1.Text = Val(Text1.Text)
b = Int(Val(Text1.Text) / 10)
Select Case b
Case 10, 9
Text2.Text = "优秀"
Case 8
Text2.Text = "良好"
Case 7
Text2.Text = "中等"
Case 6
Text2.Text = "及格"
Case 5, 4, 3, 2, 1, 0
Text2.Text = "不及格"
End Select
End Sub
-------------------------------------------
做个按钮让人退出,是不是更好点啊
1. TEXT1输入成绩,不合格,不理它,;;归于-1;
2. 自动循环, 直到输入合法,,,
3. 3次错误,友好提示一下
这样才是王道啊
----------------------------------------------------------------
Public errN As Integer
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If ((KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13) Then
KeyAscii = 0
End If
If KeyAscii = 13 And Text1 <> "" Then
DoErr
End If
End Sub
Sub DoErr()
If Val(Text1.Text) < 0 Or Val(Text1.Text) > 100 Then
Text1.Text = ""
Text2.Text = "输入有误"
errN = errN + 1
Else
errN = 0
DoOk
End If
If errN = 3 Then
MsgBox ("成绩只能是[0-100]的整数")
errN = 0
End If
End Sub
Sub DoOk()
Dim b As Integer
Text1.Text = Val(Text1.Text)
b = Int(Val(Text1.Text) / 10)
Select Case b
Case 10, 9
Text2.Text = "优秀"
Case 8
Text2.Text = "良好"
Case 7
Text2.Text = "中等"
Case 6
Text2.Text = "及格"
Case 5, 4, 3, 2, 1, 0
Text2.Text = "不及格"
End Select
End Sub
-------------------------------------------
做个按钮让人退出,是不是更好点啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Static i As Integer
If KeyCode = "13" Then
If i = 3 Then
MsgBox "输入非法"
End
ElseIf Val(Text1) > 100 Or Val(Text1) < 0 Then
MsgBox "输入的成绩无效,请重新输入"
Text1 = ""
Text2 = ""
i = i + 1
ElseIf Val(Text1) > 85 Then
Text2 = "优秀"
ElseIf Val(Text1) > 70 Then
Text2 = "良好"
ElseIf Val(Text1) > 60 Then
Text2 = "及格"
Else
Text2 = "差劲"
End If
End If
End Sub
Static i As Integer
If KeyCode = "13" Then
If i = 3 Then
MsgBox "输入非法"
End
ElseIf Val(Text1) > 100 Or Val(Text1) < 0 Then
MsgBox "输入的成绩无效,请重新输入"
Text1 = ""
Text2 = ""
i = i + 1
ElseIf Val(Text1) > 85 Then
Text2 = "优秀"
ElseIf Val(Text1) > 70 Then
Text2 = "良好"
ElseIf Val(Text1) > 60 Then
Text2 = "及格"
Else
Text2 = "差劲"
End If
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询