Link to home
Start Free TrialLog in
Avatar of Dayus
Dayus

asked on

Files Reading Question!

Is there a Function that return the number of line in a file or i have to make it make it myself?
Avatar of Dayus
Dayus

ASKER

a txt File !
ASKER CERTIFIED SOLUTION
Avatar of hj2k3
hj2k3

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could use FileLen function to get the size of the file in bytes.  but if you want number of lines, then write your own function similar to ....

Private Function NumOfLines(FileName as String) as Long
    Dim strLine as String

    NumOfLines = 0
    If (Dir(FileName) = "") then Exit Sub

    Open FileName For Input as #1
        Do
           Line Input #1, strLine
           NumOfLines = NumOfLines + 1
        Loop While (Not EOF(1))
    Close #1

End Function

Good Luck!
Avatar of Dayus

ASKER

both great answer the first get the point...
oooooo... that was pretty close! credit to supunr, though, neat answer.
Open inputfile For Input As #2
        While Not EOF(2)
            Line Input #2, linebuffer
            linecount = linecount + 1
        Wend
 Close #2
Linecount contains number of lines.