Re: File IO-I am defeated!
- From: Bob O`Bob <filterbob@xxxxxxxxxxxxxxx>
- Date: Wed, 27 Feb 2008 13:20:38 -0800
PeterD wrote:
OK, I have what should be the simplest of code fragments that there
is. Open a file, read it, close:
50 If funFileExists(strPath) Then ' file is really there.
55 nFile = FreeFile
60 Open strPath For Input Lock Read As #nFile
61 nFileLength = LOF(nFile)
63 If nFileLength > 0 Then ' File has data in it...
70 strBuffer = Input(nFileLength, #nFile)
73 End If
80 Close #nFile
90 End If
Now, this is something that I'd teach in my Intro to Programming
class, and expect it to work 100% of the time. The file's contents are
text, there is nothing special about the file. Usually the file is
created by the program dynamically, occasionally it will be an
existing file.
I'm getting err.number = 70, err.description = "Input past end of
file" for some users! This has *got* to be something so obvious that I
can't see it, but what????
BTW, I have no hair left, and am willing to post a picture proving it!
Interesting code. If the file is empty, you only have an empty string
to go on, so reading it anyway can do no harm. Here's what I use:
fh = FreeFile
Open sFn For Input Access Read Lock Write As fh
GetFile = Input$(LOF(fh), fh)
Close #fh
Doesn't really address the errors you're reporting, but I think Mike
has covered that. Binary data can contain "EOF" characters without
them having any such intrinsic meaning.
Bob
--
.
- Follow-Ups:
- Re: File IO-I am defeated!
- From: Karl E. Peterson
- Re: File IO-I am defeated!
- References:
- File IO-I am defeated!
- From: PeterD
- File IO-I am defeated!
- Prev by Date: Re: File IO-I am defeated!
- Next by Date: Re: Deactivate Form
- Previous by thread: Re: File IO-I am defeated!
- Next by thread: Re: File IO-I am defeated!
- Index(es):
Relevant Pages
|
Loading