'===========================================================================
' Subject: CALCULATING DELAY VALUES           Date: 10-26-97 (20:22)       
'  Author: William Deer                       Code: QB, QBasic, PDS        
'  Origin: ag312350@student.uq.edu.au       Packet: DATETIME.ABC
'===========================================================================
DECLARE SUB Delay (Value#)
DECLARE SUB CalculateDelay ()
' TIMER.BAS
' Some of us have found that the same program runs at entirely different
' speeds on different computers, and this makes some games difficult to
' operate without modifying a delay component. This program will
' automatically calculate delay values which should be accurate enough
' for most applications.
'
' The program will store the values, SecondDelay, and MilliDelay as double
' precision variables. These values can be used to produce quite accurate
' delays.
' To produce a delay of 3 seconds, include  CALL Delay(SecondDelay*3)
' To produce a delay of 500 milliseconds,   CALL Delay(MilliDelay*500)
'
' This program was written in Qbasic v1.1 (if I could find anyone in
' Australia willing to sell me their v4.5, I would probably use it instead),
' so it should be compatible with v1-oo


DIM SHARED SecondDelay AS DOUBLE:      ' Delay value for 1 second
DIM SHARED MilliDelay AS DOUBLE:       ' Delay value for 1 millisecond

CLS
PRINT "Timer.BAS    by William DEER c/o ag312350@student.uq.oz.au "
PRINT "Calculating Delay Values"
PRINT
CALL CalculateDelay
PRINT "Value for 1 msecond delay (stored in MilliDelay)  = "; MilliDelay
PRINT "Value for  1 second delay (stored in SecondDelay) = "; SecondDelay
PRINT
PRINT "To obtain a delay of 10 seconds, type CALL Delay(SecondDelay*10)  "
PRINT "On this computer, it will take .....";
A# = TIMER: CALL Delay(SecondDelay * 10): B# = TIMER
PRINT USING "##.###"; B# - A#;
PRINT "   seconds"
PRINT
PRINT "To obtain a delay of 645 milliseconds, type CALL Delay(MilliDelay*645)  "
PRINT "On this computer, it will take .....";
A# = TIMER: CALL Delay(MilliDelay * 645): B# = TIMER
PRINT USING "###.#"; (B# - A#) * 1000;
PRINT "   milliseconds"
PRINT
PRINT "If anyone knows of an easier way of obtaining accuracy, please let us "
PRINT "know. Because the SLEEP command handles seconds quite well, this"
PRINT "program could be made to handle only milliseconds."








SUB CalculateDelay
Test# = 50000     ' Test variable to pass number to Subrountine
StartTimer# = TIMER
CALL Delay(Test#)
StopTimer# = TIMER
Difference# = StopTimer# - StartTimer#
SecondDelay = Test# / Difference#
MilliDelay = SecondDelay# / 1000
END SUB

SUB Delay (Value#)
  FOR A# = 1 TO Value#
  NEXT A#
END SUB
