|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Thanks Doug
|
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
Quote:
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 |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Stopwatch Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|