Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 28th, 2006, 08:32 AM
Registered User
 
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stopwatch to Countdown

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?

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
Thanks in advance for any help.

 
Old August 18th, 2006, 09:05 AM
pjm pjm is offline
Authorized User
 
Join Date: Jul 2006
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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-





Similar Threads
Thread Thread Starter Forum Replies Last Post
Countdown timer DennyLoi Javascript How-To 2 November 27th, 2007 08:01 AM
Stopwatch frankjuel Excel VBA 2 July 27th, 2007 03:42 PM
Countdown kritimehrotra Access VBA 3 July 25th, 2006 02:55 PM
Countdown Timer loveperson Beginning VB 6 1 January 7th, 2005 05:31 PM
Countdown clock Ciarano Beginning VB 6 1 March 12th, 2004 07:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.