*** TIMING, by Jakob Krarup (Jake@post5.tele.dk) ***************************** Hi I'm Jakob Krarup (Jake@post5.tele.dk), and I've been programming in QBASIC around 5 years now. I was going to switch completely to Visual Basic when I came across the BASIX Arcives on the net, and suddenly I knew - I was not alone - it was cult to do the QB thing = ) So I downloaded the nine issues of BASIX and read them thoroughly over and over, and my programs started improving drastically. So now I'd like to put something back into the newzine, since I've gotten so much from it. A lot of programs I find on the net use the FOR...NEXT loop to pause the game by merely counting, and then the programmer has added a comment along the lines: "'alter this if the program runs too slow/fast". There is a better way, which doesn't change speed according to the speed of the computer. Of course we could use the SLEEP command, but since most of the delays we're talking about are all below one second, this will not do. I usually store the timer in a variable of type single and then do a loop while the difference between the starting time and the current time hasn't passed the desired delay. Like this: Delay! = 0.5 'Set the delay (change the value to the desired length) StartingTime! = TIMER 'Store the starting time DO 'keep checking whether LOOP WHILE TIMER - StartingTime! < Delay! 'enough time has passed. This can easily be changed into a SUB: SUB DELAY (Delay!) StartingTime! = TIMER 'Store the starting time DO 'keep checking whether LOOP WHILE TIMER - StartingTime! < Delay! 'enough time has passed. END SUB This way you could just write Delay .5 in your code - and the sub takes care of the rest as simple as that. -------------------------------------------------------- * EDITOR'S NOTE: * This article was originally printed in Peter Cooper's BASIX Fanzine, * Issue #10 from April 1998. This issue was edited by Alex Warren.