This is code for adding a line in text files.
Like the other Procedures (GetLine,SetLine,MaxLine) it works only if you open a file with ReadFile(), before you use this command. Maybe some day (if Fred will change OpenFile) it will work with OpenFile. At the end of the procedure the file is reopened with ReadFile().
Code: Select all
; (c) 2001 - Franco's template - absolutely freeware
; Adds a line to a text file
; return value 1 = new line added
; return value 0 = function failed
Procedure AddLine(File,FileName$,Line,String$)
UseFile(File)
LineNumber=1
If Line>1
While LineNumber0
Size=SizeORG-Location
*Buffer=AllocateMemoryBank(1,Size,0)
FileSeek(Location)
ReadData(*Buffer,Size)
CloseFile(0)
If OpenFile(0, FileName$)
UseFile(0)
FileSeek(Location)
WriteStringN(String$)
WriteData(*Buffer,Size)
CloseFile(0)
If ReadFile(0, FileName$) And SizeORG<Lof()
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndIf
Else
ExitAddLineWhile:
ProcedureReturn 0
EndIf
Else
ProcedureReturn 0
EndIf
EndProcedure
Have a nice day...
Franco
(ReadMemory and WriteMemory renamed to ReadData and WriteData)
Edited by - Franco on 06 December 2001 23:14:29