Results 1 to 5 of 5

Thread: [RESOLVED] Timer Problem

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    62

    Resolved [RESOLVED] Timer Problem

    i have a timer but i dont know how to make that when the timer make 5 sec to call a function

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Timer Problem

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        With Timer1
            .Interval = 5000
            .Enabled = True
        End With
    End Sub
    
    Private Sub Timer1_Timer()
        mySub
    
        'remove this if you want to call
        '"mySub" constantly every 5 secons
        Timer1.Enabled = False
    End Sub
    
    Private Sub mySub()
        '...
    End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    62

    Re: Timer Problem

    hmm i doesn't work for me !! or i didn't understand this part :

    vb Code:
    1. Private Sub Timer1_Timer()
    2.     mySub
    3.  
    4.     'remove this if you want to call
    5.     '"mySub" constantly every 5 secons

  4. #4
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Timer Problem

    That's the actual call. It's an example. If you remove the line the comment is talking about ('Timer1.Enabled = False'), Timer will fire EVERY 5 seconds - not just once - until it's disabled.

    Perhaps you think it doesn't work for you, cause 'mySub' is empty. Try it like this:
    Code:
    Private Sub mySub()
        MsgBox "Can you see me?"
    End Sub

  5. #5
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Timer Problem

    Ok, once you place a timer in the application and look at the properties you should see a property call Interval

    The interval propery is in miliseconds, if you want the timer to get triggred every 5 seconds you would set it to 5000. Or code it in the form load.

    You should also see an Enable property, that property should be false

    VB Code:
    1. Private Sub Form_Load()
    2.     Timer1.Interval = 5000 'This is the intervals between triggers (5 Seconds * 1000 miliseconds)
    3.     Timer1.Enabled = True
    4. End Sub
    5.  
    6. Private Sub Timer1_Timer()
    7.     'Any code that goes in here will get executed
    8.     'On the intervals you set before
    9.     MsgBox "5 seconds Passed"
    10. End Sub
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

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