Computer Science Canada

Help on multiple choice quiz program

Author:  randomperson [ Thu Dec 22, 2005 9:56 pm ]
Post subject:  Help on multiple choice quiz program

Hi, I am pretty new to VB and i need some help:

I am creating a multiple choice quiz application that generates or selects questions randomly and displays to the user one afte another, each time they press a button. Since it is random, I want to make sure that each question only appears once.

Here is my code so far.

code:

Private Sub Command1_Click()

Dim Question(1 To 3) As String, num(1 To 3) As Integer, X As Integer
Dim a As Integer, Count As Integer, Q As String, Z As Integer
Dim fl1 As Boolean, fl2 As Boolean, fl3 As Boolean              'To exit the code

Question(1) = "What is the capital of Austraila?"
Question(2) = "What is 1+1?"
Question(3) = "Which came first, the chicken or the egg?"

'This is to ensure that each question only appears once
For Count = 1 To 3
    num(Count) = Int(Rnd * 3 + 1)
   
    For a = 1 To Count
        If a < Count Then
            If num(Count) = num(a) Then
                    Count = Count - 1
                    Exit For
            End If
        End If
    Z = num(Count)
    Next a
Next Count

X = 0
   
Select Case Z

    Case 1
    Q = Question(1)
    Label1.Caption = Q
    opt1.Caption = "Brisbane"
    opt2.Caption = "Sydney"
    opt3.Caption = "Canberra"
    If opt3.Value = True Then
    X = X + 1
    End If
    fl1 = True
   
    Case 2
    Label1.Caption = Q
    Q = Question(2)
    opt1.Caption = "2"
    opt2.Caption = "11"
    opt3.Caption = "Window"
    If opt1.Value = True Then
    X = X + 1
    End If
    fl2 = True
   
    Case 3
    Label1.Caption = Q
    Q = Question(3)
    opt1.Caption = "Chicken"
    opt2.Caption = "Egg"
    opt3.Caption = "Who Cares?"
    If opt3.Value = True Then
    X = X + 1
    End If
    fl3 = True
   
End Select

If fl1 = True And fl2 = True And fl3 = True Then
    MsgBox "scored " & X & " points", vbInformation, "X"
End If

End Sub


So far i is not going too well. This is just a working model. Once I figure out the problems with this, then I will make my actual one

Author:  Tony [ Fri Dec 23, 2005 1:59 pm ]
Post subject: 

well you'd need to make a list of random unique numbers..

there's turing code that you could translate into VB


: