[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?
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
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.
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!