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
LVL 1
VingamelAsked:
Who is Participating?
 
RuchiCommented:
Open "MasterFile.MAS" For Append As #ff
1. Open the file for Append
2. WRite to the file
   Use Write# instruction to write additional data records at the end of the file.
3. Close the file
0
 
patm_EECommented:
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....
0
 
patm_EECommented:
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!

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
RuchiCommented:
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
??
0
 
Erick37Commented:
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
0
 
wsh2Commented:
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>.


0
 
wsh2Commented:
Gosh.. you gotta type quick out here.. and to think Patm_EE.. got TWO comments out.. I am pathetic.. <LOL> and a <smile>.
0
 
VingamelAuthor Commented:
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.
0
 
VingamelAuthor Commented:
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.
0
 
VingamelAuthor Commented:
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
0
 
VingamelAuthor Commented:
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
0
 
VingamelAuthor Commented:
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.

0
 
RuchiCommented:
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.
0
 
VingamelAuthor Commented:
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.

0
 
VingamelAuthor Commented:
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.  
0
 
VingamelAuthor Commented:
Also, just a note, I am using this exact same code in a separate program and it works just fine.
0
 
VingamelAuthor Commented:
(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.




0
 
VingamelAuthor Commented:
Adjusted points from 75 to 100
0
 
wsh2Commented:
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)
0
 
VingamelAuthor Commented:
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
0
 
wsh2Commented:
<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.

0
 
VingamelAuthor Commented:
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
0
 
wsh2Commented:
Write to the end of a file.. Do an

Open <filename> FOR APPEND
0
 
RuchiCommented:
Use the Append mode...

Open "MasterFile.MAS" For Append As #ff
While Not EOF(ff)
Write #1, .....
Write #1, ....
Close #ff
0
 
VingamelAuthor Commented:
Ruchi, go ahead answer this question...your answer was nice and complete.  Thanks all for putting up with me.
--Vingamel
0
 
wsh2Commented:
<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>.
0
 
RuchiCommented:
Vingamel, thank you very much, but I want you to consider ... splitting points.

Wsh2: :)
0
 
VingamelAuthor Commented:
Errr, how do I split points, guys?
0
 
RuchiCommented:
Vingamel, I don't know... I think you should go to Community Support to post a new question. Ask Wsh2.
0
 
VingamelAuthor Commented:
Errr, how do I split points, guys?
0
 
wsh2Commented:
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:

http://www.experts-exchange.com/Customer_Service/Experts_Exchange/

0
 
RuchiCommented:
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.
0
 
wsh2Commented:
<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>.
0
 
VingamelAuthor Commented:
Alrighty then...waiting on them to reduce my points so I can split this.  Danke
0
 
FoyalCommented:
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


0
 
darinwCommented:
Community Support has reduced points from 100 to 50
0
 
darinwCommented:
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:
http://www.experts-exchange.com/bin/NewQForm?ta=31

darinw
Customer Service
0
 
RuchiCommented:
<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.
0
 
VingamelAuthor Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.