+ Reply to Thread
Results 1 to 6 of 6

analyzing text file line by line

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    analyzing text file line by line

    Hello,

    I have a txt file, of which I want to get back its lines line by line, and I also need to know, how many lines does it have.

    I have this code:

    Dim fName as Strinmg
    Dim obj
    Dim SingleLine
    Set obj = CreateObject("Scripting.FileSystemObject")
    fName= "c:\data\file.txt"
    SingleLine = obj.OpenTextFile(filename, ForReading).Read(100)
    Set obj = Nothing

    But of course it is not exactly the one I need, I guess, I need to create a while statement, but I cannot find out, how.

    Could anybody help me? All advices would be appreaciated
    Last edited by HarryKlein; 05-16-2011 at 12:32 PM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: analyzing text file line by line

    Please use code tags !

    sub snb()
      open "E:\OF\example.txt" for input as #1
        sq=split(Input(LOF(1),#1),vbcrlf)
      close #1
    
      msbgox "Number of lines: " & ubound(sq)+1
    
      for j=0 to ubound(sq)
    '     ---- inspect each line
      next
    End Sub



  3. #3
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: analyzing text file line by line

    Many thanks

    May I ask a small explanation about this line
    sq=split(Input(LOF(1),#1),vbcrlf) ?

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: analyzing text file line by line

    Please use code Tags !!

    that code :
    reads the complete content of the file
    splits the content using the end of line character
    puts those separate lines into an array sq.

  5. #5
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: analyzing text file line by line

    Quote Originally Posted by snb View Post
    Please use code Tags !!

    that code :
    reads the complete content of the file
    splits the content using the end of line character
    puts those separate lines into an array sq.
    What does the number 1 after
     LOF
    Thanks again.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: analyzing text file line by line

    Use the help function (F1) of your VBEditor (F11)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1