Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

Getting an error while running my application

$
0
0
I was working on a visual basic homework and I keep getting this error

"

this is the assignment I was working on

The local Registry of Motor Vehicles office has asked you to Create a software that grades the written portion of the driver's license exam. The exam has 20 more than one choice questions. Here are the correct answers to the questions.1. B 6. A 11. B 16. C
2. D 7. B 12. C 17. C
3. A 8. A 13. D 18. B
4. A 9. A 14. A 19. D
5. C 10.D 15. D 20. A
Your software should store the correct answers in an array. When the user clicks the Score Exam button, the software should display another form displaying if each question was answered correctly or incorrectly, and if the student passed of failed the exam. A student must correctly answer 15 of the 20 questions to pass the exam.
Input validation: Only accept the letters A,B,C, or D as answers.

This is what I have done so far

Public Class Form1

Private Sub btnScore_Click(sender As Object, e As EventArgs) Handles btnScore.Click
Dim 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 intCorrect As Integer = 0
Dim validInput As Integer = 0
Result.lstResults.Items.Clear()
Dim intCount As Integer = 0
Dim strInput(19) As String

strInput(0) = txtAnswer1.Text
strInput(1) = txtAnswer2.Text
strInput(2) = txtAnswer3.Text
strInput(3) = txtAnswer4.Text
strInput(4) = txtAnswer5.Text
strInput(5) = txtAnswer6.Text
strInput(6) = txtAnswer7.Text
strInput(7) = txtAnswer8.Text
strInput(8) = txtAnswer9.Text
strInput(9) = txtAnswer10.Text
strInput(10) = txtAnswer11.Text
strInput(11) = txtAnswer12.Text
strInput(12) = txtAnswer13.Text
strInput(13) = txtAnswer14.Text
strInput(14) = txtAnswer15.Text
strInput(15) = txtAnswer16.Text
strInput(16) = txtAnswer17.Text
strInput(17) = txtAnswer18.Text
strInput(18) = txtAnswer19.Text
strInput(19) = txtAnswer20.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
intCorrect += 1
dtlResult(intCorrect) = 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.lstResults.Items.Clear()
frmResult.lstResults.Items.Add("------------------------")
frmResult.lstResults.Items.Add("Drivers licence exam resluts")
frmResult.lstResults.Items.Add("-----------------------------")

For intCount = 0 To (19)
If (dtlResult(intCount) = True) Then
frmResult.lstResults.Items.Add(intCount + 1 & "Correct" & "Answer" & strGrades(intCount))
Else
frmResult.lstResults.Items.Add(intCount + 1 & "Wrong" & "Answer" & strGrades(intCount))
End If

Next intCount


frmResult.lstResults.Items.Add("---------------------")
frmResult.lstResults.Items.Add(" Total :" & intCorrect & " /20")
If (intCorrect >= 15) Then
frmResult.lstResults.Items.Add("Your Result :" & "PASS")
Else
frmResult.lstResults.Items.Add("Your Result :" & "Fail")

End If
frmResult.ShowDialog()

Else
MessageBox.Show(("Input should be A,B,C or D"), "InputBox Validation")
End If


End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txtAnswer1.Text = String.Empty
txtAnswer2.Text = String.Empty
txtAnswer3.Text = String.Empty
txtAnswer4.Text = String.Empty
txtAnswer5.Text = String.Empty
txtAnswer6.Text = String.Empty
txtAnswer7.Text = String.Empty
txtAnswer8.Text = String.Empty
txtAnswer9.Text = String.Empty
txtAnswer10.Text = String.Empty
txtAnswer11.Text = String.Empty
txtAnswer12.Text = String.Empty
txtAnswer13.Text = String.Empty
txtAnswer14.Text = String.Empty
txtAnswer15.Text = String.Empty
txtAnswer16.Text = String.Empty
txtAnswer17.Text = String.Empty
txtAnswer18.Text = String.Empty
txtAnswer19.Text = String.Empty
txtAnswer20.Text = String.Empty

End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()

End Sub
End Class



Please help! thanks!

Viewing all articles
Browse latest Browse all 27514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>