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 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
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
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
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.
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") ) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
by: JSmith |
last post by:
I want to determine the elapsed time between two events. What is the best
way to do this?
|
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...
| |
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
|
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()'...
|
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...
|
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),...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |