Solved

runtime error 62 - input past end of file

Posted on 2006-11-03
5
7,102 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 400 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 85

Accepted Solution

by:
Mike Tomlinson earned 100 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 85

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now