데이터 유형에 대한 입력 상자를 구문 분석 할 수 있는지 궁금하고 데이터 유형과 일치하지 않으면 올바른 유형이 완료 될 때까지 반복됩니다. 나는 범위로 이것을하는 방법을 이해하지만 그것이 가능하다면 오히려하지 않을 것이다.이 GoTo를 어떻게 제거합니까?
내가 가진 코드는 다음과 같습니다
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
나는 고토는 "오른쪽"또는 선호하는 해결책이 아니다는 것을 알고 있지만 나는 임시 장소 홀더로 더 것을 사용했다. 이것이 현재 나의 프로그래밍 능력을 초월한 어떤 도움이라도 인정 될 것입니다. 이 데이터 유형 에 대한 입력 상자를 구문 분석 할 수있는 경우
'Return'을 사용 하시겠습니까? –
예외 핸들러 추가 - http://msdn.microsoft.com/en-us/library/fk6t46tz.aspx – OldProgrammer
break 문을 사용할 수 있습니다 ... – Pankaj