Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Line counting of a text file


Reply
 
Thread Tools Display Modes
  #1  
Old 09-01-2002, 04:21 AM
jindivikk2
Guest
 
Posts: n/a
Default Line counting of a text file


could anyone show me how to do a line counting of a text file.

see how many total lines are there in a file.

thanks.
jin - newbie
Reply With Quote
  #2  
Old 09-01-2002, 05:14 AM
Pookie's Avatar
Pookie Pookie is offline
Gaming God

Retired Leader
* Expert *
 
Join Date: Feb 2002
Location: Brisbane, Australia
Posts: 2,363
Default

Here is one way.
Code:
Function CountLines(strFilename as string) as long dim FF as long Dim strTest as String FF = freefile CountLines = 0 open strFilename for input as #FF do until EOF(FF) line input #FF, strTest CountLines = CountLines +1 Loop close #ff
To call:
Code:
AmountOfLines=CountLines("C:\myfile.txt")
__________________
. <--- Photo of me viewed from the Hubble telescope
Reply With Quote
  #3  
Old 09-02-2002, 06:38 AM
MacBeth
Guest
 
Posts: n/a
Default

Another way is to use the File Scripting object. Referece in your project then

Code:
Function CountLines(strFilename As String) As Long Dim fso As FileSystemObject set fso = new FileSystemObject With fso.OpenTextFile(strFilename , ForReading, False) Do While Not .AtEndOfStream .ReadLine CountLines= CountLines+ 1 Loop end with set fso = nothing end function
dunno if that's any more efficient than opening the file the other way.
Reply With Quote
  #4  
Old 09-04-2002, 07:24 PM
jindivikk2
Guest
 
Posts: n/a
Default

thanks guys...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->