Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2002
    Location
    NJ
    Posts
    139

    Unanswered: 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

  2. #2
    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

  3. #3
    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 16:14.

  4. #4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •