I am developing an application for people to learn but i realised the need to time the quizzes in the programme. Could someone please help me with a sample multiple question codes with timer?
So far this is what i got:

Public Class Form1
Dim questions(2, 4) As String
Dim answers(9) As String
Dim quesNum As Integer
Private Sub GetQuestions()
    questions = New String(,) {{"The following steps will launch Microsoft Access", "Start->Microsoft Access", "Start->All Programs->Microsoft Office->Microsoft Access", "My Access", "Start->All Programs->Microsoft Office->Microsoft Access"}, _
            {"Which of these is an example of datatype in MS Access?", "Text", "Digits", "Pictures", "Text"}, _
            {"______ is a short-cut for saving work in MS Access?", "Save", "Ctrl+S", "Ctrl+P", "Ctrl+S"}, _
            {"This key uniquely identifies each record?", "Unique Key", "Password", "Primary Key", "Primary Key"}, _
            {"Which of the following is not a database object?", "Relationships", "Queries", "Tables", "Relationships"}, _
            {"Which of the following database object hold data?", "Forms", "Report", "Tables", "Tables"}, _
            {"A __ enables you to view data from a table based on a specific criterion?", "Form", "Query", "Report", "Query"}, _
            {"What are the columns in a Microsoft Access table called?", "Rows", "Records", "Fields", "Fields"}, _
            {"Collection of related records in a database is known as?", "Relationship", "Table", "File", "Relationship"}, _
    {"Microsoft Access is a?", "Relational Database Management System", "Object Oriented Database Management System", "Access Database", "Relational Database Management System"}}
End Sub
Private Sub MarkTest()
    Dim grade As Integer = 0
    For i = 0 To 9
        If answers(i) = questions(i, 4) Then
            grade += 1
        End If
    Next
    Label1.Text = "Test finished!"
    Label2.Text = "You scored " & grade & " out of " & answers.Length & "!"
    RadioButton1.Enabled = False
    RadioButton2.Enabled = False
    RadioButton3.Enabled = False
    Button1.Enabled = False
    Button2.Enabled = False
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Text = "My Multiple Choice Quiz!"
    GetQuestions()
    quesNum = 1
    Label1.Text = "Question " & quesNum & " of " & answers.Length
    Label2.Text = questions(0, 0)
    Button1.Text = "Previous"
    Button2.Text = "Next"
    RadioButton1.Text = questions(0, 1)
    RadioButton2.Text = questions(0, 2)
    RadioButton3.Text = questions(0, 3)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If quesNum > 1 Then
        quesNum -= 1
        Label1.Text = "Question " & quesNum & " of 10"
        Label2.Text = questions(quesNum - 1, 0)
        RadioButton1.Text = questions(quesNum - 1, 1)
        RadioButton2.Text = questions(quesNum - 1, 2)
        RadioButton3.Text = questions(quesNum - 1, 3)
    End If
    If Button2.Text = "Submit" Then
        Button2.Text = "Next"
    End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    If RadioButton1.Checked = True Then
        answers(quesNum - 1) = RadioButton1.Text
    ElseIf RadioButton2.Checked = True Then
        answers(quesNum - 1) = RadioButton2.Text
    ElseIf RadioButton3.Checked = True Then
        answers(quesNum - 1) = RadioButton3.Text
    End If
    RadioButton1.Focus()
    If quesNum < 10 Then
        quesNum += 1
        Label1.Text = "Question " & quesNum & " of " & answers.Length
        Label2.Text = questions(quesNum - 1, 0)
        RadioButton1.Text = questions(quesNum - 1, 1)
        RadioButton2.Text = questions(quesNum - 1, 2)
        RadioButton3.Text = questions(quesNum - 1, 3)
        If quesNum = 10 Then
            Button2.Text = "Submit"
        End If
    Else
        MarkTest()
    End If
End Sub

End Class

Recommended Answers

All 4 Replies

Here is a short tutorial on Timer.
Do you want to time every question or just the global test?
Tip:
If you see frequently duplicated code like

RadioButton1.Text = questions(0, 1)
RadioButton2.Text = questions(0, 2)
RadioButton3.Text = questions(0, 3)

turn it into a method.

Oops, forgot to paste the link, so here it is Timer tutorial.
This post will probably be moved to a more appropriate place I guess.

I want to time the whole questions not but not individual questions

Thank you

So one Timer will be sufficient. Guess you are able to bring this to a good end.
If you should have problems, please ask!

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.