Alternative to ...For Input As #1

G

Guest

I need to open FileA, read through it line by line, parse the data, and
output line by line to FileB. (Both text files)

I'd usually use

Open FileA For Input As #1
Open FileB For Output As #2
Do While Not EOF(1)
Input #1, F1, F2, F3
...various code...
Print #2, F4, F5, F6
Loop
Close #1
Close #2

This works fine with csv files. However, one of the files I need to parse
is + delimeted. Example:

11+6146348+DOC+997+NEW+20041011+124155+REPRINT+

Is there a simple alternative to the above that will work with +? Or will I
have to use

Line Input #1, textLine

and write code to chop up textLine each loop. The fields in FileA are
variable lengths, and the records are longer than the example shown above.
Any suggestions that will save me a lot of time?

Many TIA,

Red.
 
T

Tom Ogilvy

If you have Excel 2000 or later, you can use the split command to "chop up"
the textline

varr = Split(Textline,"+")

for i = lbound(Varr) to ubound(varr)

Next i

Also look at the join function (it is the reverse of Split). You can built
an output array and then use join to convert it to a delimited string (as
long as your string elements don't contain the delimiter ).
 
G

Guest

Tom Ogilvy said:
If you have Excel 2000 or later, you can use the split command to "chop up"
the textline
Perfect.

Also look at the join function (it is the reverse of Split).

Thanks Tom! You've saved me a lot of coding!

Red.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top