+ Reply to Thread
Results 1 to 4 of 4

Answer a question within timeline

Hybrid View

  1. #1
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Answer a question within timeline

    I am stuck at a project and need help.

    1. I have a timer in cell B2 that works fine. However, it does not start from paused time. Rest all buttons work (Start, Stop, Reset, Pause) except Resume.

    2. I need a 10 seconds countdown in B4 while the main timer is running. This countdown should start after clicking on Q1 and restart after solving Q1 and then clicking on Q2 button, if the user does not answer in 10 seconds, it should run the last part (commented) of chkAnswer(). I need a code in the commented area. (Also only if possible - the countdown value should turn red when it reaches 5)

    Sample file attached. Do let me know if I need to give any clarification. Thank you.
    Sub chkAnswer()
        Range("D11").Value = Range("D11").Value + 1
        If Range("B7").Value = ans Then
            MsgBox "Bingo !!"
        Else
            MsgBox "Crap !!"
        End If
        Range("B6").Value = ""
        Range("B7").Value = ""
        If Range("D11").Value = 2 Then
            stopClock
            Range("D11").Value = 0
        End If
        'If answer is not given before the countdown time then
        '    MsgBox "You moron! 30 seconds is not enough for you?"
        'End If
    End Sub
    PS: I got the source code here http://www.youtube.com/watch?v=s2uzsj95IxQ and modified as per my requirement
    Attached Files Attached Files
    Last edited by freeofcost; 11-17-2014 at 01:41 AM. Reason: Added original source code link

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,650

    Re: Answer a question within timeline

    If you want to pause clock - you cannot simply rely on Now() with displaying value (either include used pause time in displayed value or try for instance:
    Sub runClock()
        Range("B2").Value = tCtr
          If clockOn = True Then
            tCtr = tCtr + TimeValue("00:00:01")
            Application.OnTime Now + TimeValue("00:00:01"), "runClock"
          End If
    End Sub
    Sub startClock()
      If chkStop = True Then
          MsgBox "Stop clock first and then start"
      Else
        clockOn = True
        chkStop = True
        tCtr = 0
        runClock
      End If
    End Sub
    Sub stopClock()
        clockOn = False
        chkStop = False
        Range("C3").Value = ""
        Range("C4").Value = ""
    End Sub
    Sub resetClock()
        If chkStop = True Then
            MsgBox "Stop clock first and then reset"
        Else
        Range("B2").Value = 0
        End If
    End Sub
    Sub pauseClock()
        clockOn = False
    End Sub
    Sub resumeClock()
        clockOn = True
        Application.OnTime Now + TimeValue("00:00:01"), "runClock"
    End Sub
    as for countdown - add new variables with countdown timer value and state
    red color if less than 5 seconds - use conditional formatting of the cell.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Answer a question within timeline

    Thank you Kaper.. Appreciate your help
    Quote Originally Posted by Kaper View Post
    If you want to pause clock - you cannot simply rely on Now() with displaying value (either include used pause time in displayed value or try for instance:
    I should have thought about including the used pause time. A condition in startClock() 'If chkStop = True Then' is also something I missed to ensure user does not start the clock twice. Thank you very much.

    Quote Originally Posted by Kaper View Post
    as for countdown - add new variables with countdown timer value and state
    red color if less than 5 seconds - use conditional formatting of the cell.
    I have been trying to do this from the time I posted the question. I have the logic. however, I fail in syntax. As mentioned in the original post, I took this code from a youtube video and edited as per my needs. however, unable to get the countdown timer of 10 seconds to work. I formatted B4 cell to "ss" so that only seconds can be visible then i was trying to copy the same clock logic for my countdown but in vain. Appreciate if you can help me here.
    as for color, yes... conditional formatting would be a better choice than coding...

    Thank you.

  4. #4
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Answer a question within timeline

    The Resume button is now working. I am still struggling the countdown to work. It is not alerting user when the countdown is over
    Attached Files Attached Files
    Last edited by freeofcost; 11-19-2014 at 03:49 AM. Reason: updated attachment

+ 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. code to progressively go throughly question based on answer to first question
    By Ishwarind in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-08-2014, 06:48 AM
  2. question with a worksheet that creates a timeline
    By waternut in forum Excel General
    Replies: 5
    Last Post: 07-22-2009, 02:26 PM
  3. Question/Answer programs
    By byte_me in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-26-2008, 05:12 PM
  4. [SOLVED] Help please I cannot get an answer to this question
    By Alan M in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-20-2006, 10:00 AM
  5. Answer to my question
    By David in forum Excel General
    Replies: 1
    Last Post: 06-22-2005, 08:05 PM

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