[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7443
  • Last Modified:

runtime error 62 - input past end of file

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
0
shoppe66
Asked:
shoppe66
  • 2
  • 2
2 Solutions
 
EDDYKTCommented:
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0
 
shoppe66Author 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.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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.     =)


0
 
EDDYKTCommented:
>>"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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now