• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 134
  • Last Modified:

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?
0
Dayus
Asked:
Dayus
1 Solution
 
DayusAuthor Commented:
a txt File !
0
 
hj2k3Commented:
i'm not aware of a function that will do this for you, but you could write one fairly simply:

dim fileText as string
dim i as long
dim fLen as long
dim nLines as long

open "whatever.txt" for input as #1
input #1, fileText
close #1
'the whole file is now in fileText

fLen = len(filetext)
i = inStr(1, fileText, vbcrlf)   'find the first end of line

do until i = 0
nLines = nLines + 1
i = inStr(i+1, fileText, vbcrlf)
loop


now nLines contains the number of lines in the file

hope this helps
0
 
supunrCommented:
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!
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
DayusAuthor Commented:
both great answer the first get the point...
0
 
hj2k3Commented:
oooooo... that was pretty close! credit to supunr, though, neat answer.
0
 
my_vickuCommented:
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.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now