Qbasicnews.com

Full Version: Timer Problems
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi,
In my code I have this
Code:
DO
        a=a+1
        key$=inkey$
loop until key$<>"" OR a=100000

my problem is that on a 133Mhz the loop takes 1-2 mins to complete but on 450Mhz it takes 10-20secs and I want a way to replace the a=a+1 etc with a better timer, any ideas?
TIMER
lol

----

ray if i understand you correctly, if you want your program to stop for one second then:

Code:
stimer = timer
do
loop until timer > stimer + 1

if not, then whatever.

Anonymous

optimize that like this:

Code:
stimer = timer + 1
do
loop until timer > stimer

that way the 'add' operation only happens once =)
If your delays are bigger than 1/18 second TIMER is ok
Code:
d!=2.2           'delay in seconds        
t!=timer+d!
do
loop until (timer!>t!) or (timer<d!) or (len(inkey$))

the condition timer<d! is to avoid getting stuck at midnight
i see,

Code:
stimer = timer
do
if timer < stimer then stimer = 86400 - stimer: stimer = 0 - stimer
loop until timer > stimer + 15

this also deals with midnight...i think :???:

edit: i fixed it and it does indeed work when run past midnight Smile
Quote:i see,

Code:
stimer = timer
do
if timer < stimer then stimer = 86400 - stimer: stimer = 0 - stimer
loop until timer > stimer + 15

this also deals with midnight...i think :???:

edit: i fixed it and it does indeed work when run past midnight Smile
I've never cared for the midnight bug, and never had any reports of anyone having it happen to them.. I guess it's pretty rare for people to run <1 sec timer based delays/loop exactly at midnight Tongue
that's what thought. but i guess that's why they call them contingencies.

i guess if you have a game that uses it every second or somthing.
because i want it to wait 1min30secs then start the loop again will this work:
Code:
stimer = timer+90
key$=""
do
key$=inkey$
if stimer>=timer then turncomplete=TRUE
loop until key$<>"" OR turncomplete=TRUE
there is still a problem now the screen redraws 15 times in 1 sec then goes at the exceted speed
Pages: 1 2