Results 1 to 12 of 12

Thread: how to set timer.interval = 1 hour?

  1. #1

    Thread Starter
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    how to set timer.interval = 1 hour?

    hey anybody can help me on how to set the timer.interval into 1 hour and higher? 1 sec = 1000, so 1 min = 60000, but 5 min = 300000 get an error. invalid property. why? any help here plz... tnx in advance
    noister
    <advertising link removed by moderator>

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: how to set timer.interval = 1 hour?

    You could try it like this... But be aware that the timer control is not precise...

    VB Code:
    1. 'Interval=60000
    2. Private Sub Timer1_Timer()
    3.     Static mCount As Long
    4.     mCount = mCount + 1
    5.     If mCount >= 60 Then
    6.         MsgBox "One hour"
    7.     End If
    8. End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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

    Re: how to set timer.interval = 1 hour?

    Set the timer to an interval of 1000, and keep a counter until it gets up to 3600, which is an hour. Take a look at this example that I wrote. I added time and compared that to the ending time.

    http://vbforums.com/attachment.php?attachmentid=38745

  4. #4
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: how to set timer.interval = 1 hour?

    The Interval property is an unsigned integer which means the largest value it will accept is 65535. You need to do as dee-u or dglienna suggest.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  5. #5

    Thread Starter
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    Re: how to set timer.interval = 1 hour?

    ah, ok! tnx to all, dee-u i'm from cebu, phil to...

  6. #6
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068

    Re: how to set timer.interval = 1 hour?

    A Timer's interval can only be set to 60,000 (60 seconds). The best thing to do is have a start date which you can set in a variable using String = Now, then in your timer have it constantly check String Vs Now to see if an hour has gone by. You can use the Datedif() function for this.
    VB Code:
    1. Private Sub Timer1_Timer()
    2.    If DateDiff("h", Now, String) >= 1 Then 'I may have these backwards
    3.  
    4.              'Code here, it has been an hour, ARE YOU NOT LISTENING?!?!
    5.    End If
    6. End Sub

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

    Re: how to set timer.interval = 1 hour?

    Wasn't that posted at least three times in this thread alone?

  8. #8
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068

    Re: how to set timer.interval = 1 hour?

    No one else used the DateDiff() Function, hoser.

    Also, none of the above solutions are very accurate in time keeping, the Date functions are.
    Last edited by Spajeoly; Dec 20th, 2005 at 03:20 AM.

  9. #9

    Thread Starter
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    Re: how to set timer.interval = 1 hour?

    tnx Spajeoly! actually i already solved my problem, but tnx for your other idea... i learn a lot here!...

  10. #10
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068

    Re: how to set timer.interval = 1 hour?




    Sure thing...

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: how to set timer.interval = 1 hour?

    You should use the SetTimer() function. More efficient and accurate. Counting intervals using VB's timer is not a good idea.

    If you need to you can search the Codebank section for a demonstration of using that function.

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

    Re: how to set timer.interval = 1 hour?

    Post #3, you could set your watch by it. It uses dateadd() for the timer.

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