If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > double timer issue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-14-05, 11:35
Alexxx12 Alexxx12 is offline
Registered User
 
Join Date: Sep 2002
Location: NJ
Posts: 139
double timer issue

hi,

excel 2k
win 2k + xp

I have two timers sometimes running at the same time but one of them never resets the time in the cell I2 of my spreadsheet the way the other does. I want the time when started to show 0:00:00. Can anyone help?
Here is the code for both:

Code:
Option Explicit
Public RunWhen, RunWhen2 As Double
Public TimeStop, TimeStop2 As Double
Public Const cRunIntervalSeconds = 1    ' 1 second
Public Const cRunIntervalSeconds2 = 1    ' 1 second
Public Const cRunWhat = "The_Sub"
Public Const cRunWhat2 = "The_Sub2"
Public Const NAME = "MyDelayMacro"
Public Const NAME2 = "MyDelayMacro2"




Sub StartTimer()
On Error Resume Next
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, SCHEDULE:=True
End Sub


Sub The_Sub()
  On Error Resume Next
  Range("J2") = Format(Now - Range("H2"), "hh:mm:ss")
  Range("J2").Font.Size = 20
  Range("J2").Font.Bold = True
  StartTimer

End Sub


Sub StopTimer()
   On Error Resume Next
   Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, SCHEDULE:=False
   Application.OnTime earliesttime:=Now, procedure:=NAME, SCHEDULE:=False
     
End Sub

Sub StartTimer2()
On Error Resume Next
RunWhen2 = Now + TimeSerial(0, 0, cRunIntervalSeconds2)
Application.OnTime earliesttime:=RunWhen2, procedure:=cRunWhat2, SCHEDULE:=True
End Sub


Sub The_Sub2()
  On Error Resume Next
  Range("I2") = Format(Now - Range("G2"), "hh:mm:ss")
  Range("I2").Font.Size = 20
  Range("I2").Interior.Color = vbRed
  Range("I2").Font.Color = vbYellow
  Range("I2").Font.Bold = True
  Call StartTimer2

End Sub


Sub StopTimer2()
   On Error Resume Next
   Application.OnTime earliesttime:=RunWhen2, procedure:=cRunWhat2, SCHEDULE:=False
   Application.OnTime earliesttime:=Now, procedure:=NAME2, SCHEDULE:=False
     
End Sub
Reply With Quote
  #2 (permalink)  
Old 02-14-05, 12:01
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
I cant see a problem here i ran this code to start your timer,

Code:
Sub startstuff()
    Range("G2") = Now
    Range("H2") = Now
    Call StartTimer
    Call StartTimer2
End Sub
and they both start at 1 second or call The_sub routines to start at 0
(the second timer starts a moment after the first but after 1 second they are identical)
as it takes a second to call the sub or am i missing something here
Reply With Quote
  #3 (permalink)  
Old 02-14-05, 15:11
Alexxx12 Alexxx12 is offline
Registered User
 
Join Date: Sep 2002
Location: NJ
Posts: 139
Double Timers

time 1 displays the time correctly 0:01:05
but timer2 displays 19:52:02 and eveytime I run the Stoptimer2 and start it again it adds on the time of 19:52:02....as if Timer2 was never stopped....

Last edited by Alexxx12; 02-14-05 at 15:14.
Reply With Quote
  #4 (permalink)  
Old 02-15-05, 03:57
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
whats in range G2 that should be the only difference between the 2 timers
as it may just be picking up the current system time
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On