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

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

how to get the timer to count down

Post by Quicky » Fri Jul 06, 2007 1:14 pm

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

User avatar
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations » Fri Jul 06, 2007 2:46 pm

What is that code suppossed to do?

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

Post by Quicky » Fri Jul 06, 2007 5:54 pm

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

Post by moneo » Fri Jul 06, 2007 8:54 pm

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

Post by Ralph » Sat Jul 07, 2007 9:37 am

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

Post by rgreenlaw » Mon Aug 06, 2007 6:43 pm

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.
Roger Greenlaw

Post Reply