creating a timer in vb.net

G

Guest

im having a hard time creating a timer in vb.net..
the program should run this way: the timer should only start when you press
a button then stops when presing it again..
my problem is that, how to make an output that will sum up all of the time
spent..
could you please provide me a sample code?
your reply will be greatly appreciated

thanks
 
H

Heike Kersten

hello,

do you look for something like that (?):

Public Class Form1
Dim DiffZeit As Date
Dim TSpan As TimeSpan

Private Sub BtnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnStart.Click
Timer1.Enabled = True
DiffZeit = DateTime.Now
End Sub

Private Sub BtnStop_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnStop.Click
Timer1.Enabled = False
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
TSpan = DateTime.Now.Subtract(DiffZeit)
Label1.Text = TSpan.Days & ":" & TSpan.Hours & ":" & TSpan.Minutes &
":" & TSpan.Seconds
End Sub
End Class


greetings,

heike kersten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top