Extracting fields from a tab delimited text file in VB5

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
LVL 1
mmahdiAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
PoddyConnect With a Mentor Commented:
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
 
traygreenCommented:
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
 
mmahdiAuthor Commented:
It worked great! Thanks for your valuable help.

Regards
mmahdi
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.