Question Stopwatch Class NET Framework 3.5

sisquo76

Active member
Joined
Dec 1, 2008
Messages
28
Location
Bosnia and Herzegovina
Programming Experience
3-5
I have question regarding Stopwatch Class. Is there an easy way to display more than 59 minutes on stopwatch? Here is my code:

VB.NET:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim strMinutes As String
        Dim strSeconds As String

        strMinutes = stopWatch.Elapsed.Minutes.ToString("##0")
        strSeconds = stopWatch.Elapsed.Seconds.ToString("00")

        Me.Label1.Text = strMinutes & "'" & strSeconds & "''"
    End Sub

This way minutes go till 59, and then it is 0 again.

Thanks,

Sisquo76
 
No, from there on it adds hours etc. Why not Me.Label1.Text = stopWatch.Elapsed.ToString() ? Or if you persist to display only minutes you have to add hours multiplied.
 
No, from there on it adds hours etc. Why not Me.Label1.Text = stopWatch.Elapsed.ToString() ? Or if you persist to display only minutes you have to add hours multiplied.

Ok, I did it like this at the end:

VB.NET:
Dim iMinute As Integer = Int(stopWatch.Elapsed.TotalMinutes)
Me.Label1.Text = iMinute.ToString

Thanks anyway.
 
I only recalled TimeSpan had totals for milliseconds, seconds and minutes somehow... :confused:
 
I only recalled TimeSpan had totals for milliseconds, seconds and minutes somehow... :confused:

Yes, well I didn't know either, because i jumped from VB6 to VB2008 :p. But after reading documentation i figured it, and believe me it works. BTW I'm working on stopwatch for soccer game for statistics and I'm almost done.

Regards,

Sisquo76
 

Latest posts

Back
Top