This tutorial will be focusing on the use of timer control in visual basic. Timers plays very important role in most application both client and server-based components. And this control is associated with “Tick” method that allows to be used when an event has to happen when certain amount has passed. At this time, we’re going to create an application using the timer. To do this, open Visual Basic and save it as “timers”. Then add five labels and a Timer. And arrange all the labels that look like as shown below: Now double click the timer and add the following code: The code below uses TimeOfDay property that returns a value containing current time of the day according to the local machine.
  2. lblhr.Text = TimeOfDay.Hour
  3. lblmin.Text = TimeOfDay.Minute
  4. lblsec.Text = TimeOfDay.Second
and we need to activate the when the form loads. And add the following code:
  1. Timer1.Start()
After this you can now press “F5” to run your porgram: And here’s all the code use in this application:
  1. Public Class Form1
  3. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  5. lblhr.Text = TimeOfDay.Hour
  6. lblmin.Text = TimeOfDay.Minute
  7. lblsec.Text = TimeOfDay.Second
  9. End Sub
  11. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12. Timer1.Start()
  14. End Sub
  15. End Class

Add new comment