• We just launched and are currently in beta. Join us as we build and grow the community.

Timer

Fun

Punchline Pro
F Rep
0
0
0
Rep
0
F Vouches
0
0
0
Vouches
0
Posts
99
Likes
97
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
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:

timer.png


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. lblhr.

    Text

    =

    TimeOfDay.

    Hour
  2. lblmin.

    Text

    =

    TimeOfDay.

    Minute
  3. 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. Private

    Sub

    Timer1_Tick(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    Timer1.

    Tick

  3. lblhr.

    Text

    =

    TimeOfDay.

    Hour
  4. lblmin.

    Text

    =

    TimeOfDay.

    Minute
  5. lblsec.

    Text

    =

    TimeOfDay.

    Second

  6. End

    Sub

  7. Private

    Sub

    Form1_Load(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    MyBase

    .

    Load
  8. Timer1.

    Start

    (

    )

  9. End

    Sub
  10. End

    Class

Book traversal links for Timer

  • ‹ TextBox Control
  • Up
  • Try Catch ›

 

452,292

323,341

323,350

Top