The menu strip must be created programmatically (ie NOT dragged and dropped onto the form). The exit option added to the menu strip must exit the application (This works)
A structure must be created to encapsulate all the questions and suggested answers. The structure must contain:
1.Question String
2.Answers Collection
3.Correct Answer String
When the form loads, 5 questions must be created in code using these structures. These 5 structures will then serve as the quiz. The user must be shown the first question, and have the option of browsing forwards and backwards through the quiz. The program should store saved answers to select the radio button when users cycle through. This can be done by any means possible, for example an ArrayList or SortedList.
The suggested answers must be randomized the first time the form loads only.
Once the user has selected an answer for every question, the Submit button should be enabled. When the user clicks this button, the program must then evaluate the quiz and compare the users selected answers against the correct answer. A valid message must then be displayed via a MessageBox indicating the users score.
Here is what I have done so far:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim mnuMain As MainMenu = New MainMenu()

        Dim exitApp As MenuItem = mnuMain.MenuItems.Add("Exit")
        Me.Menu = mnuMain

        For Each m As MenuItem In mnuMain.MenuItems
            AddHandler m.Click, AddressOf HandleMenuItemClick
        Next
    End Sub

    Private Sub HandleMenuItemClick(ByVal sender As System.Object, _
                                    ByVal e As System.EventArgs)

        If (Not (TypeOf (sender) Is MenuItem)) Then
            Throw New Exception("HandleMenuItemClick called incorrectly!")
        End If

        Dim s As MenuItem = CType(sender, MenuItem)
        Application.Exit()

    End Sub

End Class

Module Module1
    Sub Main()
        Dim question1 As Quiz = New Quiz("What is the fastest animal on the planet?", "Cheetah")
        Dim question2 As Quiz = New Quiz("What is the largest animal on the planet?", "Elephant")
        Dim question3 As Quiz = New Quiz("Which of these animals can survive in water and land?", "Crocodile")
        Dim question4 As Quiz = New Quiz("Which one of these animals is considered to be the King of the wild?", "Lion")
        Dim question5 As Quiz = New Quiz("Which one of these animals carry venom in their fangs?", "Snake")

    End Sub

    Public Structure Quiz
        Dim question As String
        Dim correctAnswer As String

        Public Sub New(ByVal newQuestion As String, _
                       ByVal newCorrectAnswer As String)
            question = newQuestion
            correctAnswer = newCorrectAnswer
        End Sub
    End Structure
End Module

**Am I on the right track? Where should I create the 5 arrays that hold the possible answers? What should I use to make it possible for the user to cycle through the questions? Any help will be very much appreciated. **

Recommended Answers

All 7 Replies

So far, it looks as if you are on the right track.

Now you will have to generate some false answers; such as creating an array of known false answers and pull randomly from that arra

[Useless copy-pasted post deleted.]

Is it just me or does it seem that Branickiod just copy > pasted from a project/product description?

Yeah that was very helpful...

