Public Class GPA_Form
Private Sub exitButton_Click(sender As System.Object, e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub entdatButton_Click(sender As System.Object, e As System.EventArgs) Handles entdatButton.Click
Const Prompt As String = "Enter number of Credit Hours:"
Const Title As String = "Credit Hours"
Const Prompt2 As String = "Enter grades:"
Const Title2 As String = "Grades"
Dim inputCredit As String
Dim inputGrades As String
Dim creditHrs As Integer
Dim grades As Char
Dim gradesCounter As Integer
Dim creditHrsAccumulator As Integer
Dim point As Integer
Dim gpaTot As Integer
Dim pntAccumulator As Integer
inputCredit = InputBox(Prompt, Title)
inputGrades = InputBox(Prompt2, Title2)
Do While inputCredit <> String.Empty
Integer.TryParse(inputCredit, creditHrs)
Char.TryParse(inputGrades, grades)
gradesCounter += 1
creditHrsAccumulator += creditHrs
Select Case grades
Case Is >= "A"
point = 4
Case Is >= "B"
point = 3
Case Is >= "C"
point = 2
Case Is >= "D"
point = 1
Case Is >= "F"
point = 0
End Select
pntAccumulator += point
gpaTot = pntAccumulator / gradesCounter
tchData.Text = creditHrsAccumulator.ToString("N0")
numGrEnt.Text = gradesCounter.ToString("N0")
gpaData.Text = gpaTot.ToString("N2")
inputCredit = InputBox(Prompt, Title)
inputGrades = InputBox(Prompt2, Title2)
Loop
End Sub
End Class
我只是 Visual Basic 的初学者,但想知道我在计算 GPA 时哪里出错了,即使从 Select...Case 中积累一些东西也是可能的。如果不是,那么我将不得不以不同于上面显示的方式输入,当然。如果有人能给我提示我做错了什么,将不胜感激。