Resetting a timer in VB6


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Jul 2003
    Posts
    2,405

    Default Resetting a timer in VB6

    Is there some way to reset a timer in VB6?

    What I need to do is reset a timer to zero each time a button is clicked. When the timer
    interval is reached, it clears a text box, but I need to reset the timer if another button is
    clicked before the timer interval is reached. Is this do-able?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Is there some way to reset a timer in VB6?
    If you're talking about the TIMER control, wouldn't disabling and then re-enabling it reset it to zero?

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Nope. It just disables the timer event. It will fire at odd times once it's re-enabled because
    it's not being reset to zero.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Nope. It just disables the timer event. It will fire at odd times once it's re-enabled because it's not being reset to zero.
    Timer - as in timer that counts from 0 to 86400 during a day?
    Or..
    Timer - as in timer that will fire off an event every X milliseconds?
    If it's the 1st one, I thought that one was driven by the 8259(or whatever it's equivalent is these days), a BIOS sort of thing that can't be reset with doing a 2 fingered salute (CMOS jumper reset )
    Last edited by skimask; - 21st July 2008 at 23:18. Reason: Had my numbers (1st and 2nd) backwards

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I have a VB form with multiple buttons. When a user presses a button, it prints the button
    value to a text box. Button values range from 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

    The text box needs to be cleared after a timeout period of around 15 seconds, but only if
    no other buttons are pressed during this time interval.

    I.E. the user can enter 1, and it clears in the text box after 15 seconds. But if the user
    enters 1, 2, 3, then the timer interval should be reset to zero after button #3 is pressed
    so 123 in the text box is cleared in 15 seconds.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    Bruce -
    Disable the timer, then set the interval property back to whatever you need.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  7. #7
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    I feel, it can't be done with the timer control as it is. Rewriting the interval does not reset the internal counting of the timer. I could suggest you look at this construct if you could use it.

    Code:
    sub Wait(interval as single)
    Dim x as single
    
         x = timer+interval
         while x > timer: doevents:wend
    end sub
    This uses the inbuilt function 'Timer' to wait while the interval has not expired. This function is useful as an in-line timer.

    Hope this helps.

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Thanks guys, but neither of these approaches will work. Stopping & resetting the interval is
    a no go, and a sub or proceedure that blocks button clicks isn't an option.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    Hi Bruce,
    Try disabling the Timer then set the interval to 0 and then set it back to whatever interval you want before enabling it again.

    From this page on MSDN:
    The Timer control's Enabled property determines whether the control responds to the passage of time. Set Enabled to False to turn a Timer control off, and to True to turn it on. When a Timer control is enabled, its countdown always starts from the value of its Interval property setting
    So if you first set the interval to 0 and then reset it to whatever it should do what you want, right?

    /Henrik.

  10. #10
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HenrikOlsson View Post
    Hi Bruce,
    Try disabling the Timer then set the interval to 0 and then set it back to whatever interval you want before enabling it again.

    From this page on MSDN:


    So if you first set the interval to 0 and then reset it to whatever it should do what you want, right?

    /Henrik.
    This method seems to work for me. Here's a quick test I used to verify. Set timer1 interval to 3000
    Code:
    Private Sub Command1_Click()
    Timer1.Enabled = True
    End Sub
    
    Private Sub Command2_Click()
    Label1.Caption = ""
    End Sub
    
    Private Sub Command3_Click()
    Timer1.Enabled = False
    Timer1.Interval = 0
    Timer1.Interval = 3000
    End Sub
    
    Private Sub Timer1_Timer()
    Label1.Caption = "DONE"
    End Sub
    Good call Henrik!
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  11. #11
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Woohoo...;o}

    Thanks guys. That did the trick.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  12. #12
    Join Date
    Dec 2013
    Posts
    1


    Did you find this post helpful? Yes | No

    Default Re: Resetting a timer in VB6


    • Private Sub Command1_Click() Timer1.Enabled = True End Sub Private Sub Command2_Click() Label1.Caption = "" End Sub Private Sub Command3_Click() Timer1.Enabled = False Timer1.Interval = 0 Timer1.Interval = 3000 End Sub Private Sub Timer1_Timer() Label1.Caption = "DONE" End Sub
      Good call Henrik!



      please pals were do i insert this code. is it the timer or the button use in starting the timre or the progress bar please help


Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 16:45
  3. Timer + rc5
    By naga in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th November 2009, 07:56
  4. Timer interrupt frequency
    By Samoele in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th January 2009, 23:49
  5. timer interupt help 16f73
    By EDWARD in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd July 2005, 08:41

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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