データ型の入力ボックスを解析できるかどうかに興味があります。データ型と一致しない場合は、正しい型が完了するまでループします。範囲でこれを行う方法は理解していますが、可能であればそうではありません。
私が持っているコードは次のとおりです。
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
GoTo が「正しい」または推奨されるソリューションではないことはわかっていますが、それを一時的なプレースホルダーとして使用しました。これは現在の私のプログラミング能力を超えているため、どんな助けもいただければ幸いです。