Solved

Input # problems with EOF

Posted on 2000-04-18
39
291 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:Vingamel
  • 17
  • 8
  • 8
  • +4
39 Comments
 

Expert Comment

by:patm_EE
ID: 2727742
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
 

Expert Comment

by:patm_EE
ID: 2727746
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
 
LVL 9

Expert Comment

by:Ruchi
ID: 2727747
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
 
LVL 32

Expert Comment

by:Erick37
ID: 2727757
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2727762
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2727776
Gosh.. you gotta type quick out here.. and to think Patm_EE.. got TWO comments out.. I am pathetic.. <LOL> and a <smile>.
0
 
LVL 1

Author Comment

by:Vingamel
ID: 2727807
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2727817
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2727825
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2727849
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2727857
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
 
LVL 9

Expert Comment

by:Ruchi
ID: 2727871
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2727879
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2727889
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2727899
Also, just a note, I am using this exact same code in a separate program and it works just fine.
0
 
LVL 1

Author Comment

by:Vingamel
ID: 2727921
(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
 
LVL 1

Author Comment

by:Vingamel
ID: 2727924
Adjusted points from 75 to 100
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2727937
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2727951
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 14

Expert Comment

by:wsh2
ID: 2727982
<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
 
LVL 1

Author Comment

by:Vingamel
ID: 2727990
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2727992
Write to the end of a file.. Do an

Open <filename> FOR APPEND
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2727997
Use the Append mode...

Open "MasterFile.MAS" For Append As #ff
While Not EOF(ff)
Write #1, .....
Write #1, ....
Close #ff
0
 
LVL 9

Accepted Solution

by:
Ruchi earned 50 total points
ID: 2728009
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2728023
Ruchi, go ahead answer this question...your answer was nice and complete.  Thanks all for putting up with me.
--Vingamel
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2728031
<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
 
LVL 9

Expert Comment

by:Ruchi
ID: 2728062
Vingamel, thank you very much, but I want you to consider ... splitting points.

Wsh2: :)
0
 
LVL 1

Author Comment

by:Vingamel
ID: 2728106
Errr, how do I split points, guys?
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2728148
Vingamel, I don't know... I think you should go to Community Support to post a new question. Ask Wsh2.
0
 
LVL 1

Author Comment

by:Vingamel
ID: 2728195
Errr, how do I split points, guys?
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2728210
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
 
LVL 9

Expert Comment

by:Ruchi
ID: 2728220
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2728231
<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
 
LVL 1

Author Comment

by:Vingamel
ID: 2728286
Alrighty then...waiting on them to reduce my points so I can split this.  Danke
0
 
LVL 3

Expert Comment

by:Foyal
ID: 2728374
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
 
LVL 3

Expert Comment

by:darinw
ID: 2728564
Community Support has reduced points from 100 to 50
0
 
LVL 3

Expert Comment

by:darinw
ID: 2728565
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
 
LVL 9

Expert Comment

by:Ruchi
ID: 2729502
<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
 
LVL 1

Author Comment

by:Vingamel
ID: 2730643
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now