function to find number of lines in .txt file


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: function to find number of lines in .txt file

  1. #1
    Join Date
    Dec 2006
    Posts
    23

    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

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jan 2007
    Posts
    22
    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 )

  4. #4
    Join Date
    Dec 2006
    Posts
    23
    amrelsaqqa,
    thank you!
    that worked great!

Similar Threads

  1. Replies: 18
    Last Post: 12-13-2006, 02:49 PM
  2. Packed Data(Comp-3, etc)
    By Marcos in forum VB Classic
    Replies: 3
    Last Post: 01-25-2006, 11:18 AM
  3. Replies: 8
    Last Post: 03-08-2003, 06:25 PM
  4. calling ping thru vb
    By Michael Shutt in forum VB Classic
    Replies: 6
    Last Post: 04-05-2001, 02:25 AM
  5. I am helpless - Edit Info form
    By Dan in forum VB Classic
    Replies: 0
    Last Post: 03-17-2000, 05:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center