Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to count number of lines in text file?,
Message
From
10/11/2000 14:08:13
 
 
To
10/11/2000 08:36:32
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00440122
Message ID:
00440353
Views:
14
>Hi,
> Any functions to count number of lines in text file instead of counting the number of carriage return ?
>
>Thank you
' ==================================================
' This is a very quick mod of some code I have to you 
' what you want.  remove unused vars and such.
' set ref to microsoft scripting runtime
Public Function CountLines(strSourceFile As String) As Long
    Dim fso As New FileSystemObject, txtfile, filSource As File, strAll As String, _
        filTarget As File, ts As TextStream, strRec As String
    Dim aCoords As Variant ' holds the coordinates
    CountLines = 0
          
    Set filSource = fso.GetFile(strSourceFile)      ' assign file
    Set ts = filSource.OpenAsTextStream(ForReading) ' Read the contents of the file.
    
    While Not ts.AtEndOfStream                      ' Start loop
        CountLines = CountLines + 1
    Wend
    
    ts.Close ' Cleanup
    
End Function
~Joe Johnston USA

"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams

Previous
Reply
Map
View

Click here to load this message in the networking platform