I have been struggling with this for 4 days - Please help. I have attached a copy of my code with the hope that someone here can give me some insight as to what I am missing. (This is a homework assignment, so please keep that in mind. I am not looking for someone to do my work for me, but instead, to provide guidance.)

Brief Overview of project:
Simple math quiz that presents 10 multiplication problems and tallys the results to be displayed at the end. Each problem has 5 seconds to be completed before it is counted as incorrect and the program moves on to the next.

Issues:
1. I have a timer attached to math problems that counts down from 5 seconds for each, but when the timer runs out it does not add to the incorrect answer tally.

  1. My If statement is set to stop presenting new questions after the 10th and to display the results, however it continues to present new problems.

My code:

Option Explicit On
Option Strict On
Option Infer Off

Public Class frmMain
    Dim intTimeLeft, intCorrect, intInCorrect As Integer

    Private Sub GenerateAndDisplayIntegers()
        ' generates and displays two random integers

        Dim intRandom1, intRandom2 As Integer
        Dim randomGenerator As New Random
        ' generate random integers
        intRandom1 = randomGenerator.Next(1, 10)
        intRandom2 = randomGenerator.Next(1, 10)
        ' display integers
        lblNum1.Text = Convert.ToString(intRandom1)
        lblNum2.Text = Convert.ToString(intRandom2)

        txtAnswer.Text = String.Empty
        intTimeLeft = 5
        lblTimer.Text = intTimeLeft.ToString
        tmrAnswer.Start()

    End Sub

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        ' starts math test

        Call GenerateAndDisplayIntegers()
        intTimeLeft = 5
        lblTimer.Text = intTimeLeft.ToString
        tmrAnswer.Start()
    End Sub

    Private Sub btnAnswer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAnswer.Click
        ' calculates the correct answer and then compares the correct answer to the user's answer
        ' keeps track of the number of correct and incorrect responses

        Dim x, intNum1, intNum2, intUserAnswer, intCorrectAnswer As Integer

        x = 1

        If x < 10 Then

            Integer.TryParse(lblNum1.Text, intNum1)
            Integer.TryParse(lblNum2.Text, intNum2)
            Integer.TryParse(txtAnswer.Text, intUserAnswer)

            intCorrectAnswer = intNum1 * intNum2

            If intUserAnswer = intCorrectAnswer Then
                intCorrect += 1

            ElseIf intTimeLeft > 0 Then
                intInCorrect = intInCorrect + 1

            Else
                intCorrect = intCorrect + 1

            End If

            Call GenerateAndDisplayIntegers()
            x = x + 1

        Else
            lblNum1.Text = String.Empty
            lblNum2.Text = String.Empty
            txtAnswer.Text = String.Empty
            lblTimer.Text = "Done"

            lblCorrect.Text = intCorrect.ToString
            lblIncorrect.Text = intInCorrect.ToString

        End If

    End Sub

    Private Sub tmrAnswer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAnswer.Tick
        If intTimeLeft > 0 Then
            intTimeLeft -= 1
            lblTimer.Text = intTimeLeft.ToString
            'Else

            tmrAnswer.Stop()

            '    txtAnswer.Text = String.Empty
            '    Call GenerateAndDisplayIntegers()
            '    intTimeLeft = 5
            '    lblTimer.Text = intTimeLeft.ToString
            '    tmrAnswer.Start()

        End If

    End Sub

End Class
AndreRet commented: Thanx for showing effort, I'll gladly help as far as I can... +12

First, not sure what this is, a timer or some time controlled sub?

tmrAnswer.Start()

Ahhh, don't worry, vb.net timer enabled code. This is a vb6 forum. Lets see if we can see you through this. I'd rather make use of proper timing sequences used. This is what I have been using in vb6, can do the exact same thing in vb.net -

Public Sub wait(ByVal dblMilliseconds As Double)

Dim dblStart As Double
Dim dblEnd As Double
Dim dblTickCount As Double

dblTickCount = GetTickCount()
dblStart = GetTickCount()
dblEnd = GetTickCount + dblMilliseconds

Do
    DoEvents
    dblTickCount = GetTickCount()
Loop Until dblTickCount > dblEnd Or dblTickCount < dblStart
End Sub

''In form level, a bit diff in .net, do some research -

Call wait(3000) ''-will stall all code for 3 seconds...

Hope this half way directs you in a direction. :)

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.