Liberty BASIC Help Online

TIMER
TIMER milliseconds, [branchLabel]
Timer milliseconds subName
 
Description:
This commands manages a Windows timer.  This is useful for controlling the rate of software execution (games or animation perhaps), or for creating a program or program feature which activates periodically (a clock perhaps, or an email client which checks for new messages).  The TIMER is deactivated by setting a time value of 0, and no branch label.  There is only one timer.  The elapsed time value and/or branch label to execute can be changed at any time by issuing a new TIMER command.  There are 1000 milliseconds in one second.  A value of 1000 causes the timer to fire every one second.  A value of 500 causes the timer to fire every half second, and so on.
 
Usage:
 
Branch Label Handler:          
    'set a timer to fire in 3 seconds
    'using branch label event handler
    timer 3000, [itHappened]
    'wait here
    wait
 
[itHappened]
    'deactivate the timer
    timer 0
    confirm "It happened!  Do it again?"; answer
    if answer then
        'reactivate the timer
        timer 3000, [itHappened]
        wait
    end if
    end
 
Subroutine handler:
 
    'set a timer to fire in 3 seconds
    'using subroutine event handler
    timer 3000, itHappened
    'wait here
    wait
 
sub itHappened
    'deactivate the timer
    timer 0
    confirm "It happened!  Do it again?"; answer
    if answer then
        'reactivate the timer
        timer 3000, itHappened
    end if
    end sub
 
Be Careful!
If the program attempts to execute more code within a timer routine than can be executed in the timer interval, the timer ticks build up and the program will keep executing them as quickly as it can.  This might make the program appear to have locked up.  To avoid a lock-up, place a SCAN command within the timer routine, so that the program knows when the user activates other controls, or closes a window.


Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/