Solved

Extracting fields from a tab delimited text file in VB5

Posted on 1998-10-26
3
306 Views
Last Modified: 2010-04-30
Hi,

I am trying to extract information from a tab delimited text file. For example the info are are organised in the following;

field1 <tab> field2 <tab> field3 <tab> field4
<blank><tab> field2 <tab><blank> <tab> field4

I can programmatically open the file in excel which is going to organise the fields in columns but I am trying to avoid that. So I am looking for a way to extract field1, field2, field3 and field4.

Anyone can help?

Regards
MMAHDI
0
Comment
Question by:mmahdi
3 Comments
 
LVL 2

Accepted Solution

by:
Poddy earned 100 total points
ID: 1441589
open the file using the open for input command
loop through the file:
  read a record in using the line input
  process the string, using instr to detect the field changes
close the file

0
 
LVL 3

Expert Comment

by:traygreen
ID: 1441590
Read through the file one character at a time looking for the tab character.

dim sChar as string
dim sField as string

Do While Not EOF(<filenumber>)
   
   sField = ""
   sChar = Input(1,<filenumber>)

   Do While sChar <> chr(9)   ' 9 = tab
      sField = sField & sChar
      sChar = Input(1,<filenumber>)
   Loop
   
   ' Do Something with sField (ie set variable etc)
   
Loop
0
 
LVL 1

Author Comment

by:mmahdi
ID: 1441591
It worked great! Thanks for your valuable help.

Regards
mmahdi
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question