Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

runtime error 62 - input past end of file

Posted on 2006-11-03
5
Medium Priority
?
7,372 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
0
Comment
Question by:shoppe66
  • 2
  • 2
5 Comments
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 1600 total points
ID: 17865696
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 400 total points
ID: 17867097
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
 

Author Comment

by:shoppe66
ID: 17870125
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17870968
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 17873434
>>"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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…
Suggested Courses

772 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