+ Reply to Thread
Results 1 to 6 of 6

Countdown Timer Pause and Resume Button

Hybrid View

table83 Countdown Timer Pause and... 02-07-2010, 01:41 AM
shg Re: Countdown Timer Pause and... 02-07-2010, 02:53 AM
table83 Re: Countdown Timer Pause and... 02-07-2010, 07:47 PM
shg Re: Countdown Timer Pause and... 02-07-2010, 08:16 PM
table83 Re: Countdown Timer Pause and... 02-07-2010, 08:27 PM
table83 Re: Countdown Timer Pause and... 02-07-2010, 08:37 PM
  1. #1
    Registered User
    Join Date
    10-20-2009
    Location
    Prineville, OR
    MS-Off Ver
    Office 2010
    Posts
    33

    Countdown Timer Pause and Resume Button

    Hey guys, I'm new so please forgive me for the simple questions that I'm coming up with. You are all helping me out so much and I apprecaite it very much.

    I am trying to create a countdown timer my class. I want to give them an amount of time to discuss a certain topic then bring them all back together as a class to discuss what they talked about.

    Anyway the start buttons work. I want to insert a button that will pause this (so the we can clarify something if needed) and then when I click start it will continue right where it left off.

    Sub CountDown()
    
    If Range("Time") <= 0 Then
    GoTo 10
    
    Else
    Range("Time") = Range("Wanted")
    
    10:
    End If
    
    20:
    Dim PauseTime, Start
    
    PauseTime = 1
    Start = Timer
    Do While Timer < Start + PauseTime
    DoEvents
    
    Loop
    
    Range("Time").Value = Range("Time").Value - 1
    
    If Range("Time").Value <= 0 Then
    
    MsgBox "STOP"
    Exit Sub
    End If
    
    GoTo 20
    End Sub
    Last edited by table83; 02-07-2010 at 02:21 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Countdown Timer Pause and Resume Button

    Maybe like this.

    Add three buttons from the Control Toolbox, and name them btnStart, btnPause, and btnResume. Then put this code in the Sheet module:

    Option Explicit
    
    Dim datNext         As Date
    
    Sub btnStart_Click()
        Range("Time").Value = #12:05:00 AM# ' initial value
        If datNext <> 0 Then Application.OnTime datNext, Me.Name & ".Tick", , False
        datNext = Now + #12:00:01 AM#
        Application.OnTime datNext, Me.Name & ".Tick"
    End Sub
    
    Sub btnPause_Click()
        If datNext <> 0 Then
            Application.OnTime datNext, Me.Name & ".Tick", , False
            datNext = 0
        End If
    End Sub
    
    Sub btnResume_Click()
        datNext = Now + #12:00:01 AM#
        Application.OnTime datNext, Me.Name & ".Tick"
    End Sub
    
    Sub Tick()
        With Range("Time")
            Select Case .Value
                Case 0
                    ' do nothing
                Case Is > #12:00:01 AM#
                    .Value = .Value - #12:00:01 AM#
                    datNext = Now + #12:00:01 AM#
                    Application.OnTime datNext, Me.Name & ".Tick"
                Case Else
                    .Value = 0
            End Select
        End With
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    10-20-2009
    Location
    Prineville, OR
    MS-Off Ver
    Office 2010
    Posts
    33

    Re: Countdown Timer Pause and Resume Button

    When I try the new code. It says "Compile Error: Invalid use of Me keyword"

    Am I missing something here?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Countdown Timer Pause and Resume Button

    Then put this code in the Sheet module:
    That's where it MUST go.

  5. #5
    Registered User
    Join Date
    10-20-2009
    Location
    Prineville, OR
    MS-Off Ver
    Office 2010
    Posts
    33

    Re: Countdown Timer Pause and Resume Button

    I know I'm doing something really simple that wrong here. Here is the excel sheet.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    10-20-2009
    Location
    Prineville, OR
    MS-Off Ver
    Office 2010
    Posts
    33

    Re: Countdown Timer Pause and Resume Button

    I know this is nothing big for a lot of you guys but I just got it counting down minutes and seconds! I'm proud of myself.

    If I pause the code it will resume right where it left off. I just need a macro that will pause the code. How do I do it? It can't be that hard.

    Sub CountDown()
    Dim datNext         As Date
    If Range("A_Secs") <= 0 Then
    
    Range("A_Secs") = Range("W_Secs")
    Range("A_Mins") = Range("W_Mins")
    Else
    End If
    
    20:
    Dim pausetime, Start
    
    pausetime = 1
    Start = Timer
    Do While Timer < Start + pausetime
    DoEvents
    
    Loop
    
    Range("A_Secs").Value = Range("A_Secs").Value - 1
    
    If Range("A_Secs").Value <= 0 Then
    
    If Range("A_Mins") > 0 Then
    
    Range("A_Mins") = Range("A_Mins") - 1
    Range("A_Secs") = Range("A_Secs") + 60
    GoTo 20:
    Else
    
    MsgBox "STOP"
    Exit Sub
    End If
    End If
    
    GoTo 20
    End Sub
    Last edited by table83; 02-07-2010 at 08:40 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1