Hello! Is there someone who can help me to make a timer on my entrance exam? I want every question last for only 30 seconds, after that, the next question will appear. Thanks and God Bless.! :D

Recommended Answers

All 5 Replies

Have you tried the code to load the listbox witth one item? i have pasted the code.
And have you not used the timer control?

Add timer control to ur form set the interval of the timer and make enable=true
and then in timer_click event write the cde what u want to do.

I did not used listboxes but I have seen your codes. I used textboxes and incremented some vaue but I'm still thankful. I'm still trying my timer control. Thanks and God Bless. :D

Add a timer to your form:

suppose u have a start button for exam start..and a timer named Timer1

here is a complete code with example:

Imports System.Data.OleDb
Public Class Form1
    Dim conn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim strQ As String = String.Empty
    Dim da As OleDbDataAdapter
    Dim ds As DataSet
    Dim i As Integer = 0


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database1.mdb;")

        ' filling the textbox of Question
        cmd = New OleDbCommand("Select * from Questions", conn)
        da = New OleDbDataAdapter(cmd)
        ds = New DataSet
        da.Fill(ds, "Questions")

        'filling the radiobutton according to the question number
        cmd = New OleDbCommand("Select * from QuestionChoices", conn)
        da = New OleDbDataAdapter(cmd)
        da.Fill(ds, "QuestionChoices")



        Me.TextBox1.Text = ds.Tables("Questions").Rows(i)(1).ToString()
        Me.RadioButton1.Text = ds.Tables("QuestionChoices").Rows(i)(1).ToString()
        Me.RadioButton2.Text = ds.Tables("QuestionChoices").Rows(i)(2).ToString()
        Me.RadioButton3.Text = ds.Tables("QuestionChoices").Rows(i)(3).ToString()
        Me.RadioButton4.Text = ds.Tables("QuestionChoices").Rows(i)(4).ToString()

        ' increment i to get next question
        i = i + 1

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Me.TextBox1.Text = ds.Tables("Questions").Rows(i)(1).ToString()
        Me.RadioButton1.Text = ds.Tables("QuestionChoices").Rows(i)(1).ToString()
        Me.RadioButton2.Text = ds.Tables("QuestionChoices").Rows(i)(2).ToString()
        Me.RadioButton3.Text = ds.Tables("QuestionChoices").Rows(i)(3).ToString()
        Me.RadioButton4.Text = ds.Tables("QuestionChoices").Rows(i)(4).ToString()

        i = i + 1
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Timer1.Enabled = True
        Me.Timer1.Interval = 5000
        Me.Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Call Button1_Click(Nothing, Nothing)
    End Sub
End Class

i have set interval to 5000 mili second (= 5 sec). questions will load every 5 sec

Wow! I am overwhelmed with the help you posted. I'll mark it as solved! Thank you and God Bless us. :D

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.