ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
ON TIMER and TIMER Statements Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' This example uses the TIMER and ON TIMER statements to enable timer event
' trapping. The program draws a polygon with a random shape, size, and
' location every three seconds.
 
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
 
 CLS                              ' Clear the screen
 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 3 seconds
 PRINT "Press any key to end program"
 INPUT "Press <RETURN> 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 polygon
          Y(I) = INT(RND * 199)
     NEXT
     PSET (X(N), Y(N))
     FOR I = 0 TO N
          LINE -(X(I), Y(I)), 2   ' Draw new polygon
     NEXT
     RETURN