Hi to all,
how do I get rid of the eror "INput past the end of line"?
I'm trying to open a freefile when i got this error.
TIA.
Printable View
Hi to all,
how do I get rid of the eror "INput past the end of line"?
I'm trying to open a freefile when i got this error.
TIA.
You get that error when you use Input and LineInput functions when the reading/writing location (loc) have past the End of the file (EOF)
That means usually that your reading algoritm has leaks or that the file doesn't match it. To avoid this at all cost you can do two things, error handling or checking for EOF.
Code:'for a loop
Do while EOF(1)
Input#1,stuff
Loop
'or if several Inputs
if not EOF(1) then Input#1,stuff1
if not EOF(1) then Input#1,stuff2
'yep, you need to check for it every time
'and error handling
On error resume next
Do until err
Input#1,stuff
loop
Kedaman,
I didn't know how to incorporate your code in checking the EOF(). i was able to use only on error statement.
Here the code:
Private Sub CmdList_Click()
On Error GoTo EksitView
If FileLog.ListIndex < 0 Then
MsgBox "No File Selected....", vbOKOnly, "View Log"
Exit Sub
End If
RichTextBox1.Text = ""
hfile = FreeFile
sfilename = TxtPath.Text
Open sfilename For Input As #hfile
RichTextBox1.Text = Input$(LOF(hfile), hfile)
Close #hfile
EksitView:
Exit Sub
End Sub
Doesn't this work? What do you get at LOF(hfile)?Code:if not EOF(hfile) then RichTextBox1.Text = Input$(LOF(hfile), hfile)
Also another way to do this is:
Opening in binary should never cause a input past end of file error.Code:Dim buffer as string
Open sfilename For Binary As #hfile
buffer=Space(lof(hfile))
get#hfile,,buffer
RichTextBox1.Text = buffer
Close #hfile
Hi vikoy !!!
The "INput past the end of line" error is an bug see
microsoft MSDN and search for "Q142246"
kedaman's solution, is in my opinion one of the best, except that open in binary is a litle bit slow
-cu TheOnly
try to insert a check like -- if not eof then <code>
Binary is faster than Input. That's for sure, namely the problem is (i just checked it up) you can't read binary data with input, it will probably hang up on a EOF mark and then say input past end of file because of that. Well the checking actually is the proof that it actually must be slower. Don't use Input Function, use Get, always use Get.
Hi kedaman !!!
You can read with input when you open the file binary.
if you set the amount of data you want to read exactly to the file length. (see code below - note quick an dirty)
If you want to loop trough the file your are right !!!
Dim hfile
Dim sfilename
Dim x
hfile = FreeFile
sfilename = "c:\command.com"
Open sfilename For Binary As #hfile
x = Input(LOF(hfile), hfile)
debug.print x
Close #hfile
Aye, thanks TheOnly, but i'm sure Input$ has some external file checking going on since i got some huge differences between Get and Input:
Input: 17720 ms for a 3.6 M file
Get: 192 ms for a 3.6 M file
Thank you guys!!! great code from kedaman and the only....
I prefer kedaman's code which i think is more optimize in terms of speed.
I suspect that i supposed to read a file as binary because i'm reading streams of binary data that contains non-printable characters in order to get rid of "input past the end of line" error.
Thanks for the help.
BTW? kedaman, why did you use this? Space(lof(hfile))
That should reserve the amount of memory needed for the strings, or otherways you will get only the amount of data the string size is, 0.