Timer

Submitted by: 

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.

  1.  
  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
  2.  
  3. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  4.  
  5. lblhr.Text = TimeOfDay.Hour
  6. lblmin.Text = TimeOfDay.Minute
  7. lblsec.Text = TimeOfDay.Second
  8.  
  9. End Sub
  10.  
  11. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12. Timer1.Start()
  13.  
  14. End Sub
  15. End Class

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.