I am curious if it is possible to parse an input box for a data type and if it does not match the data type it will loop until the correct type is done. I understand how to do this with ranges but would rather not if it is possible.
The code I have is:
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim amountAssignments As Integer
Dim pointsEarned As Integer = 0
Dim pointsEarnedTotal As Integer = 0
Dim pointsPossible As Integer = 0
Dim pointsPossibleTotal As Integer = 0
Dim Assignment As Integer = 1
Integer.TryParse(txtAmount.Text, amountAssignments)
Do Until Assignment > amountAssignments
txtAmount.Text = String.Empty
pointsEarned = Integer.Parse(InputBox("Please enter the amount, as a whole number, of Points Earned for Assignment " & Assignment & ":"))
On Error GoTo Check
pointsEarnedTotal = pointsEarnedTotal + pointsEarned
pointsPossible = Integer.Parse(InputBox("Please enter the amount, as a whole number, of Points Possible for Assignment " & Assignment & ":"))
On Error GoTo Check
pointsPossibleTotal = pointsPossibleTotal + pointsPossible
Assignment = Assignment + 1
Loop
lblGrade.Text = (pointsEarnedTotal / pointsPossibleTotal)
Check:
MessageBox.Show("An error has occured, most likely due to an improper value in the points earned or possible box. Please try running the program again with proper values.", "Please run the program again", _
MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End Sub
I know that GoTo isn't a "right" or preferred solution but I used that more as a temporary place holder. Any help would be appreciated as this is beyond my programming abilities currently.