﻿ TIMER Statements Action Enable, disable, or suspend timer-event trapping. Syntax TIMER ON TIMER OFF TIMER STOP Remarks TIMER ON enables timer-event trapping. A timer event occurs when n seconds have elapsed (as specified in the ON TIMER statement). If a timer event occurs after a TIMER ON statement, the routine specified in the ON TIMER statement is executed. TIMER OFF disables timer-event trapping. No timer-event trapping takes place until a TIMER ON statement is executed. Events occurring while trapping is off are ignored. TIMER STOP suspends timer-event trapping. No trapping takes place until a TIMER ON statement is executed. Events occurring while trapping is off are remembered and processed when the next TIMER ON statement is executed. However, remembered events are lost if TIMER OFF is executed. When a timer-event trap occurs (that is, the GOSUB is performed), an automatic TIMER STOP is executed so that recursive traps cannot take place. The RETURN operation from the trapping routine automatically performs a TIMER ON statement unless an explicit TIMER OFF was performed inside the routine. For more information, see Chapter 9, "Event Handling" in the Programmer's Guide. See Also ON event, TIMER Function Example This example uses the ON TIMER statement to trap timer events. It draws a polygon every three seconds with a random shape (three to seven sides), size, and location. SCREEN 1 DEFINT A-Z DIM X(6), Y(6) TIMER ON' Enable timer-event trapping. ON TIMER(3) GOSUB Drawpoly' Draw a new polygon every three seconds. PRINT "Press any key to end program" INPUT "Press to start",Test\$ DO LOOP WHILE INKEY\$ = ""' End program if any key pressed. END Drawpoly. CLS' Erase old polygon. N = INT(5 * RND + 2)' N is random number from 2 to 6. FOR I = 0 TO N X(I) = INT(RND * 319)' Get coordinates of vertices of Y(I) = INT(RND * 199)' polygon. NEXT PSET (X(N), Y(N)) FOR I = 0 TO N LINE -(X(I), Y(I)),2' Draw new polygon. NEXT RETURN