Reputation: 730
I can't figure out how to simply display to value of a timer after it's stopped in VB.
I tried stuff like MsgBox(Val(Timer2))
but it's not that simple apparently.
Upvotes: 0
Views: 11353
Reputation: 20459
Perhaps the stopwatch class would work for you:
Dim sw As New Stopwatch
sw.Start()
'do something, for example:
Threading.Thread.Sleep(1000)
sw.Stop()
MessageBox.Show(sw.ElapsedMilliseconds)
Upvotes: 3
Reputation: 2970
Timers don't do that. But you can use various date/time functions to do the same thing.
Dim startTime As DateTime
Dim elapsed As DateTime
' ...
Timer2.Start()
startTime = Now
' after race finishes, then:
elapsed = Now - startTime
This gives you a TimeSpan
object.
or
Dim startTime As Integer = Environment.TickCount
' ...
Dim elapsed As Integer = Environment.TickCount - startTime
This gives you an overall time in milliseconds.
Upvotes: 1
Reputation: 4330
I think what you want is this,
Dim StartTime = DateTime.Now()
'Do race stuff
Dim EndTime = DateTime.Now()
Dim ElapsedSeconds = EndTime.Subtract(StartTime).TotalSeconds
Upvotes: 1