MaxLine 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

MaxLine 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
; MaxLine() works with text files
; Returns the number of lines in a text file
; Example: MaxNumberOfLines = MaxLine()

Procedure MaxLine(File)
  EndPos=Lof(File)
  FileSeek(File, 0)
  NewPos=0
  LineNumber=0
  While  NewPos<=EndPos
    ReadString(File)
    LineNumber=LineNumber+1
    NewPos=Loc(File)
    If NewPos=Lof(File)
      Goto ExitMaxLineWhile
    EndIf
  Wend
  ExitMaxLineWhile:
  FileSeek(File, NowPos)
  ProcedureReturn LineNumber
EndProcedure

Have a nice day...
Franco