|
-
Apr 4th, 2009, 02:01 PM
#1
Thread Starter
Member
[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
-
Apr 4th, 2009, 03:34 PM
#2
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.
-
Apr 4th, 2009, 05:14 PM
#3
Thread Starter
Member
Re: Input past EOF
 Originally Posted by jmsrickland
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?
-
Apr 4th, 2009, 05:33 PM
#4
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
-
Apr 4th, 2009, 07:09 PM
#5
Re: Input past EOF
 Originally Posted by mixman
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.
-
Apr 4th, 2009, 07:33 PM
#6
Re: Input past EOF
 Originally Posted by westconn1
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?
-
Apr 4th, 2009, 07:45 PM
#7
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
-
Apr 4th, 2009, 08:01 PM
#8
Re: Input past EOF
 Originally Posted by westconn1
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
-
Apr 4th, 2009, 09:20 PM
#9
Re: Input past EOF
 Originally Posted by westconn1
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.
-
Apr 5th, 2009, 05:27 AM
#10
Thread Starter
Member
Re: Input past EOF
 Originally Posted by anhn
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|