Ooops
October 28, 2020, 06:42:42 AM

Author Topic: [bb] delete Me by asdfasdf [ 1+ years ago ]  (Read 1180 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] delete Me by asdfasdf [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : delete Me
Author : asdfasdf
Posted : 1+ years ago

Description : This small file will write a .log file when you call it.
ex.
Code: [Select]
Include "LogFile.bb"
LogFile=createLog("C:Log.log")

WriteLog(LogFile,"Hello")

EraseLog(LogFile)

WriteLog(LogFile,"Hello Again")

CloseLog(LogFile)


Code :
Code: BlitzBasic
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;LogFile.bb
  4. ;Contains Functions to write .log files
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. Function CreateLog(St$)
  9.  
  10. file = WriteFile(St$)
  11.  
  12. Return file
  13.  
  14. End Function
  15.  
  16. Function WriteLog(LG$,St$)
  17.  
  18. SeekFile(LG$,FileSize(LG$))
  19.  
  20. WriteLine(LG$,St$)
  21.  
  22. End Function
  23.  
  24. Function EraseLog(LG$)
  25.  
  26. SeekFile(LG$,0)
  27.  
  28. WriteLine(LG$,"")
  29.  
  30. End Function
  31.  
  32. Function CloseLog(LG$)
  33.  
  34. CloseFile(LG$)
  35.  
  36. LG$ = 0
  37.  
  38. End Function


Comments :


soja(Posted 1+ years ago)

 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:
Code: [Select]
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:
Code: [Select]
WriteLog("Logging in file log.txt...")
WriteLog("Logging to log2.txt...", "log2.txt")
WriteLog("Logging to default log again...")
...Produces log.txt:<div class="quote"> Logging in file log.txt...Logging to default log again... </div>...and log2.txt:<div class="quote"> Logging to log2.txt... </div><edit> PS: This archive would probabyl be more at home under "File Utilities" or something, since it doesn't have much todo with userlibs. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal