473,657 Members | 2,627 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 14436
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_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles StartButton.Cli ck
Me.Timer1.Start ()
Me.Timer1.Enabl ed = True
End Sub

Private Sub PauseButton_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles PauseButton.Cli ck
Me.Timer1.Enabl ed = False
End Sub

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
m_seconds = m_seconds + 1
Me.TextBox1.Tex t = m_seconds.ToStr ing()
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_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles StartButton.Cli ck
Me.Timer1.Start ()
Me.Timer1.Enabl ed = True
End Sub

Private Sub PauseButton_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles PauseButton.Cli ck
Me.Timer1.Enabl ed = False
End Sub

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
m_seconds = m_seconds + 1
Me.TextBox1.Tex t = m_seconds.ToStr ing()
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_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles StartButton.Cli ck
Me.Timer1.Start ()
Me.Timer1.Enabl ed = True
End Sub

Private Sub PauseButton_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles PauseButton.Cli ck
Me.Timer1.Enabl ed = False
End Sub

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
m_seconds = m_seconds + 1
Me.TextBox1.Tex t = m_seconds.ToStr ing()
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.FromSe conds(seconds)
Dim value As DateTime = DateTime.MinVal ue.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.FromSe conds(seconds)
Dim value As DateTime = DateTime.MinVal ue.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).AddSecond s(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
12333
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 minutes 5 seconds". Any ideas? Thanks very much! function calcElapsedTime($time) { // calculate elapsed time (in seconds!) $diff = time()-$time;
3
29028
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 h:minutes:seconds) as such: 0:15:34 (0 hours, 15 minutes, 34 seconds -> 934 seconds total) or as another example:
1
1871
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 ticket is not resolved (Finish) on the same day, I need to calculate how many 8a-5p Mon-Fri workday hours elapsed. HELP, please! *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
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
1330
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 trouble ticket is not resolved (Finish) on the same day, I need to calculate how many 8a- 5p Mon-Fri workday hours elapsed. HELP, please!
20
12590
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
16321
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()' function call for the purpose and regardless of how many time I invoke the function within my program, I get the same output!!! For better clarity consider the code snippet below. ... start_time = time(NULL);
5
1947
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 is a timestamp field. How can I calculate the time elapsed from one timestamp to the next?
1
1745
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), the form calculates the total elapsed time. It must take into consideration that a test could begin at 4 pm & end at 8 am the next day. This is what I've put together so far.....but it doesn't work. I get this message: syntax error 10: at line 11. ...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system
2
1611
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.