Private Sub ButScore_Click(ByVal sender As System.Object, ByVal e As System.Even
ID: 3640491 • Letter: P
Question
Private Sub ButScore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButScore.ClickDim strGrades() As String = {"B", "D", "A", "A", "C", "A", "B", "A", "C", "D", "B", "C", "D", "A", "D", "C", "C", "B", "D", "A"}
Dim dtlResult(19) As Boolean
Dim incorrect As Integer = 0
Dim validInput As Integer = 0
Result.lstResult.Items.Clear()
Dim intCount As Integer = 0
Dim strInput(19) As String
strInput(0) = txt1.Text
strInput(1) = txt2.Text
strInput(2) = Txt3.Text
strInput(3) = txt4.Text
strInput(4) = txt5.Text
strInput(5) = txt6.Text
strInput(6) = txt7.Text
strInput(7) = txt8.Text
strInput(8) = txt9.Text
strInput(9) = txt10.Text
strInput(10) = txt11.Text
strInput(11) = txt12.Text
strInput(12) = txt13.Text
strInput(13) = txt14.Text
strInput(14) = txt15.Text
strInput(15) = txt15.Text
strInput(16) = txt17.Text
strInput(17) = txt18.Text
strInput(18) = txt19.Text
strInput(19) = txt20.Text
Try
For intCount = 0 To (strGrades.Length - 1)
If strInput(intCount).ToUpper() = "A" Or
strInput(intCount).ToUpper() = "B" Or
strInput(intCount).ToUpper() = "C" Or
strInput(intCount).ToUpper() = "D" Then
If strGrades(intCount) = strInput(intCount).ToUpper() Then
incorrect += 1
dtlResult(intCount) = True
End If
validInput = validInput + 1
End If
Next intCount
Catch ex As Exception
End Try
If validInput = 20 Then
Dim frmResult As New Result
frmResult.lstResult.Items.Clear()
frmResult.lstResult.Items.Add("..................")
frmResult.lstResult.Items.Add("Driver's License Exam Results")
frmResult.lstResult.Items.Add("..........")
For inCount = 0 To (20)
If (dtlResult(intCount) = True) Then
frmResult.lstResult.Items.Add(inCount + 1 & "Correct" & " Answer: " & strGrades(intCount))
Else
frmResult.lstResult.Items.Add(inCount + 1 & "Wrong" & " Answer: " & strGrades(intCount))
End If
Next inCount
frmResult.lstResult.Items.Add("....")
frmResult.lstResult.Items.Add(" Total :" & incorrect & " /20")
If (incorrect >= 15) Then
frmResult.lstResult.Items.Add("The Result is:" & " PASS")
Else
frmResult.lstResult.Items.Add("The Result is:" & " FAIL")
End If
frmResult.ShowDialog()
Else
MessageBox.Show("Input must be A, B, C, D", "Input Validation")
End If
Explanation / Answer
This is what I think.. Firstly dtlResult doesnt have a default initialization. You are only initializing this in a Try statement dtlResult(intCount) = True and trying to access it later on. That try block might not be getting executed and hence your dtlResult(intCount) might have some garbage value in it.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.