Back to Examples
Public Class frmAnswers
Private Sub frmAnswers_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strUser() As String = {frmExam.txt1.Text, frmExam.txt2.Text, frmExam.txt3.Text, frmExam.txt4.Text,
frmExam.txt5.Text, frmExam.txt6.Text, frmExam.txt7.Text, frmExam.txt8.Text, frmExam.txt9.Text,
frmExam.txt10.Text, frmExam.txt11.Text, frmExam.txt12.Text, frmExam.txt13.Text, frmExam.txt14.Text,
frmExam.txt15.Text, frmExam.txt16.Text, frmExam.txt17.Text, frmExam.txt18.Text, frmExam.txt19.Text, frmExam.txt20.Text}
Dim strAnswers() As String = {"B", "D", "A", "A", "C", "A", "B", "A", "C", "D", "B", "C", "D", "A", "D", "C", "C", "B", "D", "A"}
Dim strCorrect(19) As String
Dim intCorrect As Integer
Dim intWrong As Integer
For intQuestion = 0 To 19
If strUser(intQuestion) = strAnswers(intQuestion) Then
strCorrect(intQuestion) = "Correct"
intCorrect = intCorrect + 1
Else
strCorrect(intQuestion) = "Incorrect"
End If
Select Case strUser(intQuestion)
Case "A"
Case "B"
Case "C"
Case "D"
Case Else
intWrong = intWrong + 1
End Select
Next
If intWrong > 0 Then
MessageBox.Show("Please enter valid answers. Remember, answers must be UPPERCASE letters with NO period.")
Me.Close()
Else
lbl1.Text = strCorrect(0)
lbl2.Text = strCorrect(1)
lbl3.Text = strCorrect(2)
lbl4.Text = strCorrect(3)
lbl5.Text = strCorrect(4)
lbl6.Text = strCorrect(5)
lbl7.Text = strCorrect(6)
lbl8.Text = strCorrect(7)
lbl9.Text = strCorrect(8)
lbl10.Text = strCorrect(9)
lbl11.Text = strCorrect(10)
lbl12.Text = strCorrect(11)
lbl13.Text = strCorrect(12)
lbl14.Text = strCorrect(13)
lbl15.Text = strCorrect(14)
lbl16.Text = strCorrect(15)
lbl17.Text = strCorrect(16)
lbl18.Text = strCorrect(17)
lbl19.Text = strCorrect(18)
lbl20.Text = strCorrect(19)
lblScore.Text = "You scored " & intCorrect & " out of 20!"
If intCorrect > 14 Then
lblPass.Text = "You Passed, Congratulations!"
Else
lblPass.Text = "Sorry, you failed."
End If
End If
End Sub
End Class
Back to Examples