473,503 Members | 4,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculate elapsed time

Hi,

I am seeking help for calculating the elapsed time on an activity.
When the user clicks "pause" button on a form, the timer should also
pause. When the user clicks "continue", the timer should continue from
where the user paused.
For example, if the user paused after 10 seconds of progress in the
activity, it should start from the 11th second when the user clicks
"continue".
Am using .Net version 1.1, so if stopwatch performs a similar action,
it can be ruled out.
Appreciate any help on this using vb.net or directions to a
discussion/link/articles with respect to this query.
Thanks
TS

Feb 6 '06 #1
5 14428
Hi techspirit, I think there's a pretty easy way to accomplish what you're
looking for assuming I understand your situation. I created a small winapp
to show how to do this, it contains 2 buttons, a timer, and a text box. One
Button starts the timer, the other pauses it, and the start button will
resume the timer where it left off. The textbox merely displays the time.
This seems to do what you are looking for. Below I've included the code from
form1.vb:
Public Class Form1

Dim m_seconds As Integer

Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles StartButton.Click
Me.Timer1.Start()
Me.Timer1.Enabled = True
End Sub

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

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
m_seconds = m_seconds + 1
Me.TextBox1.Text = m_seconds.ToString()
End Sub
End Class

Hope this helps!
"techspirit" wrote:
Hi,

I am seeking help for calculating the elapsed time on an activity.
When the user clicks "pause" button on a form, the timer should also
pause. When the user clicks "continue", the timer should continue from
where the user paused.
For example, if the user paused after 10 seconds of progress in the
activity, it should start from the 11th second when the user clicks
"continue".
Am using .Net version 1.1, so if stopwatch performs a similar action,
it can be ruled out.
Appreciate any help on this using vb.net or directions to a
discussion/link/articles with respect to this query.
Thanks
TS

Feb 6 '06 #2
Hi Justin,
Thanks for replying. Your code extract sure works. But, my question is
can I acccomplish the same with a time based structure.I will need to
display the counter in seconds.

Thanks
TS

Justin Swan (MSFT) wrote:
Hi techspirit, I think there's a pretty easy way to accomplish what you're
looking for assuming I understand your situation. I created a small winapp
to show how to do this, it contains 2 buttons, a timer, and a text box. One
Button starts the timer, the other pauses it, and the start button will
resume the timer where it left off. The textbox merely displays the time.
This seems to do what you are looking for. Below I've included the code from
form1.vb:
Public Class Form1

Dim m_seconds As Integer

Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles StartButton.Click
Me.Timer1.Start()
Me.Timer1.Enabled = True
End Sub

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

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
m_seconds = m_seconds + 1
Me.TextBox1.Text = m_seconds.ToString()
End Sub
End Class

Hope this helps!
"techspirit" wrote:
Hi,

I am seeking help for calculating the elapsed time on an activity.
When the user clicks "pause" button on a form, the timer should also
pause. When the user clicks "continue", the timer should continue from
where the user paused.
For example, if the user paused after 10 seconds of progress in the
activity, it should start from the 11th second when the user clicks
"continue".
Am using .Net version 1.1, so if stopwatch performs a similar action,
it can be ruled out.
Appreciate any help on this using vb.net or directions to a
discussion/link/articles with respect to this query.
Thanks
TS


Feb 7 '06 #3
Hi Justin,
Thanks for replying. Your code extract sure works perfect. But, my
question is can I acccomplish the same with a time based structure.I
will need to display the counter in seconds.

Thanks
TS

Justin Swan (MSFT) wrote:
Hi techspirit, I think there's a pretty easy way to accomplish what you're
looking for assuming I understand your situation. I created a small winapp
to show how to do this, it contains 2 buttons, a timer, and a text box. One
Button starts the timer, the other pauses it, and the start button will
resume the timer where it left off. The textbox merely displays the time.
This seems to do what you are looking for. Below I've included the code from
form1.vb:
Public Class Form1

Dim m_seconds As Integer

Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles StartButton.Click
Me.Timer1.Start()
Me.Timer1.Enabled = True
End Sub

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

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
m_seconds = m_seconds + 1
Me.TextBox1.Text = m_seconds.ToString()
End Sub
End Class

Hope this helps!
"techspirit" wrote:
Hi,

I am seeking help for calculating the elapsed time on an activity.
When the user clicks "pause" button on a form, the timer should also
pause. When the user clicks "continue", the timer should continue from
where the user paused.
For example, if the user paused after 10 seconds of progress in the
activity, it should start from the 11th second when the user clicks
"continue".
Am using .Net version 1.1, so if stopwatch performs a similar action,
it can be ruled out.
Appreciate any help on this using vb.net or directions to a
discussion/link/articles with respect to this query.
Thanks
TS


Feb 7 '06 #4
Hi,

Your code was a good place to start working with the counter display.
I used this code , referring to a discussion in this group, to convert
the counter to seconds.
Dim seconds As Integer = 75
Dim elapsed As TimeSpan = TimeSpan.FromSeconds(seconds)
Dim value As DateTime = DateTime.MinValue.Add(elapsed)
Dim s As String = value.ToString("mm:ss")

Thanks, Justin.

Feb 7 '06 #5

techspirit wrote:
Hi,

Your code was a good place to start working with the counter display.
I used this code , referring to a discussion in this group, to convert
the counter to seconds.
Dim seconds As Integer = 75
Dim elapsed As TimeSpan = TimeSpan.FromSeconds(seconds)
Dim value As DateTime = DateTime.MinValue.Add(elapsed)
Dim s As String = value.ToString("mm:ss")

Thanks, Justin.

Ok, I didnt really need all those lines of code. It was much easier to
use :
((New Date).AddSeconds(ElapsedTime).ToString("HH:mm:ss") )

Feb 11 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
12318
by: NotGiven | last post by:
Below is a good elapsed time function I found. However, I'd like to return total seconds instead of broken down into days, hours, minutes & seconds. In other words, I want "125" instead of "2...
3
29015
by: fred14214 | last post by:
I need to be able to enter an elapsed time into a text field. This time then needs to be converted into seconds and stored in a field in some table. The user will enter a time (format is...
1
1868
by: Clay | last post by:
I really need to compute elapsed time using Access and VBA. I have two date/time Access table fields, one for Start and one for Finish. I am trying to calculate net workday work hours. If a trouble...
4
1868
by: JSmith | last post by:
I want to determine the elapsed time between two events. What is the best way to do this?
1
1325
by: Clay Watson | last post by:
I really need to compute elapsed time using Access and VBA. I have two date/time Access table fields, one for Start and one for Finish. I am trying to calculate net workday work hours. If a...
20
12570
by: Jean Johnson | last post by:
Hello - I have a start and end time that is written using the following: time.strftime("%b %d %Y %H:%M:%S") How do I calculate the elapsed time? JJ
12
16271
by: Spitfire | last post by:
I've a requirement to find the elapsed time between two function calls. I need to find the time elapsed accurate to 1 millisecond. The problem I'm facing right now is that, I'm using the 'time()'...
5
1930
by: mmi48 | last post by:
Most of the discussions I've seen about elapsed time have, thus far, involved at least two date/time fields. I am trying to calculate time elapsed from one field across multiple records. The field...
1
1737
by: bklernr | last post by:
Hello, I'm working on a form in Acrobat Pro 9 (not LiveCycle). I need to have an operator enter a beginning time (firsttime) & an end time (secondtime) & when s/he pushes a button (btncalcmix.0),...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.