Syllabus

Home

Class Resources

News

CS-100 In-Class Project: Digital Clock

Download the form (Zip File)

Properties of the Timer Control

You should know the Name, Enabled and Inerval properties for the timer control.

Name: use prefix tmr
Enabled: If set to True the timer will tick. If set to False the timer does nothing.
Interval: The interval between "tick" of the timer in milliseconds. 1000 = 1 second

Code

'
' This program simulates a digital clock
' A timer control is used to modify the text property
' of a label setting it to the current time of day.
'
' The bult in function "TimeOfDay" is used to get the current time.
'

Public Class frmClock

' This event procdure causes the time to displayed whenever the
' button btnGo is clicked.

Private Sub btnGo_Click( Material Deleted ) Handles btnGo.Click

lblClock.Text = TimeOfDay

End Sub

' This event procdure starts the timer and thus, the clock ticking.
Private Sub btnStart_Click( Material Deleted ) Handles btnStart.Click

tmrClock.Enabled = True

End Sub

' This event procdure stops the timer.
Private Sub btnStop_Click( Material Deleted ) Handles btnStop.Click

tmrClock.Enabled = False

End Sub

' This is the event procedure for the timer control. Each second this
' procedure executes and resets the text property of the label to
' the current time of day.

Private Sub tmrClock_Tick( Material Deleted ) Handles tmrClock.Tick

lblClock.Text = TimeOfDay

End Sub

Private Sub btnQuit_Click( Material Deleted ) Handles btnQuit.Click
End
End Sub