Delay - Function

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!
Post Reply
User avatar
SebMcClouth
Veteran
Posts: 240
Joined: Fri Apr 29, 2005 2:20 am
Location: Inside the Matrix

Delay - Function

Post by SebMcClouth »

Currently I'm using:

Code: Select all

SUB Delay (Value as integer)
t! = timer
do: loop while timer - t! < Value
end sub
When I use under .5 it doesn't work and I need a delay that
works for say .2 secs or so.

grtz
Seb
I know why you're here. I know what you've been doing... why you hardly sleep, why you live alone, and why night after night, you sit by your computer...<br>
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

I have the same problem.
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Re: Delay - Function

Post by moneo »

SebMcClouth wrote:Currently I'm using:

Code: Select all

SUB Delay (Value as integer)
t! = timer
do: loop while timer - t! < Value
end sub
When I use under .5 it doesn't work and I need a delay that
works for say .2 secs or so.

grtz
Seb
Looking at your code, I notice that "Value" is an integer. Therefore, it will never work for .5 nor for .2 or other value with decimals.
Try it with "Value" as single.

Considerations:

* TIMER is incremented every 1/18 of a second, which should allow you to test for time differences up to .055 seconds (55 ms.).

* Please be aware that the value of TIMER will get reset to zero at midnight, which could screw up your test if you're operating near midnight.
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

I usually write a DELAY sub like this:

Code: Select all

SUB Delay (DLY%)
Let ToTest = Timer + DLY%
While ToTest > Timer
Wend
End Sub
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

This one works fine here:....

Code: Select all

DECLARE SUB DELAY (Value!)
CLS
DO
    Test! = TIMER
    DELAY .1
    LOCATE 1, 1: PRINT (TIMER - Test!)
LOOP UNTIL INKEY$ = CHR$(27)


SUB DELAY (Value!)
    T! = TIMER
    DO: LOOP UNTIL (TIMER - T!) >= Value!
END SUB
Notice its not a integer as moneo pointed out... :wink:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Guest

Post by Guest »

I found I had the same problem but figured out that I could just change the temp timer variable should be a double. I'm guessing that this is in FB.
Seb McClouth

Post by Seb McClouth »

Rattrapmax6 wrote:This one works fine here:....

Code: Select all

DECLARE SUB DELAY (Value!)
CLS
DO
    Test! = TIMER
    DELAY .1
    LOCATE 1, 1: PRINT (TIMER - Test!)
LOOP UNTIL INKEY$ = CHR$(27)


SUB DELAY (Value!)
    T! = TIMER
    DO: LOOP UNTIL (TIMER - T!) >= Value!
END SUB
Notice its not a integer as moneo pointed out... :wink:
So by chaning my Value as integer to Value! it should work?

grtz
Seb
Seb McClouth

Post by Seb McClouth »

Nvm. It works!!

Thx mate...

Grtz
Seb
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

Code: Select all

SUB DELAY (Value!)
    T! = TIMER+Value!
    PT = TIMER
    DO: LOOP UNTIL TIMER >= T! OR TIMER < PT
END SUB
Added check for midnight loop.

At midnight, TIMER resets to 0, so, if you start your delay at 11:59:59pm and have it wait for 2 seconds, it would go forever..

As:
11:59:59 + 1 = 0

Yup, silly timer behaviour..
I have left this dump.
Seb McClouth

Post by Seb McClouth »

Updating now!!

grtzz
Seb
Post Reply