Re: Read an Input File

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Argusy wrote:
Mike wrote:
Hi,
I'm using the code below to read a CSV file (a copy of Excel file) into an Array
Open (filename.csv) For Input As 1
Count = 0
Do Until EOF(1)
Line Input #1, recorddata
myRecord(Count) = recorddata
Count = Count + 1
Loop
Close #1
But the problem is that one of the Cells in one row of my csv file contains a Carriage return character so when it comes to that cell it thinks that is the end of line and it breaks my one line to 2 lines. How can I fix that!?



try setting a buffer to take the whole file, import the file, then use the split function to populate an array, using vbCrLf.

I think that will work.

Argusy

It won't as you'll be parsing the file the same way as Line Input does.
If possible, you should encode the carriage return so it doesn't break a line.
Another suggestion: if the file you'll reading is in fact a CSV-file (a comma separated values file), you can use Input instead of Line Input.
The only thing you need to know is how many values there are for each record.

Sinna

.



Relevant Pages

  • Re: Read an Input File
    ... I'm using the code below to read a CSV file into an Array ... Line Input #1, recorddata ... But the problem is that one of the Cells in one row of my csv file contains a Carriage return character so when it comes to that cell it thinks that is the end of line and it breaks my one line to 2 lines. ...
    (microsoft.public.vb.general.discussion)
  • Re: Trying to build a page that will read a csv file...
    ... > I can't figure out how to get the results to display in a multi-column ... >> Use fileto load the csv file into an array. ... >> Use a loop to iterate through every element in the array, ...
    (php.general)
  • Re: Trying to build a page that will read a csv file...
    ... cough cough ) I decided it was ... I've even managed to get php to display the database ... > Use fileto load the csv file into an array. ... > Use a loop to iterate through every element in the array, ...
    (php.general)
  • Re: Load a string of CSV from memory into a dataset
    ... you should avoid writing to the disk as ... - which after decryption and just before writing to the CSV ... Then run a foreach on the resulting array and split each line (array ... the csv file is being loaded into a datatable, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: CSV to access in ASP... making my head spin
    ... user would like to be able to upload a CSV file, ... putting the CSV in an array to save the information ... Please reply to the newsgroup. ...
    (microsoft.public.scripting.vbscript)