Stopwatch to Countdown

cervantes008

Registered User.
Local time
Today, 01:55
Joined
Jul 21, 2006
Messages
14
Is there a way to have this stopwatch to countdown from 10 minutes to 00:00:00:00?

Code:
Option Compare Database
Option Explicit

 Dim TotalElapsedMilliSec As Long
       Dim StartTickCount As Long

       Private Declare Function GetTickCount Lib "kernel32" () As Long


Private Sub Form_Timer()

   Dim Hours As String
   Dim Minutes As String
   Dim Seconds As String
   Dim MilliSec As String
   Dim Msg As String
   Dim ElapsedMilliSec As Long

   ElapsedMilliSec = (GetTickCount() - StartTickCount) + _
      TotalElapsedMilliSec

   Hours = Format((ElapsedMilliSec \ 3600000), "00")
   Minutes = Format((ElapsedMilliSec \ 60000) Mod 60, "00")
   Seconds = Format((ElapsedMilliSec \ 1000) Mod 60, "00")
   MilliSec = Format((ElapsedMilliSec Mod 1000) \ 10, "00")

   Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" _
      & MilliSec

End Sub
       
       
       
       Private Sub btnStartStop_Click()

   If Me.TimerInterval = 0 Then
      StartTickCount = GetTickCount()
      Me.TimerInterval = 15
      Me!btnStartStop.Caption = "Stop"
      Me!btnReset.Enabled = False
   Else
      TotalElapsedMilliSec = TotalElapsedMilliSec + _
         (GetTickCount() - StartTickCount)
      Me.TimerInterval = 0
      Me!btnStartStop.Caption = "Start"
      Me!btnReset.Enabled = True
   End If

End Sub
            
            
Private Sub btnReset_Click()
   TotalElapsedMilliSec = 0
   Me!ElapsedTime = "00:00:00:00"
End Sub
 
The form timer routine is the right place to start. However, you might be asking for a bit much in terms of event speed. Doing a countdown by seconds is no sweat. By tenths, doable. By hundredths,... not sure. By milliseconds, probably a stretch.

Why? Event infrastructure and Windows context-switching overhead. These aren't "free" (with respect to CPU cycles).

Conceptually, you can do a countdown. But within Access, don't forget you are carrying baggage.
 

Users who are viewing this thread

Back
Top Bottom