EOF evaluating incorrectly

P

passion_to_be_free

I'm writing a subroutine that will go to a directory, open a csv file,
and parse the data line by line. The macro is set to continue this
process for all csv files in that specific directory.

All is going well, except on one of my csv files, the EOF registers as
true before it reaches the end of the file. I have hardcoded the path
to this specific file for testing purposes. Here is my code:

Sub CSV3()

Dim TextLine As String
Dim headings As Variant
Dim record As Variant
Dim counter
Dim fileNumber As Integer

templateDir = "" 'this does have a purpose...see SetDirectories3 Sub
SetDirectories3

csvFile = "Macintosh HD:Users:tlscprojects:Desktop:CPAS Final
Reports:Data Files:CPAS, F06, ELED 302, Sec 1, ElEd, Welling.csv"

Open csvFile For Input As #1 ' Open file.

Line Input #1, TextLine ' Read line into variable.

headings = Delim(TextLine)
errorLog = Date & vbCr & Time & vbCr & stName 'start the Error Log
Application.ScreenUpdating = False

MsgBox "loc: " & Loc(1)
MsgBox "length: " & LOF(1)
MsgBox EOF(1)

Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine ' Read line into variable.

record = Delim(TextLine)

'these subroutines parse the data
newReporter headings, record
LogInformation (errorLog)
Documents(DocName).Close (wdSaveChanges)
Documents("Final Evaluation Creator2.doc").Activate
errorLog = ""
Loop
Close #1 ' Close file.

End Sub



Now, when I run the sub, I get these dialog windows:
loc: 45
length: 5639
True

If I am at location 45, and the document length is 5639, then why is
EOF evaluating as true? Anyone have any suggestions?
 
T

Tony Jollans

Most likely cause is some non-text data in the file. What is at position 45
in the file which errors?
 
J

Jay Freedman

I think a Ctrl+Z (ASCII 26) in a text file is considered an EOF marker
(at least, that was true in MSDOS and in CPM before that).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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