'===========================================================================
' Subject: TIMER FAQ                          Date: 03-11-95 (00:00)       
'  Author: Bill White                         Code: Text                   
'  Origin: FidoNet QUIK_BAS Echo            Packet: FAQS.ABC
'===========================================================================
'> I am writing a program and I am wanting the opening screen
'> to pause for maybe 3 seconds (I can work on revising the
'> amount of time if I can ever get the screen to pause)
'> before continuing on to the rest of the program.  I have
'> tried TIMER (3) variations, but haven't been able to get
'> anything to work.  It keeps going straight into the
'> program.  Does anybody have a routine to pause a program
'> for a certain amount of time before continuing?  Thankyou.

'     TIMER.FAQ                                  3/11/95

'     A Frequently Asked Question (FAQ) is "how do I
'introduce a delay into my program, independent of the
'CPU speed?"  In the past there has been extensive
'discussion in this echo of this subject, which brought
'out some problems.  A summary of this discussion
'follows:

'     The old BASIC statement we used for years:

 FOR i=1 to 1000: NEXT i

'is not independent of the CPU speed.

'     You could use SLEEP 2.  This, however, has
'problems: integer numbers only, user can hit _ANY_ key
'to jump out of it, and that key will be held in the
'buffer waiting to bite the next INPUT command unless
'dumped with DO: LOOP UNTIL INKEY$ = ""

'     TIMER can be used - it ticks off 1/18.2 of a
'second:

 delay = 2
 finish = TIMER + delay
 DO
 LOOP UNTIL TIMER => delay

'     This works, but has a fatal midnight flaw: the
'timer is reset to 0 at midnight and it is therefore
'possible that "finish" will never be reached.  It's
'easy to test for midnight (there are 86,400 seconds in
'a day).

'     However, it is easy not to depend on TIMER to do
'the counting - count it yourself.  Something like:

 delay = whatever
 t! = INT(TIMER)
 DO
     IF t! <> INT(TIMER) THEN
         t! = INT(TIMER)
         count = count + 1
         PRINT count
     END IF
 LOOP UNTIL count = delay

'     This routine doesn't care what the reading of
'TIMER is, only that it has changed.  A roll-over at
'midnight is just as valid a change as an increase of
'one second.  If you want 1/10's of a second, you'll
'need to alter accordingly.  Since TIMER ticks at 18.2
'times a second, the smallest interval will be
'0.0549450549 sec.
