Hooper

Hi,

I have a long running operation and I would like to show the time that it is taking in minutes.seconds

format. I have a timer that I set the interval to 1000 and then update the displayed text.

I have been looking at TimeSpan and DateTime but nothing seems to fit into a, get the start time, and display a running time.

Any help or examples would be appreciated.

Thanks

Jeff



Re: Visual Basic Language Elapsed Time

ArranNyc

You could try something like this:

In your load event handler, store the current time in a class level date type. e.g.

Code Snippet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

dateStart = Date.Now()

End Sub

In your timer event handler, you could then subtract the initial start date from the current date and display the result in a label :

e.g.

Code Snippet

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Dim elapsedTime As TimeSpan = Date.Now.Subtract(dateStart)

lblElapsed.Text = elapsedTime.Hours.ToString("00") & ":" _

& elapsedTime.Minutes.ToString("00") & ": " & _

elapsedTime.Seconds.ToString("00")

End Sub





Re: Visual Basic Language Elapsed Time

Hooper

Hi ArranNyc,

That looks pretty decent, I will try that out.

Thanks

Jeff





Re: Visual Basic Language Elapsed Time

spotty

You may want to check out the stopwatch class

System.Diagnostic.Stopwatch

http://msdn2.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

It is designed like a stopwatch to help with getting elapsed times.