VB Timer

Posted on 2007-08-01
Last Modified: 2013-11-26
This should be pretty simple but for some reason Im not graspin how to utilize the timer code  in VB 2005. I'm workin on practice excersises as I'm learning how to write this stuff and one of the projects I am working on is just making a simple window with a box showing the date and time. I have been instructed to insert a timer to update the clock every second but I'm not sure of the code to make the timer do exactly that. It is in the form but I need to get some help on what to write and where to put it to make the time update. *Note* - On the form I already have the timer enabled with an interval of 1000.

This is what I got so far.

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Time1 As Date
        Time1 = Now
        lbl2.Text = Time1
        lbl2.Text = Format(Time1, "h:mm:ss")

    End Sub

End Class

Its pretty simple but for some reason i cant find the answer i'm lookin for.
Question by:lcutliffe
    LVL 33

    Accepted Solution

    try this

    Remember to set the Timer's Enabled property to True as well. It is by default set to False.

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            lbl2.Text = Format(Now, "h:mm:ss")
        End Sub

        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            lbl2.Text = Format(Now, "h:mm:ss")
        End Sub

    LVL 48

    Expert Comment

    And don't forget to set the Interval = 1000 (1000 = 1 second)
    LVL 1

    Author Comment

    Thank you sir, you freed me from my sticking point.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now