Vingamel
asked on
Input # problems with EOF
I am reading in a sequential text file with Input #:
Open "MasterFile.MAS" For Input As #ff
While Not EOF(ff)
However, it does not recognize the EOF (I have checked the file, and it looks fine). It gets to the last input statement, then starts through the loop again and errors out that it has reached the end of input. The file it is reading was written with Write # statements. First, I don't know why it thinks there is more to this file when it has really reached the EOF. Second, would it be better instead of checking for EOF, to check for some End of File character to indicate the end of file? Help Help
Open "MasterFile.MAS" For Input As #ff
While Not EOF(ff)
However, it does not recognize the EOF (I have checked the file, and it looks fine). It gets to the last input statement, then starts through the loop again and errors out that it has reached the end of input. The file it is reading was written with Write # statements. First, I don't know why it thinks there is more to this file when it has really reached the EOF. Second, would it be better instead of checking for EOF, to check for some End of File character to indicate the end of file? Help Help
EOF DOES check for EOF chracter. Since this is an ASCII text file, Copy it, and paste it into another file and try it with the new file. I suspect that your file is corrupt. I know UNIX files have this problem. If it is still a problem There ARE ways around this using Binary....
Oh, ALSO IF you are inputting Like this
Input #ff a,b,c,d,e,f
Make SURE you have enough data to fill each item ....It won't work if you don't!
Input #ff a,b,c,d,e,f
Make SURE you have enough data to fill each item ....It won't work if you don't!
Did you put...
Dim ff as Integer
ff = FreeFile
Open "MasterFile.MAS" For Input As #ff
While Not EOF(ff)
......
......
Wend Or Loop
Close #ff
??
Dim ff as Integer
ff = FreeFile
Open "MasterFile.MAS" For Input As #ff
While Not EOF(ff)
......
......
Wend Or Loop
Close #ff
??
Using sequential file I/O to read in file that contains embedded null characters (characters with an ANSI value of 0) can cause the following error message:
"Run-time error '62':
Input past end of file".
http://support.microsoft.com/support/kb/articles/Q142/2/46.asp
"Run-time error '62':
Input past end of file".
http://support.microsoft.com/support/kb/articles/Q142/2/46.asp
The code snippet you posted lloks fine, Although I prefer to use the MS recommended..
Do Until EOF(ff)
syntax, rather than the While Not. With this being said, I believe you have a logic problem somewhere after your Input statement.. and are issuing an additional Input statement where you don't expect it.. or you are not Closing the file before reading it again. If you would, please post your section of code.. <smile>.
Do Until EOF(ff)
syntax, rather than the While Not. With this being said, I believe you have a logic problem somewhere after your Input statement.. and are issuing an additional Input statement where you don't expect it.. or you are not Closing the file before reading it again. If you would, please post your section of code.. <smile>.
Gosh.. you gotta type quick out here.. and to think Patm_EE.. got TWO comments out.. I am pathetic.. <LOL> and a <smile>.
ASKER
EOF DOES check for EOF chracter. Since this is an ASCII text file, Copy it, and paste it into another file and try it with the new file. I suspect that your file is corrupt. I know UNIX files have this problem. If it is still a problem There ARE ways around this using Binary....
This solution did not work.
This solution did not work.
ASKER
Did you put...
Dim ff as Integer
ff = FreeFile
Open "MasterFile.MAS" For Input As #ff
While Not EOF(ff)
.......
.......
Wend Or Loop
Close #ff
??
Yes, this correct.
Dim ff as Integer
ff = FreeFile
Open "MasterFile.MAS" For Input As #ff
While Not EOF(ff)
.......
.......
Wend Or Loop
Close #ff
??
Yes, this correct.
ASKER
Private Sub OpenMaster()
Dim a As Integer
Dim iX As Integer
Dim iY As Integer
Dim iZ As Integer
ff = FreeFile
CommonDialog1.Filter = "Text Files (*.MAS) | *.MAS"
CommonDialog1.FileName = "MasterFile.MAS"
CommonDialog1.ShowOpen
Open "MasterFile.MAS" For Input As #ff
While Not EOF(ff)
Input #ff, Race(a)
Input #ff, Skin(a)
Input #ff, HairTexture(a)
Input #ff, HairColor(a)
Input #ff, Eyes(a)
Input #ff, Stature(a)
Input #ff, Build(a)
Input #ff, Country(a)
Input #ff, Title(a)
Input #ff, Leader(a)
Input #ff, NumberOfGenerals(a)
Wend
Close #ff
End Sub
Dim a As Integer
Dim iX As Integer
Dim iY As Integer
Dim iZ As Integer
ff = FreeFile
CommonDialog1.Filter = "Text Files (*.MAS) | *.MAS"
CommonDialog1.FileName = "MasterFile.MAS"
CommonDialog1.ShowOpen
Open "MasterFile.MAS" For Input As #ff
While Not EOF(ff)
Input #ff, Race(a)
Input #ff, Skin(a)
Input #ff, HairTexture(a)
Input #ff, HairColor(a)
Input #ff, Eyes(a)
Input #ff, Stature(a)
Input #ff, Build(a)
Input #ff, Country(a)
Input #ff, Title(a)
Input #ff, Leader(a)
Input #ff, NumberOfGenerals(a)
Wend
Close #ff
End Sub
ASKER
Private Sub OpenMaster()
Dim a As Integer
Dim iX As Integer
Dim iY As Integer
Dim iZ As Integer
ff = FreeFile
CommonDialog1.Filter = "Text Files (*.MAS) | *.MAS"
CommonDialog1.FileName = "MasterFile.MAS"
CommonDialog1.ShowOpen
Open "MasterFile.MAS" For Input As #ff
While Not EOF(ff)
Input #ff, Race(a)
Input #ff, Skin(a)
Input #ff, HairTexture(a)
Input #ff, HairColor(a)
Input #ff, Eyes(a)
Input #ff, Stature(a)
Input #ff, Build(a)
Input #ff, Country(a)
Input #ff, Title(a)
Input #ff, Leader(a)
Input #ff, NumberOfGenerals(a)
Wend
Close #ff
End Sub
Dim a As Integer
Dim iX As Integer
Dim iY As Integer
Dim iZ As Integer
ff = FreeFile
CommonDialog1.Filter = "Text Files (*.MAS) | *.MAS"
CommonDialog1.FileName = "MasterFile.MAS"
CommonDialog1.ShowOpen
Open "MasterFile.MAS" For Input As #ff
While Not EOF(ff)
Input #ff, Race(a)
Input #ff, Skin(a)
Input #ff, HairTexture(a)
Input #ff, HairColor(a)
Input #ff, Eyes(a)
Input #ff, Stature(a)
Input #ff, Build(a)
Input #ff, Country(a)
Input #ff, Title(a)
Input #ff, Leader(a)
Input #ff, NumberOfGenerals(a)
Wend
Close #ff
End Sub
ASKER
Using sequential file I/O to read in file that contains embedded null characters (characters with an ANSI value of 0) can cause the following error message:
"Run-time error '62':
Input past end of file".
http://support.microsoft.com/support/kb/articles/Q142/2/46.asp
RESOLUTION
You can work around this behavior by opening the sequential file as a binary file and manipulating the sequential file as a binary file using the Get and Put statements to set and retrieve file data.
(So, I got this from the website...how would I modify my code to do this as I am not familiar with Get & Put and binary files). Thanks.
"Run-time error '62':
Input past end of file".
http://support.microsoft.com/support/kb/articles/Q142/2/46.asp
RESOLUTION
You can work around this behavior by opening the sequential file as a binary file and manipulating the sequential file as a binary file using the Get and Put statements to set and retrieve file data.
(So, I got this from the website...how would I modify my code to do this as I am not familiar with Get & Put and binary files). Thanks.
Change
Input #ff, Race(a)
Input #ff, Skin(a)
Input #ff, HairTexture(a)
Input #ff, HairColor(a)
Input #ff, Eyes(a)
Input #ff, Stature(a)
Input #ff, Build(a)
Input #ff, Country(a)
Input #ff, Title(a)
Input #ff, Leader(a)
Input #ff, NumberOfGenerals(a)
to
Input #ff, Race(a), Skin(a), HairTexture(a), so forth. This is shortcut.
You need to define 11 arrays that will hold the file's data.
Dim Skin() as ....
Dim Race() as ....
something like that.
Input #ff, Race(a)
Input #ff, Skin(a)
Input #ff, HairTexture(a)
Input #ff, HairColor(a)
Input #ff, Eyes(a)
Input #ff, Stature(a)
Input #ff, Build(a)
Input #ff, Country(a)
Input #ff, Title(a)
Input #ff, Leader(a)
Input #ff, NumberOfGenerals(a)
to
Input #ff, Race(a), Skin(a), HairTexture(a), so forth. This is shortcut.
You need to define 11 arrays that will hold the file's data.
Dim Skin() as ....
Dim Race() as ....
something like that.
ASKER
Using sequential file I/O to read in file that contains embedded null characters (characters with an ANSI value of 0) can cause the following error message:
"Run-time error '62':
Input past end of file".
http://support.microsoft.com/support/kb/articles/Q142/2/46.asp
RESOLUTION
You can work around this behavior by opening the sequential file as a binary file and manipulating the sequential file as a binary file using the Get and Put statements to set and retrieve file data.
(So, I got this from the website...how would I modify my code to do this as I am not familiar with Get & Put and binary files). Thanks.
"Run-time error '62':
Input past end of file".
http://support.microsoft.com/support/kb/articles/Q142/2/46.asp
RESOLUTION
You can work around this behavior by opening the sequential file as a binary file and manipulating the sequential file as a binary file using the Get and Put statements to set and retrieve file data.
(So, I got this from the website...how would I modify my code to do this as I am not familiar with Get & Put and binary files). Thanks.
ASKER
Ruchi, this will not work because I actually have much much much more input statements than what I put here, and several loops etc. The file is a little over 4000 lines long.
ASKER
Also, just a note, I am using this exact same code in a separate program and it works just fine.
ASKER
(The code snippet you posted lloks fine, Although I prefer to use the MS recommended..
Do Until EOF(ff)
syntax, rather than the While Not. With this being said, I believe you have a logic problem somewhere after your Input statement.. and are issuing an additional Input statement where you don't expect it.. or you are not Closing the file before reading it again. If you would, please post your section of code.. <smile>.)
I have stepped through the program, and the very last Input statement is reading in the very last item in the text file. I then continues as though there a couple extra items, and these two extra items are empty (like it is reading two empty spaces). I have made sure the file has no extra spaces after the last item in the text file. Weird.
Do Until EOF(ff)
syntax, rather than the While Not. With this being said, I believe you have a logic problem somewhere after your Input statement.. and are issuing an additional Input statement where you don't expect it.. or you are not Closing the file before reading it again. If you would, please post your section of code.. <smile>.)
I have stepped through the program, and the very last Input statement is reading in the very last item in the text file. I then continues as though there a couple extra items, and these two extra items are empty (like it is reading two empty spaces). I have made sure the file has no extra spaces after the last item in the text file. Weird.
ASKER
Adjusted points from 75 to 100
Reading your code.. tells me that you expect 11 records in your file. One record for each field.. vbCrLf delimited:
Input #ff, Race(a)
Input #ff, Skin(a)
Input #ff, HairTexture(a)
Input #ff, HairColor(a)
Input #ff, Eyes(a)
Input #ff, Stature(a)
Input #ff, Build(a)
Input #ff, Country(a)
Input #ff, Title(a)
Input #ff, Leader(a)
Input #ff, NumberOfGenerals(a)
For this to work, your Write # should look identical to the above.
If indeed when you look at your data with a text editor.. you only see one line (the above will show 11 lines) with 11 fields in it, then your input statement should look like this:
Input #ff, Race(a), _
Skin(a), _
HairTexture(a), _
HairColor(a), _
Eyes(a), _
Stature(a), _
Build(a), _
Country(a), _
Title(a), _
Leader(a), _
NumberOfGenerals(a)
Input #ff, Race(a)
Input #ff, Skin(a)
Input #ff, HairTexture(a)
Input #ff, HairColor(a)
Input #ff, Eyes(a)
Input #ff, Stature(a)
Input #ff, Build(a)
Input #ff, Country(a)
Input #ff, Title(a)
Input #ff, Leader(a)
Input #ff, NumberOfGenerals(a)
For this to work, your Write # should look identical to the above.
If indeed when you look at your data with a text editor.. you only see one line (the above will show 11 lines) with 11 fields in it, then your input statement should look like this:
Input #ff, Race(a), _
Skin(a), _
HairTexture(a), _
HairColor(a), _
Eyes(a), _
Stature(a), _
Build(a), _
Country(a), _
Title(a), _
Leader(a), _
NumberOfGenerals(a)
ASKER
I figured out my goof...How embarrassing...I was looping the whole thing as though looking for multiple files and forgot about this. So I guess this is not a problem anymore. <blush>. Lemme throw this at you then (points go to the first to answer)...how do I Write at the end of an existing text file instead of writing over it?
--Retarded Coder
--Retarded Coder
<laughing>.. you beat me with your comments.. Gawd.. I'm slow.. <sheesh>.
Obviously there is extra data at the end of the file.. <sigh>. The way your code is set up, it is read 11 records or nothing. An extra vbCrLf at the end of the file as Notepad.Exe was known to append at one time.. as it is not 11 records, will cause your program to blow.. <sigh>. The way to circumvent this, is to use the second example I showed above, and put everything on a record boundary.
Ok.. now that we have seen your Input.. lets look at your Write. If it is identical in concept to the Input.. then perhaps your Master.Mas file is corrupt, and should be recreated.. by issuing new Write statements all over again.
Obviously there is extra data at the end of the file.. <sigh>. The way your code is set up, it is read 11 records or nothing. An extra vbCrLf at the end of the file as Notepad.Exe was known to append at one time.. as it is not 11 records, will cause your program to blow.. <sigh>. The way to circumvent this, is to use the second example I showed above, and put everything on a record boundary.
Ok.. now that we have seen your Input.. lets look at your Write. If it is identical in concept to the Input.. then perhaps your Master.Mas file is corrupt, and should be recreated.. by issuing new Write statements all over again.
ASKER
I figured out my goof...How embarrassing...I was looping the whole thing as though looking for multiple files and forgot about this. So I guess this is not a problem anymore. <blush>. Lemme throw this at you then (points go to the first to answer)...how do I Write at the end of an existing text file instead of writing over it?
--Retarded Coder
--Retarded Coder
Write to the end of a file.. Do an
Open <filename> FOR APPEND
Open <filename> FOR APPEND
Use the Append mode...
Open "MasterFile.MAS" For Append As #ff
While Not EOF(ff)
Write #1, .....
Write #1, ....
Close #ff
Open "MasterFile.MAS" For Append As #ff
While Not EOF(ff)
Write #1, .....
Write #1, ....
Close #ff
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ruchi, go ahead answer this question...your answer was nice and complete. Thanks all for putting up with me.
--Vingamel
--Vingamel
<offthread>
Ruchi:
I finally beat someone to a response !!!! <ROFLMAO>.. Naturally, your comment is more thorough and better thought out than mine.. but at least I finally beat someone to the submit button.. Thank YOU.. <smile>.
Ruchi:
I finally beat someone to a response !!!! <ROFLMAO>.. Naturally, your comment is more thorough and better thought out than mine.. but at least I finally beat someone to the submit button.. Thank YOU.. <smile>.
Vingamel, thank you very much, but I want you to consider ... splitting points.
Wsh2: :)
Wsh2: :)
ASKER
Errr, how do I split points, guys?
Vingamel, I don't know... I think you should go to Community Support to post a new question. Ask Wsh2.
ASKER
Errr, how do I split points, guys?
Ahhhhh.. finally I can take my time to type.. LOL.
As per Ruchi's Comment:
To split points.. leave a question at customer service requesting that the points on this question be reduced so that you may award a split. When you get back the Additional points from the reduction, create a new question with "FOR <screenname>" in the Question Subject.. and award the amount of points to them as you deem deserved.. <smile>.
The link to customer service so you can leave a question telling them that you want to split the points is:
https://www.experts-exchange.com/Customer_Service/Experts_Exchange/
As per Ruchi's Comment:
To split points.. leave a question at customer service requesting that the points on this question be reduced so that you may award a split. When you get back the Additional points from the reduction, create a new question with "FOR <screenname>" in the Question Subject.. and award the amount of points to them as you deem deserved.. <smile>.
The link to customer service so you can leave a question telling them that you want to split the points is:
https://www.experts-exchange.com/Customer_Service/Experts_Exchange/
Go to Community Support to post a question asking for splitting points. Or, you should see "Accept as answer" button at the right of the Comment.
<offthread>
Hey Ruchi.. do you remember ever getting anything for that marathon question you and I worked on a couple of weeks ago? Its been so long.. I can't remember the question(s).. as I am about as mentally fast, as I am on the keyboard. Perhaps, I should send the above insructions there.. <smile> and a <wink>.
Hey Ruchi.. do you remember ever getting anything for that marathon question you and I worked on a couple of weeks ago? Its been so long.. I can't remember the question(s).. as I am about as mentally fast, as I am on the keyboard. Perhaps, I should send the above insructions there.. <smile> and a <wink>.
ASKER
Alrighty then...waiting on them to reduce my points so I can split this. Danke
it is also very easy to just check before each input# statement (and will solve problems concerning *incomplete* records)
Do While Not EOF(ff)
If Not EOF(ff) Then Input #ff...
If Not EOF(ff) Then Input #ff...
If Not EOF(ff) Then Input #ff...
If Not EOF(ff) Then Input #ff...
Loop
Do While Not EOF(ff)
If Not EOF(ff) Then Input #ff...
If Not EOF(ff) Then Input #ff...
If Not EOF(ff) Then Input #ff...
If Not EOF(ff) Then Input #ff...
Loop
Community Support has reduced points from 100 to 50
Reducing points to one half to allow for split.
You can now accept one of the comments in this thread as an answer. To award the other Expert, you can create a new question in this topic area with a title of 'For ExpertName -- 10330372' using that Experts username.
Remember, the Accept Comment as Answer button is in the header of the comment.
For your convenience, you can use this link to create the new question in this topic area:
https://www.experts-exchange.com/bin/NewQForm?ta=31
darinw
Customer Service
You can now accept one of the comments in this thread as an answer. To award the other Expert, you can create a new question in this topic area with a title of 'For ExpertName -- 10330372' using that Experts username.
Remember, the Accept Comment as Answer button is in the header of the comment.
For your convenience, you can use this link to create the new question in this topic area:
https://www.experts-exchange.com/bin/NewQForm?ta=31
darinw
Customer Service
<offthread> (Copying Wsh2)
Wsh2: Yeah, I remembered that we worked on that "minimizing windows" question a few weeks ago. And, I remembered you asking me "Would you like more coffee, Sir" :) Did you remember that? <wink>(imitating Wsh2)
Vingamel, thank you very much. I'm glad that I could be of any help to you.
Wsh2: Yeah, I remembered that we worked on that "minimizing windows" question a few weeks ago. And, I remembered you asking me "Would you like more coffee, Sir" :) Did you remember that? <wink>(imitating Wsh2)
Vingamel, thank you very much. I'm glad that I could be of any help to you.
ASKER
Visit me anytime at http://www.jarnath.freeservers.com