+ Reply to Thread
Results 1 to 4 of 4

stop my timer

Hybrid View

  1. #1
    Forum Contributor murray83's Avatar
    Join Date
    05-05-2016
    Location
    Daventry
    MS-Off Ver
    365
    Posts
    146

    stop my timer

    Ok so see the attached for my attempt to move my access quiz to excel; for the most part it works all fine

    Apart from the timer function, that is where imp in need of some of help from someone a bit smarter than me

    So here is what should happen

    open the document only see 1 tab, enter your name press start then hides main tab and shows Q1 tab which has a countdown to answer if that runs out then it will move you to Q2 tab and so on, but if you click it will stop the timer as is and then at the end it will work out how long it took you

    Then email your results off to the quiz master and then reset, which takes you to the main tab again and rests the quiz

    But each time I get to the results tab it says "Out of time" and moves me back to earlier in the dam quiz it’s driving me potty

    So please any help much appreciated

    cheers all

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: stop my timer

    Put the code below in a standard code module.

    Delete your old cmdStartQuiz and restart procedures.

    Assign cmdNextQ to each Next Question button.

    Delete or comment out all the event procedures in the Q sheets and Results sheet code modules.

    Public interval As Date
    Public bNextQ As Boolean
    
    Sub QTimer() 'For Q1-Q20
    
        Dim NextSheet As Integer
        
        Range("B1") = Range("B1") - TimeValue("00:00:01")
        
        If Range("B1").Value <= 0 Or bNextQ Then 'next Q-sheet when time out or button clicked
            
            If Not bNextQ Then MsgBox "Out of Time", , ""
            bNextQ = False
            
            If ActiveSheet.Name = "Q20" Then
                Sheets("Result").Visible = True
                Sheets("Result").Select
                Sheets("Q20").Visible = xlSheetVeryHidden
                Exit Sub
                
            ElseIf ActiveSheet.Name Like "Q*" Then
            
                NextSheet = Mid(ActiveSheet.Name, 2) + 1 'next Q sheet number
            
                Sheets("Q" & NextSheet).Visible = True
                Sheets("Q" & NextSheet).Select
                Range("B1").Value = ("00:00:20")
                
                Sheets("Q" & NextSheet - 1).Visible = xlSheetVeryHidden 'Hide previous Q sheet
                
            End If
            
        End If
        
        interval = Now + TimeValue("00:00:01")
        If ActiveSheet.Name Like "Q*" Then Application.OnTime interval, "QTimer"
    
    End Sub
    
    Sub QTimer_Stop()
        On Error Resume Next
        Application.OnTime interval, "QTimer", Schedule:=False
    End Sub
    
    Sub cmdStartQuiz()
        Sheets("Q1").Visible = xlSheetVisible
        Sheets("Q1").Select
        Range("B1").Value = ("00:00:20")
        QTimer
        Sheets("Main").Visible = False
    End Sub
    
    Sub restart()
    '
    ' restart Macro
    '
        Dim i As Integer
    
        With Sheets("Main")
            .Visible = True
            .Range("F11:K13").ClearContents
            .Select
        End With
        
        Sheets("Records").Visible = xlSheetVeryHidden
        Sheets("Result").Visible = xlSheetVeryHidden
        
        Sheets("ForEmail").Range("B5:B24").ClearContents
        Sheets("ForEmail").Visible = xlSheetVeryHidden
        
        For i = 1 To 20
            With Sheets("Q" & i)
                .Range("B5").ClearContents
                .Visible = xlSheetVeryHidden
            End With
        Next i
    
    End Sub
    
    Sub cmdNextQ()
        
        QTimer_Stop
        bNextQ = True
        QTimer
        
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor murray83's Avatar
    Join Date
    05-05-2016
    Location
    Daventry
    MS-Off Ver
    365
    Posts
    146

    Re: stop my timer

    cheers i shall try this ASAP

  4. #4
    Forum Contributor murray83's Avatar
    Join Date
    05-05-2016
    Location
    Daventry
    MS-Off Ver
    365
    Posts
    146

    Re: stop my timer

    Quote Originally Posted by AlphaFrog View Post
    Put the code below in a standard code module.

    Delete your old cmdStartQuiz and restart procedures.

    Assign cmdNextQ to each Next Question button.

    Delete or comment out all the event procedures in the Q sheets and Results sheet code modules.

    Public interval As Date
    Public bNextQ As Boolean
    
    Sub QTimer() 'For Q1-Q20
    
        Dim NextSheet As Integer
        
        Range("B1") = Range("B1") - TimeValue("00:00:01")
        
        If Range("B1").Value <= 0 Or bNextQ Then 'next Q-sheet when time out or button clicked
            
            If Not bNextQ Then MsgBox "Out of Time", , ""
            bNextQ = False
            
            If ActiveSheet.Name = "Q20" Then
                Sheets("Result").Visible = True
                Sheets("Result").Select
                Sheets("Q20").Visible = xlSheetVeryHidden
                Exit Sub
                
            ElseIf ActiveSheet.Name Like "Q*" Then
            
                NextSheet = Mid(ActiveSheet.Name, 2) + 1 'next Q sheet number
            
                Sheets("Q" & NextSheet).Visible = True
                Sheets("Q" & NextSheet).Select
                Range("B1").Value = ("00:00:20")
                
                Sheets("Q" & NextSheet - 1).Visible = xlSheetVeryHidden 'Hide previous Q sheet
                
            End If
            
        End If
        
        interval = Now + TimeValue("00:00:01")
        If ActiveSheet.Name Like "Q*" Then Application.OnTime interval, "QTimer"
    
    End Sub
    
    Sub QTimer_Stop()
        On Error Resume Next
        Application.OnTime interval, "QTimer", Schedule:=False
    End Sub
    
    Sub cmdStartQuiz()
        Sheets("Q1").Visible = xlSheetVisible
        Sheets("Q1").Select
        Range("B1").Value = ("00:00:20")
        QTimer
        Sheets("Main").Visible = False
    End Sub
    
    Sub restart()
    '
    ' restart Macro
    '
        Dim i As Integer
    
        With Sheets("Main")
            .Visible = True
            .Range("F11:K13").ClearContents
            .Select
        End With
        
        Sheets("Records").Visible = xlSheetVeryHidden
        Sheets("Result").Visible = xlSheetVeryHidden
        
        Sheets("ForEmail").Range("B5:B24").ClearContents
        Sheets("ForEmail").Visible = xlSheetVeryHidden
        
        For i = 1 To 20
            With Sheets("Q" & i)
                .Range("B5").ClearContents
                .Visible = xlSheetVeryHidden
            End With
        Next i
    
    End Sub
    
    Sub cmdNextQ()
        
        QTimer_Stop
        bNextQ = True
        QTimer
        
    End Sub
    worked like a charm

    thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Can't Stop a Timer
    By Exequiel3k in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-10-2019, 11:30 AM
  2. [SOLVED] VBA countdown timer help, need it to stop.
    By crowmagnus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-10-2017, 11:27 AM
  3. [SOLVED] How do i stop a timer
    By ANDREAAS in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-12-2016, 01:12 PM
  4. Stop timer
    By aprildu in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-23-2016, 05:36 PM
  5. Start/Stop timer
    By JonathanB2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-10-2014, 07:00 AM
  6. [SOLVED] Timer non-stop to run?
    By alee001 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-30-2013, 03:46 PM
  7. Replies: 1
    Last Post: 12-12-2012, 08:46 PM

Tags for this Thread

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