vb Code:
Option Explicit
Private Type QA
Question As String
Ans1 As String
Ans2 As String
Ans3 As String
Ans4 As String
CorrectAns As Integer
Correct As Boolean
End Type
Private QandA(1) As QA
Private mintQuestion As Integer
Private Sub Command1_Click()
Label1.Caption = QandA(mintQuestion).Question
Option1(0).Caption = QandA(mintQuestion).Ans1
Option1(1).Caption = QandA(mintQuestion).Ans2
Option1(2).Caption = QandA(mintQuestion).Ans3
Option1(3).Caption = QandA(mintQuestion).Ans4
Option1(0).Value = False
Option1(1).Value = False
Option1(2).Value = False
Option1(3).Value = False
End Sub
Private Sub Form_Load()
QandA(0).Question = "Who is the world's best programmer?"
QandA(0).Ans1 = "Joe"
QandA(0).Ans2 = "MartinLiss"
QandA(0).Ans3 = "Fred"
QandA(0).Ans4 = "Sam"
QandA(0).CorrectAns = 2
Option1(0).Value = False
Option1(1).Value = False
Option1(2).Value = False
Option1(3).Value = False
QandA(1).Question = "How much is 1 + 1?"
QandA(1).Ans1 = "2"
QandA(1).Ans2 = "6"
QandA(1).Ans3 = "All of the above"
QandA(1).Ans4 = "3"
QandA(1).CorrectAns = 1
End Sub
Private Sub Option1_Click(Index As Integer)
If Index + 1 = QandA(mintQuestion).CorrectAns Then
QandA(mintQuestion).Correct = True
Else
QandA(mintQuestion).Correct = False
End If
mintQuestion = mintQuestion + 1
If mintQuestion > UBound(QandA) Then
ShowResults
End If
End Sub
Public Sub ShowResults()
Dim lngIndex As Long
Dim strErrors As String
For lngIndex = 0 To UBound(QandA)
If Not QandA(lngIndex).Correct Then
strErrors = strErrors & lngIndex + 1 & ": " & QandA(lngIndex).Question & vbCrLf
End If
Next
If strErrors = "" Then
MsgBox "Well Done! You have got all the answers correct!!!"
Else
MsgBox "Sorry, but you got the following answers wrong:" & vbCrLf & strErrors
End If
End Sub