Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to put the time and date into your program so that it runs regardless.
#1
I know the general

DO
PRINT TIME$
SLEEP 1
CLS
LOOP

thing but I can't get it to work for some reason.

I'm sure theres a better way of having it do this for me, I just need it to update every second and have the date change over at midnight.
Can anyone give me a solution?
Reply
#2
Try:
Code:
DO
  CLS
  PRINT DATE$; "  "; TIME$
LOOP
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#3
Well that didn't work but I wasn't surprised, I should have specified.
  I also want to add the current up to the second date and time in my program.
  It starts out with a menu that then takes you to two choices whether you want to compute a single year or a range of years, thats off subject though i just cant figure out how to put it in so thats it runs throughout my program updating every second without me having to hit any keys. Can anyone give me a solution?
Reply
#4
Perhaps you can make a Sub to just do the updating, without a DO...LOOP, then, throughout your program, call that sub, from time to time?  Instead of using the CLS command, you can use a two LOCATEs, the first one to erase the previous date and time, the second one to write the new date and time.  Give it a try, then, if you still have a problem, post back, with the code you came up with, and explain your problem. 
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#5
(10-18-2007, 08:29 AM)Ralph link Wrote:if you still have a problem, post back, with the code you came up with, and explain your problem. 

Yes, and take a LOT of time to explain the problem adequately. Just to blurt out a question at the speed of chatroom is worthless and will never get you any help. Spend at least 15 minutes to compose your next question.

From your original question, I would have responded[pre]CLS
LastTime$ = TIME$
DO
LOCATE 10, 30: PRINT DATE$, LastTime$, ""
  WHILE TIME$ = LastTime$: WEND
  LastTime$ = TIME$
LOOP WHILE INKEY$ = ""[/pre]

Mac

Reply
#6
In my menu I put in
       GOSUB TimeandDate
after the input statement in my menu that asks "Would you like to calculate a range of years(1) or a single year(2)?";Q$ but before the part where it says
        IF VAL(Q$) = 1 THEN  GOTO Range
        IF VAL(Q$) = 2 THEN GOTO SingleYear
        IF VAL(Q$) < 1 OR VAL(Q$) > 2 THEN GOTO Menu

TimeandDate:
       LOCATE 1, 1
       PRINT DATE$
       LOCATE 1, 1
       PRINT DATE$
       LOCATE 1, 72
       PRINT TIME$
       LOCATE 1, 72
       PRINT TIME$
       RETURN        
Reply
#7
Well, you still don't explain what your problem is. Did you spend 15 minutes on that question? If so, try 30 minutes.

Making a wild guess WTF you are talking about, I jotted out the program below. Try running it.

Mac

ON TIMER(1) GOSUB UpdateTime

CLS
PRINT "Welcome to fancy program"
TIMER ON
WHILE row = 0: WEND
PRINT : PRINT "Press 'A': ";
WHILE UCASE$(INKEY$) <> "A": WEND
PRINT "You did good!"
PRINT : PRINT "Now press 'B': ";
WHILE UCASE$(INKEY$) <> "B": WEND
CLS
SYSTEM

UpdateTime:
row = CSRLIN
col = POS(1)
LOCATE 1, 60: PRINT DATE$; " "; TIME$
LOCATE row, col
RETURN

Reply
#8
That works but I don't know how to integrate that into my program.'Leapyear Calculator
'Written by: Alex Willett
'October 2007




CLS
Menu:
  CLS
  LOCATE 2, 1
  INPUT "Would you like to compute a range of years(1) or a single year(2)"; Q$
  GOSUB TimeandDate
  IF VAL(Q$) = 1 THEN GOTO Range
  IF VAL(Q$) = 2 THEN GOTO SingleYear
  IF VAL(Q$) < 1 OR VAL(Q$) > 2 THEN GOTO Menu
  ON TIMER(1) GOSUB TimeandDate

Range:
  INPUT "What is the first year"; F$
  INPUT "What is the last year"; L$
  F = VAL(F$)
  L = VAL(L$)
  FOR X = F TO L
  IF X MOD 400 = 0 OR (X MOD 100 = 0 OR X MOD 4 = 0) THEN
  COLOR 7, 0
  PRINT X; "is a leapyear!"
  ELSE
  COLOR 4, 0
  PRINT X; "is not a leapyear."
  END IF
  R = TIMER
  DO
  LOOP WHILE TIMER < R + .1
  NEXT X
  GOSUB PressAny
  GOTO Response


SingleYear:
  CLS
  y = 0
  INPUT "Enter a year"; y
  IF y < 1582 THEN
  M = 1
  END IF
  IF y = 1582 THEN
  M = 1
  END IF
  IF y MOD 4 = 0 THEN
  M = 1
  END IF
  IF y MOD 100 = 0 THEN
  M = 2
  END IF
  IF y MOD 400 = 0 THEN
  M = 1
  END IF
  IF M = 1 THEN
  PRINT y; "is a leap year."
  END IF
  IF M > 1 OR M < 1 THEN
  PRINT y; "is not a leap year."
  END IF
  GOSUB PressAny
  GOTO Response

Response:
  CLS
  INPUT "Would you like to compute another year"; R$
  IF R$ = "Y" OR R$ = "y" THEN GOTO Menu
  IF R$ = "N" OR R$ = "n" THEN GOTO ShutDown

TimeandDate:
  row = CSRLIN
  col = POS(1)
  LOCATE 1, 60: PRINT DATE$; " "; TIME$
  LOCATE row, col
  RETURN


PressAny:
  DO
  I$ = INKEY$
  LOOP WHILE I$ = ""

Shutdown:
  CLS
  END
Reply
#9
I can put a clock in a standalone program, and I can put a clock in my menu but that causes my menu to stop working and this program above did exactly the same thing.
Reply
#10
This is what you need for your "date change over at midnight".

BEWARE OF MIDNIGHT:
It is possible that your program is operating at midnight.

If you are about 1 second before midnight when obtaining the date,
it is possible, based on the speed of your processor, that the DATE$
function will give you the old date (just before midnight), and a
subsequent TIME$ function will give you the time for the new date (just
after midnight). In which case your date and time will be 24 hours off.

The following code will synchronize the date ann time.

'get today's date and time
dt$=DATE$
tm$=TIME$
if left$(tm$,2)="00" then dt$=DATE$

We first get the date and then the time. Then we check if the hour is 00
indicating that it's just past midnight. If so, we get the date again
to make certain that we have the new date corresponding to the new time.

Regards..... Moneo
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)