Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

EOF evaluating incorrectly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
passion_to_be_free@hotmail.com - 15 Sep 2006 16:41 GMT
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?
Tony Jollans - 15 Sep 2006 19:40 GMT
Most likely cause is some non-text data in the file. What is at position 45
in the file which errors?

--
Enjoy,
Tony

> 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
[quoted text clipped - 53 lines]
> If I am at location 45, and the document length is 5639, then why is
> EOF evaluating as true? Anyone have any suggestions?
Jay Freedman - 16 Sep 2006 01:56 GMT
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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>Most likely cause is some non-text data in the file. What is at position 45
>in the file which errors?
[quoted text clipped - 60 lines]
>> If I am at location 45, and the document length is 5639, then why is
>> EOF evaluating as true? Anyone have any suggestions?
John Nurick - 16 Sep 2006 07:05 GMT
IIRC in Unix (and hence perhaps OS X) it's Ctrl-D.

>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).

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.