Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > VB.NET > VB.NET General Discussion

VB.NET General Discussion VB.NET general discussion area

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-01-2008, 1:41 PM
VB.NET Forum Newbie
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: Oct 2008
Age: 20
Posts: 4
Reputation: 0
M_1_s_t_1_c is on a distinguished programming path ahead
Default How to reset the counter in my code?

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:
Code:
'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 JuggaloBrotha; 12-01-2008 at 2:16 PM. Reason: Code Tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-01-2008, 8:49 PM
jmcilhinney's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2004
Location: Sydney, Australia
Age: 40
Posts: 6,131
Reputation: 542
jmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalist
Default

If you want the number of correct answers to be set to zero then wouldn't you just set it to zero?
Code:
myNumber = 0
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 12:10 AM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.