function to find number of lines in .txt file
hello,
I have a file C:\test\test.txt that I'd like to, using a Function where you pass in the Directory and Filename that you want to utilize, in this case C:\test and test.txt, calculate the number of lines in the text file and return that value from the Function.
Could someone share with me the code that would do this?
ex. if test.txt looked like
lskdjflskjf
lksdflksdj
slkdjf
lksjdf
the Function would return the value 4.
thanks in advance,
david
[520 byte] By [
dgr7] at [2007-11-11 10:16:54]

# 2 Re: function to find number of lines in .txt file
Hello dgr7 ,
This code can help you :
code for counting lines of win.ini file :
Private Function LineCount(FileName As String) As Long
Open FileName For Input As #1
Do While Not EOF(1)
I = I + 1
Line Input #1, D
Loop
Close #1
LineCount = I
End Function
Private Sub Command1_Click()
MsgBox LineCount(Environ$("WinDir") & "\Win.INI")
End Sub
please note if u use : option explicit , u must define all variables e.g. ( Dim I as Long )