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
how to get the timer to count down
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
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
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
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
Alternative countdown timer
You could also use this:
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.
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
Roger Greenlaw