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:
Example:
...Produces log.txt:
...and 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.
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...
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.