|
-
Oct 13th, 2000, 04:00 AM
#1
Thread Starter
Lively Member
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.
-
Oct 13th, 2000, 04:09 AM
#2
transcendental analytic
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
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 16th, 2000, 01:51 AM
#3
Thread Starter
Lively Member
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
-
Oct 16th, 2000, 03:20 AM
#4
transcendental analytic
Code:
if not EOF(hfile) then RichTextBox1.Text = Input$(LOF(hfile), hfile)
Doesn't this work? What do you get at LOF(hfile)?
Also another way to do this is:
Code:
Dim buffer as string
Open sfilename For Binary As #hfile
buffer=Space(lof(hfile))
get#hfile,,buffer
RichTextBox1.Text = buffer
Close #hfile
Opening in binary should never cause a input past end of file error.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 16th, 2000, 03:42 AM
#5
Addicted Member
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
-
Oct 16th, 2000, 04:26 AM
#6
Member
try to insert a check like -- if not eof then <code>
-
Oct 16th, 2000, 04:37 AM
#7
transcendental analytic
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.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 16th, 2000, 05:56 AM
#8
Addicted Member
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
-
Oct 16th, 2000, 09:03 AM
#9
transcendental analytic
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
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 16th, 2000, 09:47 PM
#10
Thread Starter
Lively Member
Great Code!!!!
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))
-
Oct 17th, 2000, 06:12 AM
#11
transcendental analytic
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.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|