Results 1 to 11 of 11

Thread: Error reading text file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Philippines
    Posts
    85

    Question

    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.


  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Philippines
    Posts
    85

    Unhappy

    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

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  5. #5
    Addicted Member
    Join Date
    Oct 2000
    Location
    Vienna/Austria
    Posts
    132
    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

  6. #6
    Member
    Join Date
    Oct 2000
    Location
    Philippines
    Posts
    49
    try to insert a check like -- if not eof then <code>

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  8. #8
    Addicted Member
    Join Date
    Oct 2000
    Location
    Vienna/Austria
    Posts
    132
    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

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Philippines
    Posts
    85

    Cool 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))

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
  •  



Click Here to Expand Forum to Full Width