Qbasicnews.com

Full Version: Is there a way to set a delay time til next line?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to make a delay of approx 1.5 seconds between a few lines of code, im sure iv done this before so i know theres a way, but for the love of god i cant remember how. :roll:
Use the TIMER lik this:

Code:
Time! = TIMER
DO: LOOP UNTIL TIMER > (Time! + 1.5)

That's all you gotta do :wink:
Its also a good idea to put it in a subroutine, makes the code clearer:

Code:
SUB Delay(seconds!)
   Time! = TIMER
   DO: LOOP UNTIL TIMER > (Time! + seconds!)
END SUB

And then just use

Code:
Delay 1.5

if you want to delay for 1.5 secs.
Good idea, Zap!

DON'T USE THIS : however, as I found out :lol:

time$ = "00:00"
do:loop until time$ = "00:02"

ARGH it resets the system clock!!??!?!!!! lol so don't use that, I would use ZAP's idea if I were you. Good thinking, Zap!
If you people will start using the TIMER for that kind of task, take into consideration the fact that the TIMER will reset after midnight, so if you start using the delay at, let's say 23:59:59, and the delay is set to one or two seconds, the condition LOOP UNTIL TIMER > (Time! + seconds!) will never be fulfilled.

An old sub of mine...

Code:
SUB Aguanta (num!)

Now! = TIMER
o! = TIMER + num!

DO WHILE TIMER < o!
IF Now! > TIMER THEN o! = o! - 86400
LOOP

END SUB

While basically the same, if the aforementioned situation occurs the "start" time will be substracted by 86400. Why that number? 24 hours in a day, 1440 minutes in a day... 86400 seconds in a day.

*sigh*
how would you display a timer counting down on the screen? :???:
each second?

There are many ways. For example using SLEEP 1, although that would not give exact seconds as the rest of the code takes time:

Code:
' crappy, easy sollution
CLS
PRINT "10 seconts to lift off"
locate 2,1:PRINT " 10"
FOR i%=9 TO 0 STEP -1
   SLEEP 1
   LOCATE 2,1:PRINT i%
NEXT i%
PRINT "LIFT OFF!!"

Using timer should give a more accurate sollution .Without taking in account HD's sollution to midnight issue, the code is as follows:

Code:
' Better sollution
CLS
PRINT "10 seconds to lift off"
LOCATE 2,1:PRINT " 10"
FOR i%=9 TO 0 STEP -1
   t!= TIMER
   WHILE TIMER<t!+1:WEND
   LOCATE 2,1:PRINT i%
NEXT i%
PRINT "LIFT OFF!!"

I'm sure that someone can come with another, weirdest sollution Smile