Format
number1 = TIMER
Description
This statement will retrieve a timer count from the PCs hardware circuitry.
The timer count will be placed in number1. The timer count is in "clock
ticks". A "clock tick" occurs in the PC approximately 18.2 times per
second. The PC is continually incrementing this clock counter. This
statement can be used to time the duration of events.
Example
CLS
PRINT "PRESS A KEY"
STARTCNT&=TIMER
LOOP: X$=INKEY$
IF X$="" THEN LOOP:
ENDCNT&=TIMER
ELAPSED&=ENDCNT&-STARTCNT&
ELAPSED&=ABS(ELAPSED&)
ELAPSED&=ELAPSED&/18
PRINT "IT TOOK YOU APPROXIMATELY";
PRINT ELAPSED&
PRINT " SECONDS TO PRESS A KEY"
The above code fragment will time how long you wait to press a key in
seconds. You could modify it easily to display in clock ticks, which would
provide much more accuracy, if you deleted the statement which divides the
ELAPSED count by 18.
Comments
Note that it is necessary to use the absolute value of ELAPSED& since the
clock counts is stored as unsigned integers. ASIC integers, on the other
hand, are signed. If number1 is a long integer variable, then TIMER
retrieves the full PC timer value. However, if a normal integer variable
is specified as number1, then ASIC retrieves the least 16 significant bits
from the PC timer.
See Also
|