Difference between revisions of "ON TIMER(n)"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 17: Line 17:
 
* {{KW|TIMER (statement)|TIMER OFF}} disables timer event trapping. Events will not be remembered in a subsequent ON TIMER statement.
 
* {{KW|TIMER (statement)|TIMER OFF}} disables timer event trapping. Events will not be remembered in a subsequent ON TIMER statement.
 
* ON TIMER events will interrupt a {{KW|SLEEP}} call and return to normal program procedures.
 
* ON TIMER events will interrupt a {{KW|SLEEP}} call and return to normal program procedures.
* Qbasic can only use one TIMER event at a time.
+
* Qbasic can only use one TIMER event at a time and code must be in the main code.
  
 
<center> '''QB64 Specific Information''' </center>
 
<center> '''QB64 Specific Information''' </center>
Line 26: Line 26:
 
* Use the {{KW|_FREETIMER}} function to save free timer numbers to variables for TIMER statements.
 
* Use the {{KW|_FREETIMER}} function to save free timer numbers to variables for TIMER statements.
 
* TIMER(n) FREE releases a timer event after being turned off.
 
* TIMER(n) FREE releases a timer event after being turned off.
 +
* '''QB64''' allows TIMER statements to also be inside of SUB and FUNCTION procedures.
 
* Does not currently interrupt {{KW|SLEEP}} calls.
 
* Does not currently interrupt {{KW|SLEEP}} calls.
 
* {{KW|$CHECKING}}:OFF can disable QB64 event checking. '''It should ONLY be used with errorless code that needs every CPU cycle!'''
 
* {{KW|$CHECKING}}:OFF can disable QB64 event checking. '''It should ONLY be used with errorless code that needs every CPU cycle!'''

Revision as of 22:11, 7 November 2010

The ON TIMER statement sets up a timed event to be repeated at specified intervals.


Qbasic Syntax: ON TIMER(seconds%) GOSUB {linelabel|linenumber}


QB64 Syntax #1: ON TIMER([number%,] seconds!) GOSUB {linelabel|linenumber}
QB64 Syntax #2: ON TIMER([number%,] seconds!) SubProcedure [parameter[,...]]


Description

QBasic and QB64 Information
  • In Qbasic the INTEGER seconds parameter can be from 1 to 86400 seconds(one day).
  • A TIMER ON statement must be made before an ON TIMER event is enabled in QB or QB64.
  • TIMER STOP remembers previous events when enabled by a TIMER ON statement and the ON TIMER statement(s) may be executed immediately if a timer event has occurred.
  • TIMER OFF disables timer event trapping. Events will not be remembered in a subsequent ON TIMER statement.
  • ON TIMER events will interrupt a SLEEP call and return to normal program procedures.
  • Qbasic can only use one TIMER event at a time and code must be in the main code.
QB64 Specific Information
  • Can use multiple timers and SINGLE floating point second values down to one millisecond(.001).
  • If the TIMER number is omitted, the TIMER used is the base timer. That TIMER cannot be freed using TIMER[0] FREE. No number referance is used for that timer and keeps QB64 compatible with Qbasic.
  • Direct SUB procedure calls are also allowed without using CALL.
  • Use the _FREETIMER function to save free timer numbers to variables for TIMER statements.
  • TIMER(n) FREE releases a timer event after being turned off.
  • QB64 allows TIMER statements to also be inside of SUB and FUNCTION procedures.
  • Does not currently interrupt SLEEP calls.
  • $CHECKING:OFF can disable QB64 event checking. It should ONLY be used with errorless code that needs every CPU cycle!



Example: How to update the time while printing at the same time in a program.

TIMER ON ' enable timer event trapping LOCATE 4, 2 ' set the starting PRINT position ON TIMER(10) GOSUB Clock ' set procedure execution repeat time DO WHILE INKEY$ = "": PRINT "A"; : SLEEP 6: LOOP TIMER OFF SYSTEM Clock: row = CSRLIN ' Save current print cursor row. col = POS(0) ' Save current print cursor column. LOCATE 2, 37: PRINT TIME$; ' print current time at top of screen. LOCATE row, col ' return to last print cursor position RETURN

NOTE: SLEEP will be interrupted in Qbasic.


See also




Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page