Countdown Timer Using Multiple TextBoxes (1 Viewer)

wmcnaughton

New member
Local time
Yesterday, 16:20
Joined
Apr 12, 2020
Messages
3
I have a pretty involved project with multiple macros and I am stuck on one portion. I have, as part of one of my userforms, four text boxes side by side... TextHours, TextMinutes, TextSeconds and TextFraction (milliseconds). I use this for both a stopwatch (counting up) and a countdown timer (counting down to 0). My stopwatch works perfectly with Start, Stop and Reset buttons using the timer method. I have a command button that toggles between stopwatch and timer and then a pop-up box for user input to set the countdown timer starting time.

My issue is I am having a heck of a time getting a countdown timer that works with these same boxes. I already have a way that populates the boxes with the start times... for instance if I want a 30 second countdown, I can get the TextSeconds box to populate with "30", and if I want a 30 minute countdown, I can get the TextMinutes box to populate with "30" and the TextSeconds box to populate with "00" and so on. I can't seem to come up with a formula to count down to 0 using all four of these boxes. I have searched and searched, and tried 5-6 different macro ideas and I am at a loss. Any help would be greatly appreciated!

Thanks,

-Bill
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:20
Joined
Oct 29, 2018
Messages
21,453
Hi Bill. Welcome to AWF! One idea is to use one textbox for counting down. Maybe that will be easier. This textbox can be hidden, and you can parse the current countdown time into those four other textboxes, if that's how you want to display them.
 

wmcnaughton

New member
Local time
Yesterday, 16:20
Joined
Apr 12, 2020
Messages
3
Hi theDBguy,

Thanks for the welcome!

That would be fine... I could either use one textbox or even a cell on the worksheet, either way. I am just not sure of the correct syntax for the countdown and parse. I have included my code for the stopwatch section that works perfectly so you can see what I did there.

Code:
Dim StartTime, FinishTime, TotalTime, PauseTime

StopIt = False
ResetIt = False

If TextHours.value = 0 And TextMinutes.value = 0 And TextSeconds.value = 0 And TextFraction = 0 Then
    StartTime = Timer
    PauseTime = 0
    LastTime = 0
Else
    StartTime = 0
    PauseTime = Timer
End If

StartIt:
    DoEvents

    If StopIt = True Then
        LastTime = TotalTime
        Exit Sub
    Else
        FinishTime = Timer

    TotalTime = FinishTime - StartTime + LastTime - PauseTime
    TTime = TotalTime * 1000
    HM = TTime Mod 1000
    TTime = TTime \ 1000
    hh = TTime \ 3600
    TTime = TTime Mod 3600
    MM = TTime \ 60
    SS = TTime Mod 60
    TextHours.Text = Format(hh, "0")
    TextMinutes.Text = Format(MM, "00")
    TextSeconds.Text = Format(SS, "00")
    TextFraction.Text = Format(HM, "000")

    If ResetIt = True Then
        TextHours.Text = Format(0, "0")
        TextMinutes.Text = Format(0, "00")
        TextSeconds.Text = Format(0, "00")
        TextFraction.Text = Format(0, "000")
        LastTime = 0
        PauseTime = 0
        End
    End If

GoTo StartIt

I appreciate your help!
 
Last edited:

wmcnaughton

New member
Local time
Yesterday, 16:20
Joined
Apr 12, 2020
Messages
3
Just checking back to see if anyone can help with this... I am pretty stuck! Thanks so much in advance.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:20
Joined
Oct 29, 2018
Messages
21,453
Just checking back to see if anyone can help with this... I am pretty stuck! Thanks so much in advance.
Hi. Not sure if it will help, but maybe take a look at this other thread.

 

Users who are viewing this thread

Top Bottom