3 Replies - 602 Views - Last Post: 22 April 2011 - 09:30 AM Rate Topic: -----

#1 gec5741  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 09-December 09

Label only counts up to 9

Posted 21 April 2011 - 03:53 PM

am working on an app that generates 2 random numbers. When the numbers match it plays a sound. I'm trying to keep count of each time this accurs by using a label to hold the number each time it counts. It's working but when I use a label it only counts up to 9 then goes back to one and stays there. Here is a snippet of the code I wrote.

Public Class Form1
    Public int As Integer = 0

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim Randx As New Random

        TextBox1.Text = Randx.Next(1, 2)
        TextBox2.Text = Randx.Next(1, 2)

        If TextBox1.Text = TextBox2.Text Then
            Timer1.Stop()
            My.Computer.Audio.Play(My.Resources.fart, AudioPlayMode.Background)
            int = int + 1
            Label1.Text = int
            Timer1.Start()
        End If
        

        
    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Label only counts up to 9

#2 gec5741  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 09-December 09

Re: Label only counts up to 9

Posted 21 April 2011 - 04:10 PM

I tested this with a textbox and thought it worked. I have 5 timers with similar code but each one plays a different sound. Seemed to work ok with one timer running the code into a text box. But when I turned them all on seems to give me random results for the count.
Was This Post Helpful? 0
  • +
  • -

#3 gec5741  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 09-December 09

Re: Label only counts up to 9

Posted 21 April 2011 - 07:12 PM

View Postgec5741, on 21 April 2011 - 04:10 PM, said:

I tested this with a textbox and thought it worked. I have 5 timers with similar code but each one plays a different sound. Seemed to work ok with one timer running the code into a text box. But when I turned them all on seems to give me random results for the count.


Well I'm just slow I guess. And new. I figured itout. I had it right but I had to use a diff var per timer. Now all working like I planned. thanks.
Was This Post Helpful? 1
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 215
  • View blog
  • Posts: 1,408
  • Joined: 16-March 11

Re: Label only counts up to 9

Posted 22 April 2011 - 09:30 AM

View Postgec5741, on 21 April 2011 - 07:12 PM, said:

View Postgec5741, on 21 April 2011 - 04:10 PM, said:

I tested this with a textbox and thought it worked. I have 5 timers with similar code but each one plays a different sound. Seemed to work ok with one timer running the code into a text box. But when I turned them all on seems to give me random results for the count.


Well I'm just slow I guess. And new. I figured itout. I had it right but I had to use a diff var per timer. Now all working like I planned. thanks.


Was just about to comment sir, but I'm glad you figured it out anyhow. :)

By the way "+=" is a good habit to pick up on when you are incrementing. Spare ya some confusion in the future.

This post has been edited by trevster344: 22 April 2011 - 09:31 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1