![]() |
Read text file
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 |
Read text file
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 "jacob" wrote in message ... 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 |
Read text file
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 "jacob" wrote in message ... 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 . |
All times are GMT +1. The time now is 12:12 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com