Subject: Stopwatch to Countdown
Posted By: cervantes008 Post Date: 7/28/2006 8:32:15 AM
Hello All.

I have been driving myself nuts the past few weeks on finding a countdown timer to make a Mock Auction training app for my company.  My goal is to have a 10 minute timer countdown and adding 2 minutes (if neccessary) as an extension.

The only timer I found was a microsoft stopwatch.  Is there anyway to reverse this code to start at 10 minutes and work it's way down to 00:00:00:00?


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


Thanks in advance for any help.

Reply By: pjm Reply Date: 8/18/2006 9:05:45 AM
I think that you can just change the expression:

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

to:

     ElapsedMilliSec = (10*60*1000) - ((GetTickCount() - StartTickCount) + _
           TotalElapsedMilliSec)

and then in btnReset_Click:

    Me!ElapsedTime = "10:00:00:00"

I hope I'm not just oversimplifying.


-Phil-

Go to topic 48503

Return to index page 200
Return to index page 199
Return to index page 198
Return to index page 197
Return to index page 196
Return to index page 195
Return to index page 194
Return to index page 193
Return to index page 192
Return to index page 191