SetLine procedure for Textfiles

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

SetLine procedure for Textfiles

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by Franco.

Code: Select all

; (c) 2001 - Franco's template - absolutely freeware
; SetLine(Line) works with text files
; Returns the pointer position for this line
; If you set a line number higher than there is available you get 0
; Example: Line30StartsAt = Setline(30) 
; Returns the pointer position for line # 30 and will set this position

Procedure SetLine(File, Line)
  LineNumber=1
  If Line>1
    While  LineNumber<Line
      ReadString(File)
      LineNumber=LineNumber+1
      NewPos=Loc(File)
      If NewPos=Lof(File)
        FileSeek(File, 0)
        Goto ExitSetLineWhile
      EndIf
    Wend
    ExitSetLineWhile:
  Else
    FileSeek(File, 0)
  EndIf
  ProcedureReturn Loc(File)
EndProcedure
Have a nice day...
Franco


Edited by - franco on 09 October 2001 18:50:05