Okay, first I must say I am new to this but I am a quick study. I have a project that works as coded except for in one instance of validation. I am accepting numeric input from the user and anytime the input is not numeric or no entry is given, I have coded a messagebox error within a Do-Loop to once again prompt for the correct input.
The problem is that the code works fine when any numbers are out of range and will display the proper messagebox error BUT when anything else like letters or no data is entered the code crashes during my validation. I have placed the code with validations below. Please tell me why the If statement in the Do-Loop seems to be failing. Thanks in advance for the help all.
The Freaky One
<Code Follows>
'Constant Variables
Dim Student As String
Dim Gr1 As Single
Dim Gr2 As Single
Dim Gr3 As Single
Dim Average As Single
Dim Grade As String
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'End Program
End
End Sub
Private Sub btnData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnData.Click
'Gather information
Do
Student = InputBox("Please enter the Student's Name:", "Student Name")
Loop While Student = ""
Do
Gr1 = InputBox("Please enter " & Student & "'s first test score:", "First Test Score")
If Not IsNumeric(Gr1) Or 100 >= Gr1 >= 0 Then
MessageBox.Show("Please enter a valid first test score.")
End If
Loop Until IsNumeric(Gr1) And Gr1 >= 0
Do
Gr2 = InputBox("Please enter " & Student & "'s second test score:", "First Test Score")
If Not IsNumeric(Gr2) Or 100 >= Gr2 >= 0 Then
MessageBox.Show("Please enter a valid second test score.")
End If
Loop Until IsNumeric(Gr2) And Gr2 >= 0
Do
Gr3 = InputBox("Please enter " & Student & "'s third test score:", "First Test Score")
If Not IsNumeric(Gr3) Or 100 >= Gr3 >= 0 Then
MessageBox.Show("Please enter a valid third test score.")
End If
Loop Until IsNumeric(Gr3) And Gr3 >= 0
'Calculate and Display Data
Average = (Gr1 + Gr2 + Gr3) / 3
If Average >= 90 Then
Grade = "A"
ElseIf Average >= 80 Then
Grade = "B"
ElseIf Average >= 70 Then
Grade = "C"
ElseIf Average >= 60 Then
Grade = "D"
Else : Grade = "F"
End If
lstTally.Items.Add(Student & " Average: " & Average.ToString & " Grade: " & Grade)
End Sub
End Class
</Code Ends>
The program runs normally and successfully when proper data is entered. Validation works properly for the name. Only the numeric responses are crashing out when non numeric input is entered.