Page 1 of 1

Help with making a log file!!

Posted: Thu Apr 27, 2006 8:27 pm
by KijanaKiume
I am making a progam that in it i ask the user for the date and an explanation.
I want to add that info the end of a file each time it is entered(Like a log file.). The only problem is that i want to go to the end of the file each time i need to enter the data. I think i need to use the function EOF. HELP!!!

Posted: Thu Apr 27, 2006 8:48 pm
by MystikShadows
hi KijanaKiume,

A typical log file is usually plain text.

If you want to be sure that everything you add gets added at the end of the file, you just need to open it like this:

OPEN "FileName.ext" FOR APPEND AS #1

For append will make sure that all PRINT or WRITE statements write at the end of the file.

Hope this helps.

using APPEND

Posted: Mon May 01, 2006 11:30 am
by Zim
Mystic Shadows is correct!

Also, please note that even if the file does not already exist, opening a file with APPEND will simply create the file! So, you do not need to worry about whether the file already exists. If it doesn't, APPEND works just like OUTPUT.

Posted: Tue May 02, 2006 4:55 pm
by Patz QuickBASIC Creations
Try this.

Code: Select all

' Quick LOG generator
Print "Type in EOF at the end of your explanation."
A = FREEFILE
OPEN "Filename.log" FOR APPEND AS #A
Print #A, "System date: "+DATE$
Print #A, "System time: "+TIME$
WHILE NOT INSTR(LCASE$(Explan$), "eof")
INPUT Explan$
Print #A, Explan$
WEND
CLOSE #A
From what you said this should do what you asked plus some.

(I am generalizing but most English words do not contain EOF in them.)
(Note: This is just quick code from memory. It may need a few tweaks. :wink: )[/quote]

Posted: Tue May 02, 2006 7:03 pm
by moneo
KijanaKiume wrote:I am making a progam that in it i ask the user for the date and an explanation.
I want to add that info the end of a file each time it is entered(Like a log file.).....
If you are asking the user for the date and an explanation, then it's not really a log file, but an accumulation or record of whatever the user enters.
Even if you asked the user for the time as well, you would have to validate the date and time, and also make sure that this date/time was never entered before. All this validation process is quite tedious.

If it is truly a log file, then the program must put the time and date onto every record. I suggest that the program put in the date/time appended with the "explanation" entered by the user. All that follows assumes a true log file.

Here's a little tutorial of mine about Date and Time:

Code: Select all

DATE$
A function which returns a 10 character string of mm-dd-yyyy,
where mm is the month (01-12), dd is the day (01-31),
and yyyy is the year (1980-2099).

TIME$
A function which returns an eight character string of hh:mm:ss,
where hh is the hour (00-23), mm is minutes (00-59),
and ss is seconds (00-59).

BEWARE OF MIDNIGHT (DATE$, TIME$):
It's possible that your program is operating just at midnight.

If you are 1 second before midnight when obtaining the date, you should decide whether you want your program to use yesterday's old date or today's new date. The following code assumes you want to use the new date:
'get today's date
z$=DATE$
if left$(TIME$,2)="00" then z$=DATE$  'make sure date didn't just roll over
tyyyy$=right$(z$,4)
tmm$  =left$(z$,2)
tdd$  =mid$(z$,4,2)

We first get the date. 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.
When you're all through getting the date and time, you should build a date/time key with the following format:
YYYYMMDDHHMMSS
If you want to put some delimeters within the fields, that's ok too. In a previous example, the date, time and explanation were put into 3 separate records. This is not the way to create a log record.

You should have one and ony one log record for each explanation or event. So build your log record as follows:
YYYYMMDDHHMMSS followed by the explanation.....

This format will enable you to later be able to a search (using whatever you want including Notepad) on the log file to identify all the events (explanations) which occurred on a particular day.

Do you agree?
*****

Posted: Fri May 05, 2006 4:30 pm
by Patz QuickBASIC Creations
I had not thought about that...

Moneo, you always have the best bug-fixes. People can sure learn alot from you...

Posted: Sat May 06, 2006 8:19 pm
by moneo
Thanks, Patz, we aim to please......
*****