I'm writing a program the allows Professor Carver to display a grade based on the number of possible points he enters in the inputbox (strMax). Then the user enters the points he earned in the textbox (dblPoints)
Then I solve the percentage. dblResults = dblPoints/CDbl(strMax)
The first step is to store the minimum percentage points in one dimensional array. I did that.
The second step is to store the grades in one dimensional array. I did that.
The arrays should be parallel arrays. <------ Having trouble with it
It then should display the corresponding grade from the strGrades array <---- Not done.
I'm having trouble to display arrays in that are parallel. The problem is the for loop
I tried this
For intGrade As Integer = 0 To 4
If dblResults <= dblPer(intGrade) Then
lblGrade.Text = strGrade(intGrade + 1)
ElseIf dblResults >= dblPer(0) Then
lblGrade.Text = strGrade(0)
Else
lblGrade.Text = strGrade(4)
End If
Next intGrade
I'm getting the error that says "Index was outside the bounds of the array." There's something wrong with the strGrade(intGrade+1), but no idea how to fix this.
I also tried this way
For intGrade As Integer = 0 To 4
If dblResults >= dblPer(intGrade) Then
lblGrade.Text = strGrade(intGrade + 1)
End If
Next intGrade
Still getting the same error?
Any help with the if statements? I don't understand what's wrong.
Thanks.
Here is the code in case you don't understand
Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
' display the grade the student gets
Dim dblPoints As Double
Dim dblResults As Double
Dim strGrade() As String =
{"A", "B", "C", "D", "F"}
Dim dblPer() As Double =
{0.9, 0.8, 0.7, 0.6, 0.5}
Double.TryParse(txtPoints.Text, dblPoints)
' displays the percentage the student recieves
dblResults = dblPoints / CDbl(strMax)
' determines the grade
For intGrade As Integer = 0 To 4
If dblResults >= dblPer(intGrade) Then
lblGrade.Text = strGrade(intGrade + 1)
End If
Next intGrade
End Sub
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' get the total number of possible points
strMax =
InputBox("Enter the total possible points.", "Professor Carver")
End Sub