Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EOF Problem

Status
Not open for further replies.

Es

Programmer
Aug 5, 2000
1
GB
I am trying to open a Text file ( Notepad) with Open / Input and Output commands.<br>The text file contains a series of comma delinated words that will be then stored in a datastructure before ammending the data and saving back out to a text file.<br>Unfortunatly, although this worked once I now cannot open the text file without receiving a &quot;input past EOF&quot; error message.<br>I cannot resolve this issue and must use the existing structures and text files. For college assessment.<br>Can anyone advise me what to do next. <br>Enclosed copy of appropriate code.<br>Thnaks in advance.<br><br><br><br>Private Sub mnuOpenFile_Click()<br><br>Dim filesaved, fileedited As Boolean<br>Dim index As Integer<br>Dim filenumber As Integer<br>Dim reg, stats As String<br>Dim ctype As Integer<br>Dim premiles As Long<br>Dim serv As String<br><br>cdlgBox.InitDir = App.Path<br>cdlgBox.Filter = &quot;textFiles(*.txt)¦*.txt¦AllFiles(*.*)¦*.*&quot;<br>cdlgBox.FilterIndex = 1<br>cdlgBox.ShowOpen<br><br>filenumber = FreeFile<br>Open cdlgBox.filename For Input As #filenumber<br>index = 0<br><br>Do Until ((EOF(1) = True) And (index &lt; max))<br>index = index + 1<br>With CarList.Cars(index)<br><br>Input #filenumber, .CarReg, .CarType, .LastService, .PreviousMileage, .Status 'reg, ctype, serv, premiles, stats<br>End With<br>Loop<br>Close #filenumber<br>CarList.CarCount = index<br><br>filesaved = False<br>&nbsp;fileedited = False<br>&nbsp;<br>&nbsp;If CarList.CarCount &gt; max Then<br>&nbsp;MsgBox &quot;Car List is Full&quot;<br>&nbsp;End If<br><br>&nbsp;<br>&nbsp;&nbsp;End Sub<br>
 
i believe you should put the loop like this<br><br>Do while not EOF(1)<br>&nbsp;&nbsp;if (index &gt; max) then exit do<br>&nbsp;&nbsp;'or if (index &gt;= max) then exit do<br>&nbsp;&nbsp;index = index + 1<br>&nbsp;With CarList.Cars(index)<br><br>Input #filenumber, .CarReg, .CarType, .LastService, .PreviousMileage, .Status 'reg, ctype, serv, premiles, stats<br>End With<br>Loop<br><br>the way i see your loop uses 'AND' so both condition must be true in order for the loop the break loose, since most likely the EOF(1) will be true first but index still &lt; max, so another input will generate that input past EOF error msg.<br><br>good luck.<br>
 
Hmmm,<br><br>Blurred is almost 100% correct.&nbsp;&nbsp;<br>The original logic doesn't work. <br>In programming, doing something <b>until something is broke</b> is almost never a good idea. <br>&nbsp;It's usually better to <b>do it while it's OK</b>.<br><br>Besides all that there is another problem that might cause a break down in both solutions...<br><br>It's best to test the file you are reading.<br><b>EOF(1)</b> should be coded <b>EOF(filenumber)</b>.<br><br>I'm a purist and believe that even index and max should be based on information (UBound/LBound) gathered from they object they relate to, but that's another story.<br> <p>Wil Mead<br><a href=mailto:wmead@optonline.net>wmead@optonline.net</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top