time in qb

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

User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

You can get it to work as long as your loop runs in =< 1 second of time, otherwise it can skip a second every now and then.
Image
lostoros
Newbie
Posts: 5
Joined: Fri Sep 30, 2005 10:46 am

Post by lostoros »

OK, i have the loop now and it looks something like this

Code: Select all

t! = timer +1
timerem = timestart     

'timestart is 300 in this case 5 minutes, set in another spot

DO
 If timer = T! then
  t! = timer +1
  timerem = timerem -1
  minuterem = timerem/60
  secrem = int(timestart-(minuterem*60)
  print fix(minuterem);
  print ":";
  print 60- secrem
 end if
loop
but it has some issues...
1. When it gets to single digits in seconds remaining 4:09 for isntance. how do I get it to display "4:09" instead of "4: 9"? i've tried some simple work arounds that have failed..any ideas?

2. When it gets past 4 minutes even, the minutes change to 3, but the seonds go down past 0, instead of going back to 59. i get 3:-1, etc. how do i fix this, once again i've tried some simple stuff but its failed

other then that its been good though...
Seb McClouth

Post by Seb McClouth »

In order to show "xx:xx" you'll need to add some stuff:

Code: Select all

if len(ltrim$(rtrim$(str$(secrem)))) < 2 then
  print "0"+ltrim$(rtrim$(str$(secrem)))
else
  print secrem
end if
I hope this works for ya!

grtz
Seb
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

lostoros,

Your conversion of seconds to MM:SS is not working. I'm going to insert into your code part of the conversion logic which I previously posted.

Code: Select all

t! = timer +1
timerem = timestart     

'timestart is 300 in this case 5 minutes, set in another spot
'***NOTE: The following will only work if minutes is less than 60,
' that is, if timestart is less than 3600.

DO
 If timer = T! then
  t! = timer +1
  timerem = timerem -1
  rem ... minuterem = timerem/60
  rem ...secrem = int(timestart-(minuterem*60)
  ISEC=timerem
  IF ISEC >= 60 THEN 
      MM = INT(ISEC/60) 
      ISEC=ISEC-MM*60 
  ELSE 
     MM = 0 
  END IF 
  SS = ISEC 
  print right$("00"+ltrim$(str$(MM)),2);":";
  print right$("00"+ltrim$(str$(SS)),2)
 end if
loop
This should solve all your "issues".
*****
Post Reply