Solved

EOF on input file

Posted on 1998-09-04
10
453 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 6

Expert Comment

by:clifABB
ID: 1433112
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
ID: 1433113
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
ID: 1433114
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:clifABB
ID: 1433115
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
ID: 1433116
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
 
LVL 6

Expert Comment

by:clifABB
ID: 1433117
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
ID: 1433118
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
ID: 1433119
"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
ID: 1433120
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
ID: 1433121
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

696 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