Click to See Complete Forum and Search --> : File line Count


stlai
April 18th, 2001, 08:48 AM
Hi,
I opened a file using
open filename for input as #1

How do i know how many line is in that file?
Does anyone know what API to use to count the number of lines in the file?

Thank you so much in advance.

Sue

shree
April 18th, 2001, 08:58 AM
This is not an efficient method but should work


dim OneLine as string, LineCnt as integer
open filename for input as #1
LineCnt = 0
do until eof(1)
line input #1, OneLine
LineCnt = LineCnt + 1
loop
close #1
msgbox LineCnt

Sharathms
April 18th, 2001, 09:26 AM
Try this. this works much faster.

Dim strFileName as string
strFileName = "c:\temp\resy2000.log"
Dim strHuge as string
Dim LineCnt as Long
Dim ln as Long
Dim strFileContent() as string
Dim iFile as Integer

iFile = FreeFile
Open strFileName for input as #iFile
ln = FileLen(strFileName) 'get the lenth of the file
strHuge = Space(ln) 'Required
strHuge = input(ln, iFile) 'Read all the data into a string
Close #iFile 'close the file
strFileContent = Split(strHuge, vbCrLf)
LineCnt = UBound(strFileContent) ' this will have the number of lines in the file
'strFileContent will have the contents of the file as an array of string.