all groups > dotnet general > march 2006 >
You're in the

dotnet general

group:

creating a timer in vb.net


creating a timer in vb.net av
3/31/2006 3:35:01 PM
dotnet general:
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

Re: creating a timer in vb.net Andrej Tozon
4/1/2006 12:00:00 AM
In .NET 2.0, there's a Stopwatch class, which would be the simplest tool for
solving your task. For an example on how to use it, please refer to MSDN
documentation:
http://msdn2.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx.

Andrej

[quoted text, click to view]

Re: creating a timer in vb.net Heike Kersten
4/3/2006 2:25:08 PM
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

"av" <av@discussions.microsoft.com> schrieb im Newsbeitrag
news:C988F0B1-328A-454B-AD8A-4D43115BE2D8@microsoft.com...
[quoted text, click to view]

AddThis Social Bookmark Button