Page 1 of 1

how to get the timer to count down

Posted: Fri Jul 06, 2007 1:14 pm
by Quicky
i can only get the timer to count up

ex.
start! = TIMER
INPUT "what is your name"; answer$
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

Posted: Fri Jul 06, 2007 2:46 pm
by Patz QuickBASIC Creations
What is that code suppossed to do?

Posted: Fri Jul 06, 2007 5:54 pm
by Quicky
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

Posted: Fri Jul 06, 2007 8:54 pm
by moneo
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

Posted: Sat Jul 07, 2007 9:37 am
by Ralph
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
 

Alternative countdown timer

Posted: Mon Aug 06, 2007 6:43 pm
by rgreenlaw
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$ = ""
PRINT "Enter your name? ";
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.