We help IT Professionals succeed at work.

runtime error 62 - input past end of file

shoppe66
shoppe66 asked
on
Medium Priority
7,872 Views
Last Modified: 2011-08-18
Hi:

I'm writing an app that reads in hundreds of (not so large - 400kb or so) column delimited text files into an array, one at a time, and does some processing on each one.  I can get through about 20 or 30 of the files, and then I hit one in particular, and my app exits with:

"runtime error 62 - input past end of file"

I've checked the text file over and can't see why it's causing my app to act up.  It's just a text file.  The code below is where it's acting up.  What's wrong with it?  Is there any kind of "while not EOF' I can add to this to make it more robust?


Option Explicit
Dim arrayMyFile () As String

Sub GrabThatFile(TheFilePath, TheFileName)
Dim fnum As Integer
fnum = FreeFile()
    Open TheFilePath & TheFileNameFor Input As #fnum
        arrayMyFile = Split(Input(LOF(fnum), #fnum), vbCrLf)
    Close #fnum
End Sub
Comment
Watch Question

Commented:
try this way

dim s as string

Open TheFilePath & TheFileNameFor For Binary Access Read Lock Read Write As #fnum
s = Space$(LOF(ff))
Get #ff, , s
arrayMyFile = Split(s, vbCrLf)

Close ff

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
Another variation that works for me:

    Dim arrayMyFile () As String
    arrayMyFile = Split(GetFileContents("c:\someFile.txt"), vbCrLf)




Private Function GetFileContents(ByVal fileName As String) As String
    Dim ff As Integer
    Dim entireFile As String
   
    If Dir(fileName) <> "" Then
        ff = FreeFile
        Open fileName For Binary Access Read As #ff
        GetFileContents = Input(LOF(ff), ff)
        Close #ff
    Else
        MsgBox fileName, vbExclamation, "File Not Found"
    End If
End Function

Author

Commented:
OK two things:

Could you explain what "Binary Access Read Lock Read Write" is giving me that my initial code didn't?  I'd like to have some idea as to why I was getting the error in the first place.

Also I'd like to split the points because I kind of like the elegance of the second solution, but I have already successfully tested the first.  I'm not sure of the etiiquette here.  What would be a fair way of splitting the points, or should I just give them all to EDDYKT?
You see, I'm a paying member and I largely use this site as a resource, and rarely post questions.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
In general, if two people post essentially the SAME solution then the first to post gets the points. (Unless they posted at the same time...then you split if you're nice).

If you have several variations of a solution or different solutions then it's really up to your discretion.  Give points to posts that you have benefited from.  It doesn't have to be a fair split either...nothing wrong with an 80/20 split for instance.

You are in no way obligated to give points to all who have posted in your question.

If people think you have grossly dispersed points incorrectly they will either yell at you or ask a moderator to adjust points.  That doesn't happen very often though...

Personally, I wouldn't be offended if you gave all the points to EDDYKT.     =)


Commented:
>>"Binary Access Read Lock Read Write"

it means lock the file and read file as binary instead of text.

>>Personally, I wouldn't be offended if you gave all the points to EDDYKT.     =)

Personally, I don't really care of the points. I just need 3000pts every month to extend my membership. To be honest. hehe
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.