[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

BeeJ

12/31/2011 5:12:00 PM

I use this to suck all the data in.
But this time I got an
input past end
error.
I created the file and it is all text using Print lFNbr.
What can cause this to fail?

vLOF = FileSizeGet(sDPName)

lFNbr = FreeFile
Open sDPName For Input As #lFNbr
bOpen = True
' one suck
sLines = input(vLOF, lFNbr)

and Yes
LOF(lFNbr) ' gives the same value as vLOF.
using FileSizeGet since it handles large files.


6 Answers

Jim Mack

12/31/2011 5:24:00 PM

0

> I use this to suck all the data in.
> But this time I got an
> input past end
> error.
> I created the file and it is all text using Print lFNbr.

> What can cause this to fail?

A byte in the file with the decimal value 26 (eof) could.

What you're doing would be better handled using Binary, not Input.

open Fil for binary as 1
buf$ = space$(lof(1))
get 1,,buf
close 1

--
Jim


ralph

12/31/2011 6:20:00 PM

0

On Sat, 31 Dec 2011 09:11:37 -0800, BeeJ <nospam@spamnot.com> wrote:

>I use this to suck all the data in.
>But this time I got an
> input past end
>error.
>I created the file and it is all text using Print lFNbr.
>What can cause this to fail?
>
> vLOF = FileSizeGet(sDPName)
>
> lFNbr = FreeFile
> Open sDPName For Input As #lFNbr
> bOpen = True
> ' one suck
> sLines = input(vLOF, lFNbr)
>
>and Yes
> LOF(lFNbr) ' gives the same value as vLOF.
>using FileSizeGet since it handles large files.
>

Or if text ...

> vLOF = FileSizeGet(sDPName)
>
> lFNbr = FreeFile
> Open sDPName For Input As #lFNbr

Do Until EOF(IFNbr)
sLine = Input(vLOF, LFNbr)
...
Loop

-ralph

GS

1/1/2012 2:02:00 AM

0

This is what I use. It's always handled some really large files
reliably without issue...

Function GetTextFromFile(sFileName As String) As String
' Opens and reads the contents of a text file
Dim iNum As Integer, bOpen As Boolean, sz As String

On Error GoTo ErrHandler
iNum = FreeFile() 'Get the next file number
'Read the entire file
Open sFileName For Binary Access Read As #iNum
bOpen = True '//if we got here then file opened successfully
GetTextFromFile = Space$(LOF(iNum)): Get iNum, , GetTextFromFile

ErrHandler:
If bOpen Then Close #iNum
End Function '//GetTextFromFile()

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup! comp.lang.basic.visual.misc


GS

1/1/2012 2:04:00 AM

0

After serious thinking GS wrote :
Seems I haven't updated this recently as I no longer use the string
variable...

> Function GetTextFromFile(sFileName As String) As String
> ' Opens and reads the contents of a text file
> Dim iNum As Integer, bOpen As Boolean
>
> On Error GoTo ErrHandler
> iNum = FreeFile() 'Get the next file number
> 'Read the entire file
> Open sFileName For Binary Access Read As #iNum
> bOpen = True '//if we got here then file opened successfully
> GetTextFromFile = Space$(LOF(iNum)): Get iNum, , GetTextFromFile
>
> ErrHandler:
> If bOpen Then Close #iNum
> End Function '//GetTextFromFile()

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup! comp.lang.basic.visual.misc


Mike Williams

1/1/2012 3:13:00 PM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:jdnfoj$280$1@dont-email.me...
> I use this [snipped] to suck all the data in.
> I created the file and it is all text using Print lFNbr.

The fact that you used Print to create the file does not necessarily mean
that it contains only what would normally be considered standard text
characters.

> But this time I got an
> input past end
> error.
> Open sDPName For Input As #lFNbr
> sLines = input(vLOF, lFNbr)
> What can cause this to fail?

Either a byte with the value 26 or a byte with the value zero will cause the
above code to fail with an Input Past End of File error. The 26 will cause
it to fail because it will be seen by the Input function as an end of file
marker and the zero byte will cause it to fail because the Input function
ignores zeros whilst reading everything else around them, causing the
function to attempt to read as many "extra bytes that are not there" from
the end of the file as there are zeros contained within it.

The Get statement will be better for your needs, partly because it does not
have the above problems and partly because it is hundreds of times faster
than the Input function on large files.

Mike

Mike Williams

1/1/2012 3:47:00 PM

0

"Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message
news:jdpt6c$t5m$1@dont-email.me...

> . . . and partly because it is hundreds of times
> faster than the Input function on large files.

Actually the "hundreds of times faster" was just an attention grabber. It is
about ten times faster though ;-)

Mike