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!!!
Help with making a log file!!
-
- Veteran
- Posts: 703
- Joined: Sun Nov 14, 2004 7:36 am
- Contact:
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.
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.
When God created light, so too was born, the first Shadow!
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
using APPEND
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.
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.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
--- Time flies like an arrow, but fruit flies like a banana ---
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
Try this.
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. )[/quote]
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
(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. )[/quote]
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.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.).....
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.
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?
*****
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact: