Results 1 to 10 of 10

Thread: [RESOLVED] Input past EOF

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    56

    Resolved [RESOLVED] Input past EOF

    Evening to all, again i have problem with file editing, this time runtime error 62.

    What i try to do is, open 1 file (default file for my program), for input
    then take values from textboxes and replace default values and save it as file2.

    I readed file I/O tutorial, but that did not help me much...
    My "file editing code " is this:
    Code:
    Open SampFolder & "\erpmod\mod\tooresbind.sav" For Input As #1
          Open SampFolder & "\erpbind.sav" For Output As #2 ' make sure different path then the original file or different name
        Do While Not EOF(1)
           Input #1, tooresBind1
           bind1 = Replace(tooresBind1, "tooresbind1", Text1.Text)
           Print #2, bind1 '
           Input #1, tooresBind2
           bind2 = Replace(tooresBind2, "tooresbind2", Text2.Text)
           Print #2, bind2
           Input #1, tooresBind3
           bind3 = Replace(tooresBind3, "tooresbind3", Text3.Text)
           Print #2, bind3
           Input #1, tooresBind4
           bind4 = Replace(tooresBind4, "tooresbind4", Text4.Text)
           Print #2, bind4
           Input #1, tooresBind5
           bind5 = Replace(tooresBind5, "tooresbind5", Text5.Text)
           Print #2, bind5
           Input #1, tooresBind6
           bind6 = Replace(tooresBind6, "tooresbind6", Text6.Text)
           Print #2, bind6 '
    Loop
    Close #1
    Close #2
    And default file for input is this:
    Code:
    [SendKey]
    Send1=t/login tooresparool~
    Send2=t/mootor~
    Send3=t/tooresbind1~
    Send4=t/tooresbind2~
    Send5=t/tooresbind3~
    Send6=t/tooresbind4~
    Send7=t/tooresbind5~
    Send8=t/tooresbind6~
    Send9=
    Send10=
    Send11=
    Send12=
    Send13=
    Send14=
    Send15=
    Send16=
    Send17=
    Send18=
    Send19=
    Send20=
    [HotKey]
    Key1=42
    Key2=43
    Key3=0
    Key4=1
    Key5=2
    Key6=3
    Key7=4
    Key8=5
    Key9=8
    Key10=9
    Key11=10
    Key12=11
    Key13=12
    Key14=13
    Key15=14
    Key16=15
    Key17=16
    Key18=17
    Key19=18
    Key20=19
    [Activate]
    act1=True
    act2=True
    act3=True
    act4=True
    act5=True
    act6=True
    act7=True
    act8=True
    act9=False
    act10=False
    act11=False
    act12=False
    act13=False
    act14=False
    act15=False
    act16=False
    act17=False
    act18=False
    act19=False
    act20=False
    I think it reads input file wrongly...

    I hope you guys understand what i mean (english is not my native language so its hard to explain myself correctly)

    Idea is that it takes from input line
    Code:
    Send3=t/tooresbind1~
    And replaces this with Text1.Text value..
    Code:
    Send4=t/tooresbind2~
    with Text2.Text value, and so on...


    Kindly Regards
    Mixman

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Input past EOF

    Are you taking into considerations about the extra [....] lines in the file?

    [SendKey]
    [HotKey]
    [Activate]

    When you first open your input file and do your first Input #1, tooresBind1
    statement your first line that actually is read is [SendKey].

    I always use Line Input #1 rather than Input #1. Not sure what the dufference is but I don't think it has to do with your problem but I do think you need to consider the extra lines.

    Also I see that in your loop you are reading in 6 lines per itteration through the loop but your file is not in multiples of 6. Don't quite understand your thinking here.

    Your input file has 63 lines.

    You loop 10 time reading in 60 records

    Then it starts to loop again; the 11th time

    It reads in 3 more records

    This is your 63 lines

    Then it tried to read one more....this is your Input Past EOF error

    So, you need to allow for the [....] lines and you need to make sure your number of lines to process in the file are equal in multiples of the number of lines you process each time through the loop.
    Last edited by jmsrickland; Apr 4th, 2009 at 03:54 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    56

    Re: Input past EOF

    Quote Originally Posted by jmsrickland View Post
    Are you taking into considerations about the extra [....] lines in the file?

    [SendKey]
    [HotKey]
    [Activate]

    When you first open your input file and do your first Input #1, tooresBind1
    statement your first line that actually is read is [SendKey].

    I always use Line Input #1 rather than Input #1. Not sure what the dufference is but I don't think it has to do with your problem but I do think you need to consider the extra lines.

    Also I see that in your loop you are reading in 6 lines per itteration through the loop but your file is not in multiples of 6. Don't quite understand your thinking here.

    Your input file has 63 lines.

    You loop 10 time reading in 60 records

    Then it starts to loop again; the 11th time

    It reads in 3 more records

    This is your 63 lines

    Then it tried to read one more....this is your Input Past EOF error

    So, you need to allow for the [....] lines and you need to make sure your number of lines to process in the file are equal in multiples of the number of lines you process each time through the loop.
    Since i am a beginner, this is not written from my head, i searched google for samples.
    All i really want to do is replace on those lines (bolded out exact what replace)
    Send3=t/tooresbind1~ --------- Text1.Text
    Send4=t/tooresbind2~ --------- Text2.Text
    Send5=t/tooresbind3~ --------- Text3.Text
    Send6=t/tooresbind4~ --------- Text4.Text
    Send7=t/tooresbind5~ --------- Text5.Text
    Send8=t/tooresbind6~ --------- Text6.Text


    So its the loop that messes things up?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Input past EOF

    I think it reads input file wrongly...
    input past end of file mostly occurs when there is and eof character within the content of the file

    this can be resolved by opening the file for binary instead of input, as eof characters are just read as part of the file

    alteratively if you know how many lines are in the input file, you can just loop for that number of lines, instead of until eof

    for i = 1 to numberoflines
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Input past EOF

    Quote Originally Posted by mixman View Post
    Since i am a beginner, this is not written from my head, i searched google for samples.
    '
    '
    '
    So its the loop that messes things up?
    It is exactly the way I posted it. Your Do Loop only allows for multiples of 6 so your input must also be in multiple of 6. You must also read in the [...] lines and bypass them as they are not part of the lines you are processing.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Input past EOF

    Quote Originally Posted by westconn1 View Post
    input past end of file mostly occurs when there is and eof character within the content of the file.

    This can be resolved by opening the file for binary instead of input, as eof characters are just read as part of the file
    I have run into this many times, usually when using Input$() to read a text file. When I back down only one or two characters of the read rather than LOF(), the error disappears. That often makes me wonder what is going on at EOF().

    Nobody has ever been able to explain this to me, so I abandoned Input$() and now read all text files in binary when I want the entire file in memory. Do you blame me?
    Doctor Ed

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Input past EOF

    Nobody has ever been able to explain this to me, so I abandoned Input$() and now read all text files in binary when I want the entire file in memory. Do you blame me?
    not at all
    i believe some programs put an eof character at the end of file, edlin maybe one of those also i have struck problem with text files saved in word, so yes binary is safer to avoid error, but may need to handle eof character in the returned strings
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Input past EOF

    Quote Originally Posted by westconn1 View Post
    input past end of file mostly occurs when there is and eof character within the content of the file
    This is NOT the case with a "pure" text file. The problem is what jmsrickland already explained.
    The error happend at round 11th at the line
    Input #1, tooresBind4
    after all 63 lines of the file were read.

    "While Not EOF(1)" need to check after every Input #1, but you do 6 consecutive Input #1 at a time before checking EOF(1), so it fails at 64th Input #1

    Try this:
    Code:
        Dim sLine As String
        
        Open SampFolder & "\erpmod\mod\tooresbind.sav" For Input As #1
        Open SampFolder & "\erpbind.sav" For Output As #2
        Do While Not EOF(1)
            Line Input #1, sLine
            Select Case Left$(sLine, 6)
                Case "Send3=": sLine = "Send3=t/" & Text1.Text & "~"
                Case "Send4=": sLine = "Send4=t/" & Text2.Text & "~"
                Case "Send5=": sLine = "Send5=t/" & Text3.Text & "~"
                Case "Send6=": sLine = "Send6=t/" & Text4.Text & "~"
                Case "Send7=": sLine = "Send7=t/" & Text5.Text & "~"
                Case "Send8=": sLine = "Send8=t/" & Text6.Text & "~"
            End Select
            Print #2, sLine
        Loop
        Close #1
        Close #2
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  9. #9
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Input past EOF

    Quote Originally Posted by westconn1 View Post
    not at all
    i believe some programs put an eof character at the end of file, edlin maybe one of those also i have struck problem with text files saved in word, so yes binary is safer to avoid error, but may need to handle eof character in the returned strings
    What irks me most is that Input$() sometimes works and sometimes does not from one text file to the next, and I find that a bit nerve wracking.
    Doctor Ed

  10. #10

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    56

    Re: Input past EOF

    Quote Originally Posted by anhn View Post
    This is NOT the case with a "pure" text file. The problem is what jmsrickland already explained.
    The error happend at round 11th at the line
    Input #1, tooresBind4
    after all 63 lines of the file were read.

    "While Not EOF(1)" need to check after every Input #1, but you do 6 consecutive Input #1 at a time before checking EOF(1), so it fails at 64th Input #1

    Try this:
    Code:
        Dim sLine As String
        
        Open SampFolder & "\erpmod\mod\tooresbind.sav" For Input As #1
        Open SampFolder & "\erpbind.sav" For Output As #2
        Do While Not EOF(1)
            Line Input #1, sLine
            Select Case Left$(sLine, 6)
                Case "Send3=": sLine = "Send3=t/" & Text1.Text & "~"
                Case "Send4=": sLine = "Send4=t/" & Text2.Text & "~"
                Case "Send5=": sLine = "Send5=t/" & Text3.Text & "~"
                Case "Send6=": sLine = "Send6=t/" & Text4.Text & "~"
                Case "Send7=": sLine = "Send7=t/" & Text5.Text & "~"
                Case "Send8=": sLine = "Send8=t/" & Text6.Text & "~"
            End Select
            Print #2, sLine
        Loop
        Close #1
        Close #2
    Thanks a ton, that solved my problem, and i will write that down, since its a good way to do replascements.

    Thank you all!


    Regards

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