Read text file

J

jacob

Hi,
I'm reading a text file originating from Unix using the
Line Input #Filenumber statement. This goes haywire due
to the fact that each line in the file is terminated with
Chr(10), i.e. linefeed, only. Excel then reads the whole
file into one string as Chr(13) is missing. Anybody know
how to deal with this?
Any help appreciated.

jacob
 
S

shockley

You could do something as below using the Input Funciton (not to be confused
with the Input Statement) to read the characters individually and when you
get to a LineFeed, tack on a Carriage Return before it. This procedure
replaces the old file with a new one that has the Carriage Returns inserted.

Sub Tester02()

Open sFile For Input As #1
Do While Not EOF(1)
sChar = Input(1, #1)
If sChar = vbLf Then sChar = vbCr & sChar
sString = sString & sChar
Loop
Close #1

Open sFile For Output As #1
Print #1, sString
Close #1

End Sub

HTH,
Shockley
 
J

jacob

Hi,
Thx, this should work.
-----Original Message-----
You could do something as below using the Input Funciton (not to be confused
with the Input Statement) to read the characters individually and when you
get to a LineFeed, tack on a Carriage Return before it. This procedure
replaces the old file with a new one that has the Carriage Returns inserted.

Sub Tester02()

Open sFile For Input As #1
Do While Not EOF(1)
sChar = Input(1, #1)
If sChar = vbLf Then sChar = vbCr & sChar
sString = sString & sChar
Loop
Close #1

Open sFile For Output As #1
Print #1, sString
Close #1

End Sub

HTH,
Shockley





.
 

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