Hi guys, okay 2 questions, please see the below code.

1.) Why in the code below, does my incrementing ScoreInt not work ? need a fresh pair of eyes.

2.) The time in my form when run only displays the time the application was initially run, but does not update... how can i get the time to update every minute correctly ?

Public Class Mathy

    Dim ScoreInt As Integer

    Dim intHour = Hour(Now)
    Dim intMinute = Minute(Now)

    Private Sub Mathy_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Score.Text = ScoreInt

        hhmm.Text = intHour & intMinute

    End Sub

    Private Sub ButtonGuessAnswer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGuessAnswer.Click
        Static NumberOfGuesses As Integer

        Dim Number1 As Double
        Dim Number2 As Double

        ScoreInt = 0

        If String.IsNullOrEmpty(TextBoxAnswer.Text) Then
            MessageBox.Show("Please enter a response.")
        ElseIf Not IsNumeric(TextBoxAnswer.Text) Then

            Number1 = CDbl(LabelRandomNumber1.Text)
            Number2 = CDbl(LabelRandomNumber2.Text)

            If CDbl(TextBoxAnswer.Text) = Number1 - Number2 Then
                LoadRandomValues()      'reset
                NumberOfGuesses = 0
                ScoreInt += 1

                ScoreInt += 1
            End If
        End If

        NumberOfGuesses += 1

        If NumberOfGuesses = 3 Then
            MessageBox.Show("You're out of guesses. The answer was " & Number1 - Number2)
            NumberOfGuesses = 0

        End If

        ScoreInt = 0

    End Sub

    Public Sub LoadRandomValues()

        Dim generator As New Random

        LabelRandomNumber1.Text = generator.Next(1, 100)
        LabelRandomNumber2.Text = generator.Next(1, 100)

    End Sub

End Class

5 Years
Discussion Span
Last Post by codeorder
Featured Replies
  • [CODE]YourCoolLabelToDisplayScoreInt.Text = ScoreInt.ToString[/CODE] ...should be added somewhere w/in your [iCODE]Private Sub ButtonGuessAnswer_Click[/iCODE] Sub, possibly the very last line of code. Read More


If you want to update a field automatically (like to display the time) you have to add a Timer control to your form and set it to run at a convenient interval. For example, if you add Timer1 to your form, you can set the interval to the number of milliseconds between events (1000 = one second). If you set it to 1000 you can update the time field once a second with the current time. Set the Enabled property of Timer1 to True to start the timer.


Question 1, check line.25.
If you want to keep score up to date and Not constantly resetting it's self to "0" before it adds a +1 to it, .Remove the line. Hope this helps.

Almost missed this. :D
Line.59, same issue. .Remove it and your score should update as needed.


Thank you so much for your help. Believe it or not that's not even the issue ! I deleted both those lines and it's still not incrementing the label on the form. Those lines you said to remove (i should have removed before posting apologies) were me trying to fix it. Any other ideas ? I just cannot see it.

YourCoolLabelToDisplayScoreInt.Text = ScoreInt.ToString

...should be added somewhere w/in your Private Sub ButtonGuessAnswer_Click Sub, possibly the very last line of code.

Edited by codeorder: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.