[Solved] Simple CountDown Timer

Important Notice


Please note that on 14th December 2023 users will experience an expected outage whilst we make upgrades to our network. We anticipate this process may take a couple of hours and so we apologise in advance for any inconvenience.

  • Good morning everyone,


    As you can see from the subject, I am playing around with creating a simple countdown timer in excel. The user inputs the hours, minutes, and seconds on the worksheet and then clicks the start button. This action calls up a userform that has the timer as well as two buttons - pause and stop. I have yet been able to figure out how to code within the timer loop to check for either of these two buttons getting clicked.


    The stop button is self-explanatory. When the user clicks on the pause button, I want it to call up a message box that states "Timer Paused", which, of course, will suspend the timer loop until the user clicks the OK button on the message box. Also, I have found that the timer freezes is the mouse is clicked or any key on the keyboard is pressed, so is there any way to code in so that the only way the timer can be disrupted is pressing either the pause or stop button? Right now the timer part works perfectly except for the fact that it enters into an endless loop until the hours counter reaches zero or the user presses CTRL-Break.


    Thanks to any and all who are able to assist in this. I have posted a copy of the file for your convenience.

  • Hi DG,


    I think the problem lies in the fact that you are using 'Wait'. If you look in the VBE Help files there is a caveat as follows "Important The Wait method suspends all Microsoft Excel activity and may prevent you from performing other operations on your computer while Wait is in effect. However, background processes such as printing and recalculation continue."


    Normally, when people look to make use of a counter like this they use OnTime instead. Have a look here at Chip_Pearson's section on OnTime >>> http://www.cpearson.com/excel/ontime.htm . For a good example of its use have a look at Aaron's active_Clock workbook here >>> http://www.xl-logic.com/pages/vba.html



    HTH

  • Good morning Richie,


    Thanks for your reply. I looked briefly at both links you provided, but being that I still have some work to wrap up before the end of my shift, I will have to wait til I get home to look at these more in depth.


    Will let you know how I make out. :)

  • Good morning,


    Well, I had a chance to look at both examples more in depth, but unfortunately, I am no further ahead. Aaron's active clock file looks good, but in looking at his code, I was not able to figure out how to reverse it so that it would act as a countdown timer instead of a clock.


    Another way that I would like to be able to use this is as an elapsed time counter so that when you start the timer, it starts at zero and counts up from there. The elapsed time counter is something that I would like for inclusion in a large-scale accounting, invoicing, and billings project I am working on.


    Anyways, if anyone out there is able to offer some insight into this, I would be truly grateful.

  • I looked at using a counter for timewriting but decided that it relied too much on the operator remembering to start it and switch it off at the end and/or breaks. The only thing I could come up with was to stamp the time when a workbook was opened and then when it closed stamp that time and calculate the time that the workbook was open and log that result.

  • Yes, I suppose that could be a problem... unless everything necessary for the completion of projects and the resulting accounting of such were all contained within the same file, each user having his/her own login and such. When a user logs in, the timer begins; then, when the user logs out, either for a break or when they are done for the day, the timer stops and the timer value is recorded for that user and then the timer is reset back to zero.


    Of course, the method that you use gives me yet another option that I can look at. Eventually, I know that I will have to find another forum for the completion of this project as, upon the successful completion of it using Excel, I am planning on trying to port it out to be compiled using a combination of both VB and VF(Visual FoxPro). But that is, at best, a long way down the road for me... hehehe. :biggrin:

  • Good morning Richie,


    Thank you so much. That is exactly what I was looking for. And it was easily modified to act as an elapsed time counter instead. There are some other things that I want to try with this, but I am going to do my best to figure those out on my own. My thanks again for your help.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!