GetLine 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

GetLine 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
; GetLine() works with text files
; Returns the actual line position in a text file
; Example: LineNumber = Getline() 
; Returns the actual LINE position in a text file NOT the file pointer position

Procedure GetLine(File)
  NowPos=Loc(File)
  FileSeek(File, 0)
  NewPos=0
  LineNumber=0
  While  NewPos<=NowPos
    ReadString(File)
    LineNumber=LineNumber+1
    NewPos=Loc(File)
    If NewPos=Lof(File)
      Break
    EndIf
  Wend
  FileSeek(File, NowPos)
  ProcedureReturn LineNumber
EndProcedure

Have a nice day...
Franco