Code archives/User Libs/delete Me

This code has been declared by its author to be Public Domain code.

Download source code

delete Me by asdfasdf2004
This small file will write a .log file when you call it.
ex.
Include "LogFile.bb"
LogFile=createLog("C:\Log.log")

WriteLog(LogFile,"Hello")

EraseLog(LogFile)

WriteLog(LogFile,"Hello Again")

CloseLog(LogFile)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;LogFile.bb
;Contains Functions to write .log files
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Function CreateLog(St$)

file = WriteFile(St$)

Return file

End Function

Function WriteLog(LG$,St$)

SeekFile(LG$,FileSize(LG$))

WriteLine(LG$,St$)

End Function

Function EraseLog(LG$)

SeekFile(LG$,0)

WriteLine(LG$,"")

End Function

Function CloseLog(LG$)

CloseFile(LG$)

LG$ = 0

End Function

Comments

soja2004
May I suggest some improvements?

1) It can all be done in one function with FileType.
2) Eof doesn't seem to work (maybe it's a BlitzPlus thing)
3) Adding the default parameter f$ makes it so you don't have to worry about variable scope issues and yet leaves the filename flexible (and you can have more than one).

Include this function:
Function WriteLog(s$, f$="log.txt")
	If FileType(f) Then
		file = OpenFile(f)
		SeekFile(file, FileSize(f))
	Else
		file = WriteFile(f)
	EndIf
	WriteLine(file, s)
	CloseFile(file)
End Function

Example:
WriteLog("Logging in file log.txt...")
WriteLog("Logging to log2.txt...", "log2.txt")
WriteLog("Logging to default log again...")

...Produces log.txt:
Logging in file log.txt...
Logging to default log again...

...and log2.txt:
Logging to log2.txt...


<edit> PS: This archive would probabyl be more at home under "File Utilities" or something, since it doesn't have much todo with userlibs.


Code Archives Forum