回复 10楼 wube
我觉得wube完全是在误人子弟,用得着那么复杂吗?有好几个地方完全是多此一举,如:1:完全没必要用api
2:前一句 Scores = Val(Text1.Text),紧接着If IsNumeric(Scores) = True Then岂不是废话
3:同理Command1_Click过程的第一句就High_Low = "Z",后面的许多句If UCase(High_Low) = "Z"完全没必要
4:对这类求作业的初学者完全不应该理会,我前面不小心理会了是因为这类算法可以不需要使用判断语句的,而你用一大堆判断完全在浪费资源。
5:你的代码有一处错误,如果重复加载程序会不能退出的,会反复提示,在unload me后需加句exit sub。
我同样使用了你的工程文件完成同样的功能,我的代码如下,敬请指正!
Private Sub Command1_Click()
Dim a As Integer
If Not IsNumeric(Text1) Then
Text1_LostFocus
Exit Sub
End If
a = Val(Text1)
If a >= 0 And a <= 100 Then
a = Int(a / 10)
If a < 6 Then a = 5
If a > 9 Then a = 9
a = 74 - a
Label2.Caption = "你的成绩等级为:" & Chr(a)
Else
MsgBox "Enter the Results of Range , Please !"
End If
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub
Private Sub Form_Load()
If App.PrevInstance Then
MsgBox "程序已加载,不能重复加载。", vbCritical, "Warning"
Unload Me
Exit Sub
End If
frmMain.Caption = frmMain.Caption & " Ver " & App.Major & "." & App.Minor & "." & App.Revision
Text1_LostFocus
End Sub
Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
'只允许输入的数字
If (KeyAscii > 47 And KeyAscii < 58) Or KeyAscii = 8 Or KeyAscii = 45 Then Exit Sub
If KeyAscii = 13 Then Command1_Click '如果是回车确认即给出成绩等级
KeyAscii = 0
End Sub
Private Sub Text1_LostFocus()
If Not IsNumeric(Text1) Then
Text1.Text = " Enter the test scores !"
Label2.Caption = "Level not determined !"
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End If
End Sub
q12改.rar
(6.84 KB)
[ 本帖最后由 lowxiong 于 2011-5-28 06:42 编辑 ]