I have this code. I enter three grades into 3 different textbox and then click a submit button that displays the grades in a listbox. Works well except for this. When I enter one or two grades only and click submit I get error message "Exception was unhandeled". How would I code this to prevent this from happening. The Error Happens here.
' retrieve the student's grades
grades(studentCount, 0) = Convert.ToInt32(test1TextBox.Text)
grades(studentCount, 1) = Convert.ToInt32(test2TextBox.Text)
grades(studentCount, 2) = Convert.ToInt32(test3TextBox.Text)
Private Sub submitButton_Click(sender As Object,
e As EventArgs) Handles submitButton.Click
' process one student's grades
' retrieve the student's grades
grades(studentCount, 0) = Convert.ToInt32(test1TextBox.Text)
grades(studentCount, 1) = Convert.ToInt32(test2TextBox.Text)
grades(studentCount, 2) = Convert.ToInt32(test3TextBox.Text)
' begin creating String containing the student's grades and average
Dim output As String = "Student " & studentCount & vbTab
' append each test grade to the output
For column = 0 To grades.GetUpperBound(1)
' if the Letter RadioButton is checked
If letterRadioButton.Checked = True Then
' append letter grade to the output
output &= vbTab & LetterGrade(grades(studentCount, column))
Else
' append number grade to the output
output &= vbTab & grades(studentCount, column)
End If
Next
' append the student's test average to the output
output &= vbTab & CalculateStudentAverage(studentCount)
gradesListBox.Items.Add(output) ' add output to the ListBox
studentCount += 1 ' update number of students entered
lblClassAverageResult.Text = CalculateClassAverage() ' display class average
DisplayBarChart() ' display the current grade distribution
' clear the input TextBoxes and set focus to first TextBox
test1TextBox.Clear()
test2TextBox.Clear()
test3TextBox.Clear()
test1TextBox.Focus()
' limit number of students
If studentCount = grades.GetUpperBound(0) + 1 Then
inputGradesGroupBox.Enabled = False ' disable GroupBox's controls
End If
End Sub ' submitButton_Click