Public Class Form1
    'Random class declaration
    Dim r As Random = New Random()

    'Variable declarations
    Dim questions(4) As String
    Dim score As String
    Dim timesClicked As Integer

    'Create new instances of the Quiz structure
    Dim question1 As Quiz = New Quiz("What is the fastest animal on the planet?", "Cheetah")
    Dim question2 As Quiz = New Quiz("What is the largest animal on the planet?", "Elephant")
    Dim question3 As Quiz = New Quiz("Which of these animals can survive in water and land?", "Crocodile")
    Dim question4 As Quiz = New Quiz("Which one of these animals is considered to be the King of the wild?", "Lion")
    Dim question5 As Quiz = New Quiz("Which one of these animals carry venom in their fangs?", "Snake")

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        btnSubmit.Enabled = False

        'Put all questions in an array
        questions(0) = question1.question
        questions(1) = question2.question
        questions(2) = question3.question
        questions(3) = question4.question
        questions(4) = question5.question

        'To generate a random question
        Dim randomQuestion As String = questions(r.Next(5))

        'Do a check on which question was generated, change radiobutton text accordingly
        If randomQuestion = question1.question Then

            lblQuestionTxt.Text = question1.question
            rdbtnA1.Text = "Hiyena"
            rdbtnA2.Text = "Ostrich"
            rdbtnA3.Text = "Zebra"
            rdbtnA4.Text = question1.correctAnswer

        ElseIf randomQuestion = question2.question Then

            lblQuestionTxt.Text = question2.question
            rdbtnA1.Text = "Giraffe"
            rdbtnA2.Text = "Anaconda"
            rdbtnA3.Text = question2.correctAnswer
            rdbtnA4.Text = "Gorilla"

        ElseIf randomQuestion = question3.question Then

            lblQuestionTxt.Text = question3.question
            rdbtnA1.Text = "Baboon"
            rdbtnA2.Text = question3.correctAnswer
            rdbtnA3.Text = "Aardvark"
            rdbtnA4.Text = "Lizzard"

        ElseIf randomQuestion = question4.question Then

            lblQuestionTxt.Text = question4.question
            rdbtnA1.Text = question4.correctAnswer
            rdbtnA2.Text = "Ferret"
            rdbtnA3.Text = "Pig"
            rdbtnA4.Text = "Cow"

        ElseIf randomQuestion = question5.question Then

            lblQuestionTxt.Text = question5.question
            rdbtnA1.Text = question5.correctAnswer
            rdbtnA2.Text = "Leopard"
            rdbtnA3.Text = "Turtle"
            rdbtnA4.Text = "Bat"
        End If


        'Create the MainMenu object
        Dim mnuMain As MainMenu = New MainMenu()

        'Add a menu item to the main menu
        Dim exitApp As MenuItem = mnuMain.MenuItems.Add("Exit")

        'Refers to the current instance of the Menu
        Me.Menu = mnuMain

        For Each m As MenuItem In mnuMain.MenuItems
            'Addhandler used to handle the event
            AddHandler m.Click, AddressOf HandleMenuItemClick
        Next
    End Sub

    Private Sub HandleMenuItemClick(ByVal sender As System.Object, _
                                    ByVal e As System.EventArgs)

        If (Not (TypeOf (sender) Is MenuItem)) Then
            'Throws a new exception
            Throw New Exception("HandleMenuItemClick called incorrectly!")
        End If

        Dim s As MenuItem = CType(sender, MenuItem)
        'Exit the application
        Application.Exit()
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        'Increment the timesChecked variable each time the user presses the "Next" button
        timesClicked = timesClicked + 1

        'Do a check on the number of times the user clicked the "Next" button
        If timesClicked = 6 Then
            'Disable the "Next" button
            btnNext.Enabled = False
            btnSubmit.Enabled = True
        End If

        'Do a check on the question currently visible to the user, calculate score and then generate next question. 
        If lblQuestionTxt.Text = question1.question Then
            If rdbtnA4.Checked = True Then

                score = score + 1

            End If

            lblQuestionTxt.Text = question2.question
            rdbtnA1.Text = "Giraffe"
            rdbtnA2.Text = "Anaconda"
            rdbtnA3.Text = "Elephant"
            rdbtnA4.Text = "Gorilla"

        ElseIf lblQuestionTxt.Text = question2.question Then

            If rdbtnA4.Checked = True Then
                score = score + 1
            End If

            lblQuestionTxt.Text = question3.question
            rdbtnA1.Text = "Baboon"
            rdbtnA2.Text = "Crocodile"
            rdbtnA3.Text = "Aardvark"
            rdbtnA4.Text = "Lizzard"

        ElseIf lblQuestionTxt.Text = question3.question Then
            If rdbtnA2.Checked = True Then
                score = score + 1
            End If

            lblQuestionTxt.Text = question4.question
            rdbtnA1.Text = "Lion"
            rdbtnA2.Text = "Ferret"
            rdbtnA3.Text = "Pig"
            rdbtnA4.Text = "Cow"

        ElseIf lblQuestionTxt.Text = question4.question Then

            If rdbtnA1.Checked = True Then
                score = score + 1
            End If

            lblQuestionTxt.Text = question5.question
            rdbtnA1.Text = "Snake"
            rdbtnA2.Text = "Leopard"
            rdbtnA3.Text = "Turtle"
            rdbtnA4.Text = "Bat"

        ElseIf lblQuestionTxt.Text = question5.question Then

            If rdbtnA1.Checked = True Then
                score = score + 1
            End If

            lblQuestionTxt.Text = question1.question
            rdbtnA1.Text = "Hiyena"
            rdbtnA2.Text = "Ostrich"
            rdbtnA3.Text = "Zebra"
            rdbtnA4.Text = "Cheetah"
        End If
    End Sub

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        'The user is shown his/her score
        MessageBox.Show("Your score is : " + score + "/5")
        'The application starts again
        Application.Restart()
    End Sub
End Class

'Declare a public structure
Public Structure Quiz
    'Instance variables
    Dim question As String
    Dim correctAnswer As String

    'Constructor is created
    Public Sub New(ByVal newQuestion As String, _
                   ByVal newCorrectAnswer As String)
        'Assign a value to each of the instance variables
        question = newQuestion
        correctAnswer = newCorrectAnswer
    End Sub
End Structure

This is the best I could come up with

Looks good, great job!

Are you having any issues with it?

Nothing too serious thankfully. Made a few adjustments to the code above before handing the project in and I got a respectable mark :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.