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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading comma delimited file

Status
Not open for further replies.

dejfatman

Programmer
Jan 24, 2002
34
0
0
US
I am reading a *.csv file into my program, but when the program finishes grabbing each field from the first row, it returns an EOF condition. Here is a snippet:

i = 1
while i <= lastRecord And Not exportError
Input #nFile(1), strRecord
If EOF(nFile(1)) Then
MsgBox "EOF on " & i & " read."
exportError = True
Else
Put #nFile(0), i, formatByte(strRecord)
end if
i = i + 1
Wend

After writing out the 124th field, I get the "EOF on 124 read." There are 124 delimited fields on the first row, and there are 38 rows total with approximately the same number of fields on each row. How do I keep reading through each row?
 
Is the CSV file one from DOS, or UNIX/Mac?
Could there be an invalid character at the end of the first row?
Open the source file in a text editor and look to ensure that the last record is followed by a CR/LF combination/
(10/13 or OA/OD in hex)

If not, you will either have to read it a different way, or convert it to DOS format first.

And don't forget to TRIPLE check that the file you are processing is the one you thought you were processing.
Is there a one-row test file lying around somewhere that you forgot about?

 
How is strRecord declared? You might try to simplify the code...


Code:
i = 1
Do While Not EOF(nFile(1)) 
   Input #nFile(1), strRecord
   Put #nFile(0), i, formatByte(strRecord)
   i = i + 1
Loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top