Solved

EOF on input file

Posted on 1998-09-04
10
446 Views
Last Modified: 2010-04-30
Reading a comma delimited file and "Do While Not EOF" is not working as I would expect.  The following pgm gets an error 62 "input past end of file".  In order to get this to work, I had to put some dummy records at the end of the input file, test for the dummy values, then exit.


 Private Sub Command1_Click()
Dim UID         As String
Dim LASTN       As String
Dim FIRSTN      As String
Dim MI          As String
Dim MAIL        As String
Dim Phone       As String

Open "c:\mydocs\mystuff\user" For Input As #1

Do While Not EOF(1)
    Input #1, UID, LASTN, FIRSTN, MI, MAIL, Phone
    Debug.Print UID, LASTN, FIRSTN, MI, MAIL, Phone
    ' process record work
Loop

exit_close:
    Close #1
   
End Sub
0
Comment
Question by:jalymo
10 Comments
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
Are you sure you have a mulitple of six entries in you file?

Because you are inputing six entries at a time, if you get to a point where there is only five left (ie someone didn't enter a phone number), you will get an error.
0
 
LVL 1

Expert Comment

by:hozempa
Comment Utility
jalymo,
ClifABB touches on an interesting point regarding the Line# Statement.  If all of the records(lines) in the source file do not contain exactly six variables separated by a comma, then Line# statement will produce errors (ie, begin reading the next line if the previous did not contain six variable or try to read past the EOF).  You may want to use the Line Input statement to read each line in at a time and then parse the line which is returned as a string using InStr and Mid.  It's a little more work but is usually worth it unless you can guarantee that each line will contain six entries.

good luck, hozempa
0
 
LVL 3

Accepted Solution

by:
SPECIALIST earned 20 total points
Comment Utility
I'm a little unclear, but you can add  On error resume next  
to the beginning of the file.  This will get rid of your error message.  just make sure the program is working the way you want and you are in business.


specialist

0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
SPECIALIST:
I disagree with your "answer".  This amounts to sweeping the problem under the rug.  You can always hide an error by using an "On Error Resume Next" but this doesn't fix the error.

jalymo:
I would suggest the following:
Make sure your file has records in multiples of six as this is most likely the problem.
To verify, break up your test input statement and watch the values:

Do
  If EOF(1) Then Exit Do
  Input #1, UID
  Debug.Print "UID = "; UID
  If EOF(1) Then Exit Do
  Input #1, LASTN
  Debug.Print "LASTN = ";LASTN
  If EOF(1) Then Exit Do
  Input #1, FIRSTN
  Debug.Print "FIRSTN = "; FIRSTN
  If EOF(1) Then Exit Do
  Input #1, MI
  Debug.Print "MI = "; MI
  If EOF(1) Then Exit Do
  Input #1, MAIL
  Debug.Print "MAIL = "; MAIL
  If EOF(1) Then Exit Do
  Input #1, Phone
  Debug.Print "Phone = "; Phone
Loop
Running the above test will let you know if you are missing data and will indicate where to look for it.

I can see the problem probably arises when you are writing data to the file where if, say, the MI is missing you skip writing to the file.  If there is any data missing, you must still at least write an empty string.
0
 

Author Comment

by:jalymo
Comment Utility
My test file contains 3 records, all containing the six values and it bombs with the EOF error.  The file is as follows:

LJ1,JONES,LATOYA,R,EI-20,2025877324
WHG,HOLMES,WAYNE,L,EI-53,2024351291
TWW,WILLIAMS,TIMOTHY,H,EI-42,2025874631

 
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:clifABB
Comment Utility
I have some bad news for you.

Using your original code (cut & paste from above), and using your test file, I end up with no errors.

Did you cut & paste the contents of your test file?  Or did you just re type it in here?
0
 

Author Comment

by:jalymo
Comment Utility
I cut and pasted into a new file and it also worked for me!!  My original file was transferred from our mainframe and I now believe that the end of file marker was removed/lost/deleted.

Given the above responses, I vote to give the points to clifABB.

Thanks to all.
0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
"I vote to give the points to clifABB"
I appreciate the gesture, unfortunately you gave the points to specialist.  This occasionally happens, so don't worry about it.

Thanks anyway.  :)
0
 

Author Comment

by:jalymo
Comment Utility
clifABB: I am new to Experts Exchange and now realize I should examine the options more closely to get the points to the right person.
0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
I figured as much.  :)
This is why I said not to worry about it.  I'm sure you'll get the hang of it.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now