igfp
asked on
count number of lines in a file
hi everyone, is it possible to count the number of lines in a file?
I'm using:
Dim strTemp As String * 1
Dim i As Integer
i = 0
Open App.Path & "\aras.pol" For Input As 1#
Do Until EOF(1)
i% = i% + 1
Line Input #1, strTemp
Loop
Close #1
msgbox "number of lines: " & i
this works but is there another way?
I'm using:
Dim strTemp As String * 1
Dim i As Integer
i = 0
Open App.Path & "\aras.pol" For Input As 1#
Do Until EOF(1)
i% = i% + 1
Line Input #1, strTemp
Loop
Close #1
msgbox "number of lines: " & i
this works but is there another way?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Similar to stefri and yours, you can read the entire file in one shot, then "count" the number of newline characters.
dim strTemp as strnig
dim strLinesSplit() as string
dim iNumLines as integer
' read the entire file
Open App.Path & "\aras.pol" For Input As 1#
strTemp = input$(lof(1), #1)
Close #1
' count the number of newlines, then add one for the last line
strLinesSplit = Split(strTemp, vbNewLine)
iNumLines = UBound(linesSplit) - 1
--
The key here is the Input$ and the Split functions.
dim strTemp as strnig
dim strLinesSplit() as string
dim iNumLines as integer
' read the entire file
Open App.Path & "\aras.pol" For Input As 1#
strTemp = input$(lof(1), #1)
Close #1
' count the number of newlines, then add one for the last line
strLinesSplit = Split(strTemp, vbNewLine)
iNumLines = UBound(linesSplit) - 1
--
The key here is the Input$ and the Split functions.
ASKER
my question now is, since i like mine the best, wich one takes the points????
>is there another way
Since this Q was answered in the first comment (stefri), I think you should accept that as your answer.
Since this Q was answered in the first comment (stefri), I think you should accept that as your answer.
ASKER
as you wish! ;) Thank you both!
ASKER