Results 1 to 10 of 10

Thread: Get pass timer Limitation

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    12

    Angry

    Thanx for reading my thread...

    When using the Timer.. The time interval value is between 0 to 65,535.. is there any way to get the timer event to fire between 0 to 7,200,000??? Cause i want it to fire every 2 hours or less?? Suggestions would be appreciated! =)

  2. #2
    Guest
    You can create your own timer using the Timer function.

    Code:
    Private Sub TimeCheck(Interval As Long)
    
        Start = Timer
        
        'Loop until the number of seconds in "Interval" has passed by
        Do While Timer < Start + Interval
            DoEvents
        Loop
        
    End Sub
    
    Private Sub Command1_Click()
    
        'Wait 2 hours then display a MessageBox
        TimeCheck (7200)
        MsgBox ("Time is up")
        
    End Sub

  3. #3
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    I'm pretty certain that the SetTimer API doesn't have this restriction. I know that it will at least run to 70,000. Give this a try:

    ****************Put this code in a module***************

    Code:
    Public Declare Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    
    Public Declare Function KillTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    Const WM_TIMER = &H113
    
    
    Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, _
            ByVal dwTime As Long)
            
            MsgBox "It is now 70 Seconds"
            
            
    'you can call the cleanup here, or call it from the form.
    'Just make sure you call it, or your program will crash
            
            Call TimerCleanup(hwnd)
            
       
    End Sub
    
    Private Sub TimerCleanup(ByVal hwnd As Long)
        Dim lret As Long
        
        lret = KillTimer(hwnd, 1)
    
    End Sub

    *******************Code for Form********************

    Code:
    Private Sub Command1_Click()
    Dim tval as long
    
    tval = SetTimer(Me.hwnd, 1, 70000, AddressOf TimerProc)
    End Sub

    And that should do it.


    Hope this helps.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    12
    I'm pretty new at this so i'm just trying to understand here

    Magatron: I'm assuming that in the

    Private Sub TimeCheck(Interval As Long)

    You are creating a New Timer Control and calling it "Start"

    (Snip of your code below)

    'Loop until the number of seconds in "Interval" has passed by
    Do While Timer < Start + Interval
    DoEvents
    Loop

    -- So this is kidda like a busy waiting loop right?

    (Snip of your code below)

    Private Sub Command1_Click()

    'Wait 2 hours then display a MessageBox
    TimeCheck (7200)
    MsgBox ("Time is up")

    End Sub

    -- So here, after user clicks on the command, basically it'll wait for 2 hours doing things in the "DoEvent" then print the message?

    -- I'm just starting so i'm not totally sure about things yet...


  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    12
    reeset :

    (snip of your code below)


    Dim tval as long
    tval = SetTimer(Me.hwnd, 1, 70000, AddressOf TimerProc)


    -- Is tval a special name that means the time of the interval it stores? And I was wondering how i know the Address for the TimerProc?

    Thanx for responding to my post magatron and reeset =)

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    12
    Hello, i just read about the Timer.setInterval :

    public final synchronized void setInterval( int value )

    -- So it takes an int values, which means that it can go up to 7,200,000 right? so if i go :

    public final synchronized void setInterval(7200000)

    -- Then theoritically i will get a timer event happening every 2 hours? I want the event cause i want it to do other things all the time but only something else every 2 hours?

  7. #7
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    Fragile:

    Quickly, the tval in

    Code:
    Dim tval as long 
    tval = SetTimer(Me.hwnd, 1, 70000, AddressOf TimerProc)
    isn't special in anyway. It is just a variable I used to hold the returned integer. If the function is successful, it returns a 1 and if it is unsuccessful, it returns a zero.

    Also, the Addressof is a pointer function. If points a named public function in a module. So as long as you have the TimeProc in a module (any module in the project), the Addressof operator will find it.


    Hope this answers your questions.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    12
    Reeset:

    Yes.. thanx for the explaination.. i have a much better idea now!! =)


  9. #9
    Guest
    Fragile, I was actually creating a sub called TimeCheck, not a control. The variable Start is stored when the function is called, so we have a starting time of when the sub was called hence we can determine when 2 hours is from then.

    So this is kidda like a busy waiting loop right?
    Yes, that loop, in a sense pauses the sub until the number of seconds specified in the Interval argument have passed by.

    Regarding your last question, yes, it will wait until 2 hours have passed by then it will continue execution of the sub.



  10. #10

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    12
    Magatron:

    Thanx for getting back to me..
    Actually, I'm trying to find a way to call an event every 2 hours.. and not have it stop and wait..

    When i use :

    timer.Interval = (setting the interval here in ms)


    it will fire the timer event to whatever i set, however, it's only up to about 65sec. at most...

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