• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

VB Timer

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.
LC
0
lcutliffe
Asked:
lcutliffe
1 Solution
 
hongjunCommented:
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


hongjun
0
 
jpaulinoCommented:
And don't forget to set the Interval = 1000 (1000 = 1 second)
0
 
lcutliffeAuthor Commented:
Thank you sir, you freed me from my sticking point.

LC
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now