Page 1 of 1

Using Timer A Simple Clock & Egg Timer Rate Topic: -----

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Posted 19 July 2008 - 10:52 AM

I wrote this tutorial to help you understand the basic of timers.
A Simple Clock
Start a new Windows Application project
Add a new Label
Name it Lbl_Clock
Set AutoSize =False
Set Text ="00:00:00"

Add A Timer
Name it Timer_Clock

Double Click on the Timer
This opens the subroutine that is called every time the interval period is reached
Write
Private Sub Timer_Clock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_Clock.Tick
 ' Update clock label Format (HH:MM:SS)
  Me.Lbl_Clock.Text = Now.ToLongTimeString
End Sub



Now to set the timer intervals, double click on Form1
'Set Timer_Clock Interval to 1 second (1 Second => 1000 ms)
Me.Timer_Clock.Interval = 1 * 1000
Me.Timer_Clock.Enabled = True


These can be set via the Timer_Clock properties windows, but this demostrates how to do it in code.

Run. Now you have a simple clock.

Stop the application, when you are ready for the next part.

A 3-Minute Egg Timer

Even though maximum value for interval in 214743674ms (~ 59 Hours)
Let assume in this example it's 100000ms (1 Minute 40 Seconds)
We want the interval to be 180000ms (3 Minutes) how do we do it?
We could count the number of minutes (60000ms) passed.

Add to Form1 a button
Name it StartEggTimerButton
Add a timer, name it EggTimer
Double click on the button and add
' Keep track on how many minutes have passed  
 Dim MinuteCount As Integer = 0

Private Sub StartEggTimerButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles  StartEggTimerButton.Click
 ' Set count of minutes to Zero
 MinuteCount = 0
 ' Set Interval to a minute
 Me.EggTimer.Interval = 60 * 1000 ' (A minute)
 ' Start the Egg Timer
 Me.EggTimer.Enabled = True
End Sub




Double click on EggTimer and add
Private Sub EggTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EggTimer.Tick
' Add another minute to the Count of minutes
 MinuteCount += 1
 ' Have I counted 3 minutes?
 If MinuteCount = 3 Then
  ' Yes
  ' Stop the timer
  Me.EggTimer.Enabled = False
  ' Display a message  
  MessageBox.Show(Me, "Egg Done")
 End If
End Sub



Run the Application
Click the button

I hope this helps you to understand timers.

Now.Eat the nice boiled egg.

Is This A Good Question/Topic? 1
  • +

Replies To: Using Timer

#2 sam.adams61  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 283
  • Joined: 14-July 08

Posted 24 July 2008 - 05:23 PM

Many thanks Adam for your many contributions...as a raw beginner (and not a young one either) I found this tutorial very helpful.
Was This Post Helpful? 0
  • +
  • -

#3 Brassconstruction  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-November 08

Posted 14 November 2008 - 11:09 PM

I am a new guy to this forum and am glad i did.This project from Adam is quite nice.Keep it up.
Was This Post Helpful? 0
  • +
  • -

#4 Guest_smason*


Reputation:

Posted 18 August 2010 - 09:41 AM

Very simple and to the point. Well done!
Was This Post Helpful? 0

#5 jasser  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 03-July 09

Posted 19 August 2011 - 10:03 PM

thanks man
it's been very helpful ^_^
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1