Results 1 to 4 of 4

Thread: [RESOLVED] Open and Process Tab Delimited Text File

  1. #1

    Thread Starter
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    Resolved [RESOLVED] Open and Process Tab Delimited Text File

    This may be a simple matter, but I'm rather stumped.

    I have a tab delimited text file from which I want to extract only two 'columns'

    The rest I don't care about.

    How do I do this? I've looked at using the File System Object, but it seems to be lacking a method for handling tab delimiting.

    Help?

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Open and Process Tab Delimited Text File

    Whether you use the FSO or the old-school file processing methods, the idea is that you need to read one record, or line, from the file at a time, and break it up, or parse it, by the tab delimiter. The easiest way to do that is with the Split function. Here's an example using the old-school file processing methods:
    Code:
    Dim strInputRec        As String
    Dim astrInputFields() As String
    
    Open "C:\SomeDir\MyFile.txt" For Input As #1
    Do Until EOF(1)
        Line Input #1, strInputRec
        astrInputFields = Split(strInputRec, vbTab)
        ' you can now process the fields.
        ' astrInputFields(0) will be the first field, (1) will be the second, etc.
    Loop
    Close #1
    "It's cold gin time again ..."

    Check out my website here.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Open and Process Tab Delimited Text File

    Once you have a line from the file (or even the whole file), you can do somthing like

    Code:
    Dim strParts() As String
    
    strParts = Split(MyData, vbTab)
    strParts(0) will then contain the first piece of data, strParts(1) the 2nd, etc.

  4. #4

    Thread Starter
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    Re: Open and Process Tab Delimited Text File

    Believe it or not, I figured it out and wrote almost identical code to what you did. It's been so long since I used an "Open x For Input" statement I had to look it all up!

    Thanks so much for your reply. I appreciate it!

Posting Permissions

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



Click Here to Expand Forum to Full Width