Thread: Stopwatch query
View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
atlashill atlashill is offline
external usenet poster
 
Posts: 11
Default Stopwatch query

The code you supplied failed to stop counting when hitting zero, giving
me way too many prompt boxes to clear out.

Below are the stopwatch modules I've found online and augmented to fit.
As I said earlier, this below is capable of starting, stopping, and
restarting where it left off. I'd like to find a way to adapt your
code to fit this.

==========

First Module:

Declare Function timeGetTime Lib "winmm.dll" () As Long
Dim stopit As Boolean
Dim XCClock As Boolean
Dim StartTime

Sub RunTimer()
stopit = False
clock
End Sub

Sub clock()
If stopit = True Then Exit Sub
ActiveWorkbook.Worksheets(1).Range("C7").Value = _
Format(Now, "hh:mm:ss")
Application.OnTime (Now + TimeSerial(0, 0, 1)), "clock"
End Sub

Sub PauseTime()
stopit = True
End Sub

Sub StopClock()
XCClock = False
End Sub

Sub RestartClock()
XCClock = True
StartTime = TimeValue(Now())
ControlClock
End Sub

Sub ControlClock()
If XCClock = True Then
Range("C5").Value = Now - StartTime
Application.OnTime Now + TimeValue("00:00:01"), "ControlClock"
End If
End Sub

Second Module:

Dim AlarmTime As Date, AlarmTime2 As Date

Sub CountDown60()
ActiveSheet.Range("K1").Value = "60"
ActiveSheet.Range("K2").Value = "Counting"
Call TrapTime60
Call TrapTime
End Sub

Sub CountDown30()
ActiveSheet.Range("K1").Value = "30"
ActiveSheet.Range("K2").Value = "Counting"
Call TrapTime30
Call TrapTime
End Sub

Sub CountDownAgain()
ActiveSheet.Range("K1").Value = Range("K1").Value
ActiveSheet.Range("K2").Value = "Counting"
Call TrapTime
Call TrapTimeRestart
End Sub

Private Sub ShowTimeLeft()
ActiveSheet.Range("K1").Value = Second(AlarmTime - Now)
Call TrapTime
End Sub

Private Sub TrapTime60()
AlarmTime = CDate(Date) + TimeValue(Now()) + TimeValue("00:01:00")
Application.OnTime earliesttime:=AlarmTime, procedu="StopTimer"
End Sub

Private Sub TrapTime30()
AlarmTime = CDate(Date) + TimeValue(Now()) + TimeValue("00:00:30")
Application.OnTime earliesttime:=AlarmTime, procedu="StopTimer"
End Sub

Private Sub TrapTimeRestart()
AlarmTime = CDate(Date) + TimeValue(Now()) + Range("K3").Value
Application.OnTime earliesttime:=AlarmTime, procedu="StopTimer"
End Sub

Private Sub TrapTime()
AlarmTime2 = CDate(Date) + TimeValue(Now()) + TimeValue("00:00:01")
Application.OnTime earliesttime:=AlarmTime2, procedu="ShowTimeLeft"
End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=AlarmTime2, procedu="showtimeleft",
schedule:=False
On Error GoTo 0
ActiveSheet.Range("K2").Value = "Done"
End Sub