3 Replies - 327 Views - Last Post: 05 February 2011 - 07:39 AM Rate Topic: -----

#1 xweetok59  Icon User is offline

  • New D.I.C Head

Reputation: -16
  • View blog
  • Posts: 45
  • Joined: 23-June 10

Timer Problem

Posted 04 February 2011 - 03:58 PM

Ok, now I'm stuck at producing the goods. If you press this button, it will produce one good:

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        If Plastic >= 2 Then
            Plastic = Plastic - 2
            Timer1.Interval = 5000
            Timer1.Enabled = True
            Me.Button2.Enabled = False
            MsgBox("Bla will be done after 5 seconds. Buttons will be                      enabled again after Bla is produced!")
        Else
            MsgBox("2 pieces of plastic required!")

        End If
    End Sub



Code of timer:

If Timer1.Interval = 0 Then
            MsgBox("Good(s) are done!")
            Me.Button2.Enabled = True
            Good = Good + 1
            Form3.Label1.Text = Good
            Timer1.Enabled = False


Now, when I press the button, the button gets disabled, but nothing happens afterwards. The good doesn't get produced, I don't get a msgbox that it is done and the button doesn't get enabled again. Please help somebody...

Is This A Good Question/Topic? 0
  • +

Replies To: Timer Problem

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2233
  • View blog
  • Posts: 9,401
  • Joined: 29-May 08

Re: Timer Problem

Posted 04 February 2011 - 04:09 PM

Timer is,in my opinion badly named compared to what it does.

Timer is not a countdown timer but a metronome, do something every time it ticks.

.Interval is the length time between each tick.
Was This Post Helpful? 0
  • +
  • -

#3 xweetok59  Icon User is offline

  • New D.I.C Head

Reputation: -16
  • View blog
  • Posts: 45
  • Joined: 23-June 10

Re: Timer Problem

Posted 05 February 2011 - 01:50 AM

Then what should I use for something like this?
Was This Post Helpful? 0
  • +
  • -

#4 Guest_Jim*


Reputation:

Re: Timer Problem

Posted 05 February 2011 - 07:39 AM

Your problem is this line:

If Timer1.Interval = 0 Then


You set the interval to 5000. The interval is 5000! It isn't zero! The timer doesn't change the value of the interval, so this condition will never be true and the code inside your tick event never gets executed.

Uhmmm. . . . You do know how to set breakpoints and step through code to find errors don't you? This type of problem should be very easy to find if you use the tools available.

Jim
Was This Post Helpful? 0

Page 1 of 1