Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading In Line Feeds Rather Than Carraige Returns

Status
Not open for further replies.

bobbarker

Programmer
Dec 20, 2001
83
0
0
GB
Not sure if this is the best forum for this but here goes...

I have a VB app that processes a CSV file, using LINE INPUT to read each line into a string.

From what I have read LINE INPUT relies on the lines being seperated by Carraige Returns.

For a (currently) unknown reason it appears the CSV files being read in (from another third party app) has started seperating the lines by line feeds in places, and thus not being split correctly using LINE INPUT (I have tested this by using InStr(inputstring, CHR(13) returning 0 and through another util).

The other third party developer is lost as to why this is happening. Their development environment is Mac which I believe only outputs carraige returns, not line feeds.

-Does anyone have any suggestions what may be happening here? E.g. when the file is being downlaoded from the FTP site to a windows environment may the characters get 'reformatted' somehow?
-Should I need to change my code what are my options? Anything else apart from replace all chr(10) with chr(13)?
Cheers
Bob
 
whenever I have to deal with reading files I first examine
the file with Debug.
And what you see there is what you get.
From there you can judge if LINE INPUT is working correctly.
 
Try

vbCr or vbNewLine to split the lines. You can also split the lines and load an array using

Dim arr() as String

arr = Split(fileContents,vbCr)

or

arr = Split(fileContents,vbNewLine)

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
Here is what I used to read a line at a time.
You will need to have the Micrsoft Scripting Runtime installed as a component.

Code
Open filename For Output As #10 'Open the file
Set ts = fso_OpenTextFile(InputFolder & Fname) 'Open File for Output
Do While ts.AtEndOfStream <> True
strData = ts.Read(1) 'Put file into strData
Print #10, strData; ' Print a line the data
Loop 'Loop it!!
Close #10 'Close the Port File
ts.Close 'Close the FSO file

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top