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
Solved

EOF on input file

Posted on 1998-09-04
10
451 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
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

840 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