|
-
April 18th, 2001, 08:48 AM
#1
File line Count
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
-
April 18th, 2001, 08:58 AM
#2
Re: File line Count
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
-
April 18th, 2001, 09:26 AM
#3
Re: File line Count
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|