1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-26 07:25:53 +00:00
QB64-PE/internal/help/TIMER_(statement).txt
SMcNeill 6e01fc8dce Altered string compare routines (<,<=,>,>=) so they don't give false results with CHR$(0).
Added new _STRCMP and _STRICMP commands for quick string comparisons.
Cleaned up QB64 to finish removing the QUI (quick user insert) code and folders.
Altered UCASE and LCASE routines to be faster in some situations for us.
2014-09-22 08:19:03 -04:00

58 lines
2.6 KiB
Plaintext

A '''TIMER''' statement enables, turns off or stops timer event trapping. Qbasic only uses the base timer, but '''QB64''' can run many.
QB {{PageSyntax}}
:::TIMER {ON|STOP|OFF}
QB64 {{PageSyntax}}
:::TIMER(''number%'') {ON|STOP|OFF|FREE}
* TIMER ON enables event trapping of an [[ON TIMER (n)]] statement. While enabled, a check is made after every code statement to see if the specified time has elapsed and the ON TIMER [[GOSUB]] (or [[SUB]] in QB64) procedure is executed.
* TIMER STOP disables timer event trapping. When an event occurs while stopped, it is remembered. If timer events are turned back on later, any remembered events are immediately executed.
* TIMER OFF turns timer event trapping completely off and no subsequent events are remembered.
&lt;center&gt;'''QB64 only'''&lt;/center&gt;
* ''number'' denotes a specific numbered timer event in '''QB64 only'''. QB64 can run many timer events at once including the base timer.
* Get a TIMER number from [[_FREETIMER]] ONLY except when the base timer(no number or 0) is used. Use specific variables or an array to hold each event number value for later reference.
* If the TIMER number is omitted or 0, the TIMER used is the base timer.
* Specific TIMER events can be enabled, suspended, turned off or freed using [[TIMER (statement)|TIMER(n)]] ON, STOP, OFF or FREE.
* TIMER(n) '''FREE''' clears a specific timer event when it is no longer needed. '''The base TIMER or TIMER(0) cannot be freed!'''
&lt;center&gt;'''QB64 Timing Alternatives'''&lt;/center&gt;
* The [[TIMER]] function can be used to find timed intervals down to 1 millisecond(.001) accuracy.
* The [[_DELAY]] statement can be used to delay program execution for intervals down to milliseconds.
* [[_LIMIT]] can slow down loops to a specified number of frames per second. This can also alleviate a program's CPU usage.
''Example:'' How to update the time while [[PRINT|printing]] at the same time in a program.
{{CodeStart}} '' ''
TIMER ON ' enable timer event trapping
LOCATE 4, 2 ' set the starting PRINT position
{{Cl|ON TIMER(n)|ON TIMER}}(10) GOSUB Clock ' set procedure execution repeat time
DO WHILE INKEY$ = &quot;&quot;: PRINT &quot;A&quot;; : SLEEP 6: LOOP
TIMER OFF
{{Cl|SYSTEM}}
Clock:
row = {{Cl|CSRLIN}} ' Save current print cursor row.
col = {{Cl|POS|POS(0)}} ' Save current print cursor column.
LOCATE 2, 37: PRINT {{Cl|TIME$}}; ' print current time at top of screen.
LOCATE row, col ' return to last print cursor position
{{Cl|RETURN}} '' ''
{{CodeEnd}}
: NOTE: SLEEP will be interrupted in Qbasic.
''See also:''
* [[ON TIMER(n)]], [[TIMER]](function)
* [[_DELAY]], [[_LIMIT]]
{{PageNavigation}}