VB简单制作
哪位第1题:编写一个求成绩等级的程序。要求输入一个学生的考试成绩,输出其分数和对应的等级。共分五个等级:小于60分的为“E”;60~69分为“D”;70~79分为“C”;80~89分为“B”;90分以上为“A”。同时要求能够对错误的输入进行相应处理<如果输入A或者其他字母又或者大于100 或者小于0的数 就显示你输入的不符合要求 ,请重新输入》。[ 本帖最后由 bi1014227000 于 2011-5-28 12:47 编辑 ]
程序代码:
Option Explicit
Private Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
Dim High_Low As String
Private Sub Command1_Click()
Dim Scores As Integer
High_Low = "Z"
If Text1.Text <> "" And InStr(Text1.Text, "Enter the test scores !") = 0 Then
Scores = Val(Text1.Text)
If IsNumeric(Scores) = True Then
If Scores > 100 Or Scores < 0 Then
MsgBox "Enter the Results of Range , Please !"
Exit Sub
Else
If UCase(High_Low) = "Z" Then High_Low = IIf(Scores < 50, "F", "Z"): If High_Low = "F" Then Label2.Caption = High_Low: Exit Sub
If UCase(High_Low) = "Z" Then High_Low = IIf((Scores >= 50 And Scores < 60), "E", "Z"): If High_Low <> "Z" Then Label2.Caption = High_Low: Exit Sub
If UCase(High_Low) = "Z" Then High_Low = IIf((Scores >= 60 And Scores < 70), "D", "Z"): If High_Low <> "Z" Then Label2.Caption = High_Low: Exit Sub
If UCase(High_Low) = "Z" Then High_Low = IIf((Scores >= 70 And Scores < 80), "C", "Z"): If High_Low <> "Z" Then Label2.Caption = High_Low: Exit Sub
If UCase(High_Low) = "Z" Then High_Low = IIf((Scores >= 80 And Scores < 90), "B", "Z"): If High_Low <> "Z" Then Label2.Caption = High_Low: Exit Sub
If UCase(High_Low) = "Z" Then High_Low = IIf((Scores >= 90 And Scores < 100), "A", "Z"): If High_Low <> "Z" Then Label2.Caption = High_Low: Exit Sub
If UCase(High_Low) = "Z" Then High_Low = IIf(Scores = 100, "A+", "A"): If High_Low <> "Z" Then Label2.Caption = High_Low: Exit Sub
If UCase(High_Low) = "Z" Then Label2.Caption = High_Low: Exit Sub
End If
If UCase(High_Low) = "Z" Then Exit Sub
End If
Else
If InStr(Text1.Text, "Enter the test scores !") <> 0 Then Exit Sub
End If
End Sub
Private Sub Form_Initialize()
High_Low = "Z"
End Sub
Private Sub Form_Load()
If App.PrevInstance Then
Call MsgBox("This program has been executed !", vbCritical, "Warning")
Unload Me
End If
SetCurrentDirectory App.Path
frmMain.Caption = frmMain.Caption & " Ver " & App.Major & "." & App.Minor & "." & App.Revision
Text1.Text = " Enter the test scores !"
Label2.Caption = "Level not determined !"
End Sub
Private Sub NewCalcu()
High_Low = ""
Text1.Text = " Enter the test scores !"
Label2.Caption = "Level not determined !"
End Sub
Private Sub Text1_Click()
Call NewCalcu
Text1.Text = ""
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then Call Command1_Click
End Sub
Private Sub Text1_LostFocus()
If Text1.Text = "" Then Text1.Text = " Enter the test scores !"
End Sub
