Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to count number of lines in text file?,
Message
 
 
À
10/11/2000 08:36:32
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00440122
Message ID:
00440353
Vues:
11
>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

Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform