how to get the timer to count down

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Quicky
Coder
Posts: 20
Joined: Wed Jun 13, 2007 10:51 am

how to get the timer to count down

i can only get the timer to count up

ex.
start! = TIMER
COLOR 5, 10
x = INT(rnt * 300)
y = INT(rnt * 310)
finish! = TIMER
PRINT "time elapsed:"; finish - start!

but how do you get a count down

Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:
What is that code suppossed to do?

Quicky
Coder
Posts: 20
Joined: Wed Jun 13, 2007 10:51 am
it is just an ex. of a timer but that is as far as i can go with the timer the code just tells you how long it took you to answer what i want is a timer that will display and count down

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico
OK, the TIMER runs for 24 hours, giving eleapsed seconds from midnight.
Now, there are 60 seconds in a minute and 60 minutes in an hour.
So, there are 24*60*60 = 86,400 seconds in a day.

If you get the value of seconds that TIMER gives you and subtract it from 86,400 you will get a value that "counts down."

However, if you run this program just before midnight, you will have to make some additional adjustments, because the "day" will wrap around when your counter gets to zero.

Makes sense?

Regards..... Moneo

Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas
Assuming you start after midnight, and that you want a countdown time of less than one day, you can use this to show the countdown, second-by-second:

Code: Select all

``````'Following code shows remaining time, starting with 35 seconds.
CLS
CountDownTime = 35 'seconds, say
T0 = TIMER
T2 = TO + TIMER
DO WHILE TIMER < T2
LOCATE 2, 10
PRINT SPACE\$(40)
PRINT " Remaining Time Is: "; INT(T2 - TIMER)
'execution code goes here
LOOP
``````
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish

rgreenlaw
Newbie
Posts: 9
Joined: Mon Aug 06, 2007 1:20 pm

Alternative countdown timer

You could also use this:

Code: Select all

``````t = 35' 35 seconds
ON TIMER(1) GOSUB tickme
CLS
PRINT
PRINT
PRINT "timer has started"
TIMER ON
k\$ = ""
WHILE t > 0 AND k\$ <> CHR\$(13)

k\$ = INKEY\$
IF k\$ <> CHR\$(13) THEN a\$ = a\$ + k\$: PRINT k\$; : k\$ = ""
IF TIMER = 0 THEN PRINT : PRINT "Your name is "; a\$
IF k\$ = CHR\$(13) THEN PRINT : PRINT "your name is "; a\$
WEND
SYSTEM
tickme:
t = t - 1
r = CSRLIN
c = POS(0)
LOCATE 1, 1
PRINT "Time remaining: "; t
LOCATE r, c
RETURN

``````
This isn't the best because it doesn't allow backspace or filter out undesired characters, but it does give an example of timing the input of data and aborting the input if the timer expires. Depending upon the input need you can change the code to fit most any purpose.
Roger Greenlaw