Results 1 to 2 of 2

Thread: Questions question....

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    29

    Questions question....

    I'm trying to make a basic general knowledge program with a set of questions all on one form. A labels caption holds the question and below it there are 4 option buttons with multiple choice answers. All this is housed in a frame, so that each question is separate. The title of each frame is 'Question 1, Question 2, question 3' etc. When you have answered all the questions you then press a button at the bottom of the form which checks whether correct answer has been selected. I want a message box to come up which will say "Well Done! You have got all the answers correct!!!" if you have got all the answers correct. If some have been answered incorrectly I want a messagebox to come up which will say "Sorry, but you got the following answers wrong: ----then it will list each question no. which the user answered incorrectly-----.

    As you can see from the following code, I am nowhere near close to finishing it!

    Private Sub Command1_Click()
    If (Option4.Value) And (Option6.Value) = True Then
    MsgBox "Well Done! You have got all the answers correct!!!"
    ElseIf Option4.Value = False Then
    MsgBox "You Got Question 1 wrong!"
    ElseIf Option6.Value = False Then
    MsgBox "You got question 2 wrong!"
    End If

    End Sub


    I would be most grateful for your comments and solutions.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Questions question....

    vb Code:
    1. Option Explicit
    2. Private Type QA
    3.     Question As String
    4.     Ans1 As String
    5.     Ans2 As String
    6.     Ans3 As String
    7.     Ans4 As String
    8.     CorrectAns As Integer
    9.     Correct As Boolean
    10. End Type
    11. Private QandA(1) As QA
    12. Private mintQuestion As Integer
    13.  
    14. Private Sub Command1_Click()
    15.  
    16.     Label1.Caption = QandA(mintQuestion).Question
    17.     Option1(0).Caption = QandA(mintQuestion).Ans1
    18.     Option1(1).Caption = QandA(mintQuestion).Ans2
    19.     Option1(2).Caption = QandA(mintQuestion).Ans3
    20.     Option1(3).Caption = QandA(mintQuestion).Ans4
    21.     Option1(0).Value = False
    22.     Option1(1).Value = False
    23.     Option1(2).Value = False
    24.     Option1(3).Value = False
    25. End Sub
    26.  
    27. Private Sub Form_Load()
    28.  
    29.     QandA(0).Question = "Who is the world's best programmer?"
    30.     QandA(0).Ans1 = "Joe"
    31.     QandA(0).Ans2 = "MartinLiss"
    32.     QandA(0).Ans3 = "Fred"
    33.     QandA(0).Ans4 = "Sam"
    34.     QandA(0).CorrectAns = 2
    35.    
    36.     Option1(0).Value = False
    37.     Option1(1).Value = False
    38.     Option1(2).Value = False
    39.     Option1(3).Value = False
    40.    
    41.     QandA(1).Question = "How much is 1 + 1?"
    42.     QandA(1).Ans1 = "2"
    43.     QandA(1).Ans2 = "6"
    44.     QandA(1).Ans3 = "All of the above"
    45.     QandA(1).Ans4 = "3"
    46.     QandA(1).CorrectAns = 1
    47.    
    48. End Sub
    49.  
    50.  
    51. Private Sub Option1_Click(Index As Integer)
    52.    
    53.     If Index + 1 = QandA(mintQuestion).CorrectAns Then
    54.         QandA(mintQuestion).Correct = True
    55.     Else
    56.         QandA(mintQuestion).Correct = False
    57.     End If
    58.     mintQuestion = mintQuestion + 1
    59.    
    60.     If mintQuestion > UBound(QandA) Then
    61.         ShowResults
    62.     End If
    63.    
    64.  
    65. End Sub
    66.  
    67. Public Sub ShowResults()
    68.  
    69.     Dim lngIndex As Long
    70.     Dim strErrors As String
    71.    
    72.     For lngIndex = 0 To UBound(QandA)
    73.         If Not QandA(lngIndex).Correct Then
    74.             strErrors = strErrors & lngIndex + 1 & ": " & QandA(lngIndex).Question & vbCrLf
    75.         End If
    76.     Next
    77.    
    78.     If strErrors = "" Then
    79.         MsgBox "Well Done! You have got all the answers correct!!!"
    80.     Else
    81.         MsgBox "Sorry, but you got the following answers wrong:" & vbCrLf & strErrors
    82.     End If
    83.        
    84.  
    85. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width