Question How to reset the counter in my code?

M_1_s_t_1_c

New member
Joined
Oct 8, 2008
Messages
4
Programming Experience
1-3
I developed a code that would generate random math problems for 1st and 2nd graders...I have it where it keeps track of how many correct and incorrect answers are given. The problem is when I clear the correct and incorrect answers and switch to 2nd grade problems, it leaves off at the last count of correct and incorrect answers (Basically it doesn't reset the counter). Here is the code for the counter:
VB.NET:
'Verifies if the answer is correct
        'Keeps track of the total right and wrong answers
        Dim intNum1 As Integer
        Dim intNum2 As Integer
        Dim intUserAnswer As Integer
        Dim intCorrectAnswer As Integer

        Try
            'Assign numbers and answers to variables
            intNum1 = Convert.ToInt32(Me.lblNum1.Text)
            intNum2 = Convert.ToInt32(Me.lblNum2.Text)
            intUserAnswer = Convert.ToInt32(Me.txtAnswer.Text)

            'Calculate correct answer
            Select Case True
                Case Me.radAddition.Checked
                    intCorrectAnswer = intNum1 + intNum2
                Case Else
                    intCorrectAnswer = intNum1 + intNum2
                    Select Case True
                        Case Me.radSubtraction.Checked
                            intCorrectAnswer = intNum1 - intNum2
                        Case Else
                            intCorrectAnswer = intNum1 - intNum2
                    End Select
            End Select


            'Whether the answer is correct/incorrect
            If intUserAnswer = intCorrectAnswer Then
                mintNumCorrect = mintNumCorrect + 1
                Me.txtAnswer.Text = ""
                Call GenerateAndDisplayNumbers()
            Else
                mintNumIncorrect = mintNumIncorrect + 1
                MessageBox.Show("Give it another try", "Math Practice", _
                    MessageBoxButtons.OK, MessageBoxIcon.Information)
                Me.txtAnswer.SelectAll()
            End If
            Me.txtAnswer.Focus()
            Me.lblCorrect.Text = Convert.ToString(mintNumCorrect)
            Me.lblIncorrect.Text = Convert.ToString(mintNumIncorrect)

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Math Practice", _
                MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub
 
Last edited by a moderator:
Back
Top