Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 29th, 2005, 09:50 AM
Journeyman Journeyman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 20 Journeyman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 18 sec
Reputation Power: 0
Stopwatch Help

Good day all,
I’m writing a stopwatch program. As per code below.

Private Sub cmdStartTimer_Click()
tmrTime.Enabled = True
End Sub

Private Sub cmdStpTimer_Click()
tmrTime.Enabled = False
End Sub

Private Sub Form_Load()
tmrTime.Enabled = False
lblTime.Caption = Format(Time, "0:00:00")
End Sub

Private Sub tmrTime_Timer()
If lblTime.Caption <> Format(Now, "h:mm:ss") Then
lblTime.Caption = Format(Now, "h:mm:ss")
End If
End Sub

My problem is, when I press the start button the stopwatch starts with the current system time. How do I get the counter to count up from 0:00:00

Reply With Quote
  #2  
Old January 29th, 2005, 04:29 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 19 m 36 sec
Reputation Power: 181
Don't use Now(), create some other date variable and preset it to 0:00
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #3  
Old January 29th, 2005, 08:27 PM
Journeyman Journeyman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 20 Journeyman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 18 sec
Reputation Power: 0
Thanks Doug

Reply With Quote
  #4  
Old January 29th, 2005, 09:16 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 19 m 36 sec
Reputation Power: 181
You can also just let your timer events figure the time, the timer is quite accurate.

For example, if your interval was for 1 second, you could just increment a seconds counter on a timer event.

Reply With Quote
  #5  
Old January 30th, 2005, 01:12 AM
Journeyman Journeyman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 20 Journeyman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by Doug G
You can also just let your timer events figure the time, the timer is quite accurate.

For example, if your interval was for 1 second, you could just increment a seconds counter on a timer event.



Here is what I did and it works great, sometimes when it's simple it's hard.

I added two labels to capture the start time and stop time, they weren't there in the previous code but does not affect the stop watch function.
Code:
 Dim MyTime, StTime, CurTime As Date
 Option Explicit
 
 Private Sub cmdStartTimer_Click()
     tmrTime.Enabled = True
     Label1.Caption = Time
     StTime = Now
 End Sub
 
 Private Sub cmdStpTimer_Click()
     tmrTime.Enabled = False
     Label2.Caption = Time
 End Sub
 
 Private Sub Form_Load()
     tmrTime.Enabled = False
     lblTime.Caption = Format(Time, "0:00:00") 'Note Now does not like "0:0:0"
 End Sub
 
 Private Sub tmrTime_Timer()
     CurTime = Now
     MyTime = CurTime - StTime
    If lblTime.Caption <> Format(MyTime, "h:mm:ss") Then
       lblTime.Caption = Format(MyTime, "h:mm:ss")
    End If
 End Sub
 

Last edited by Shadow Wizard : January 30th, 2005 at 05:21 AM. Reason: added code tags

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Stopwatch Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT