Results 1 to 7 of 7

Thread: timer trouble

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    133

    Question timer trouble

    HI i have the following code


    VB Code:
    1. timer1.enabled = False
    2. 'a bit of code
    3. timer1.enabled = True

    this executes the code between the timer1, every time its interval is up, so to say.

    I want to disable this timer when a button is pressed and enable it again, when another is pressed....

    to disable it had

    VB Code:
    1. Private Sub command1.click ()
    2.  
    3. timer1.enabled = False
    4.  
    5. End Sub
    6.  
    7. ' and to enable it again i had
    8.  
    9. Private Sub command1.click ()
    10.  
    11. timer1.enabled = True
    12.  
    13. End Sub

    This didn't work as i have already enabled it in another part of the code

    Any Thoughts
    Chris Lynch
    11 is the magic number

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: timer trouble

    You have to disable it if you don't want it to fire. There is no problem with enabling the timer twice. See this code.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  Timer1.Interval = 5000
    5.  Timer1.Enabled = True
    6.  MsgBox ""
    7.  Timer1.Enabled = True
    8. End Sub
    9.  
    10. Private Sub Timer1_Timer()
    11.   Beep
    12. End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    133

    Re: timer trouble

    I think you misunderstand me, i want to disable the timer when i press a command button nut the code i have in post1 is not working?

    Chris Lynch
    11 is the magic number

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: timer trouble

    You had it right:
    VB Code:
    1. Timer1.Enabled = False

    will disable the timer.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    133

    Re: timer trouble

    Yes i know that but its not disabling the timer......
    11 is the magic number

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    133

    Re: timer trouble

    I have it thanks
    Chris Lynch
    11 is the magic number

  7. #7
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Thumbs up Re: timer trouble

    Quote Originally Posted by Chris Lynch
    HI i have the following code



    visual basic code:--------------------------------------------------------------------------------

    timer1.enabled = False
    'a bit of code
    timer1.enabled = True

    --------------------------------------------------------------------------------

    this executes the code between the timer1, every time its interval is up, so to say.

    I want to disable this timer when a button is pressed and enable it again, when another is pressed....

    to disable it had


    visual basic code:--------------------------------------------------------------------------------
    Private Sub command1.click ()

    timer1.enabled = False

    End Sub

    ' and to enable it again i had

    Private Sub command1.click ()

    timer1.enabled = True

    End Sub
    --------------------------------------------------------------------------------

    This didn't work as i have already enabled it in another part of the code

    Any Thoughts
    Chris Lynch
    __________________
    11 is the magic number
    I found this code on the forum and it wrks great in the Click Event of a Command Button:

    VB Code:
    1. Private Sub Command1_Click()
    2.       Timer1.Enabled = Not Timer1.Enabled
    3. End Sub

    Every time the Command button is clicked the enable property will be toggled. Great idea for the person who can up with this idea.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


Posting Permissions

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



Click Here to Expand Forum to Full Width