Page 1 of 1

Delay - Function

Posted: Wed Aug 24, 2005 2:33 pm
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

Posted: Wed Aug 24, 2005 3:58 pm
by Patz QuickBASIC Creations
I have the same problem.

Re: Delay - Function

Posted: Wed Aug 24, 2005 5:48 pm
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.
*****

Posted: Wed Aug 24, 2005 5:57 pm
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

Posted: Wed Aug 24, 2005 6:07 pm
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:

Posted: Thu Aug 25, 2005 12:07 am
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.

Posted: Thu Aug 25, 2005 4:54 am
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

Posted: Thu Aug 25, 2005 4:56 am
by Seb McClouth
Nvm. It works!!

Thx mate...

Grtz
Seb

Posted: Thu Aug 25, 2005 5:54 am
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..

Posted: Thu Aug 25, 2005 1:13 pm
by Seb McClouth
Updating now!!

grtzz
Seb