What determines the EOF (End of File)?

Papa_Don

New Member
Joined
Jan 22, 2015
Messages
38
Group, I've written a VB.net program to format and merge multiple text files together. Assuming there are 3 files to merge together, the program removes the last lines of file 1 and 2 (these are blank lines and a line that says "End of Report) and then merges these two together. The third file is then merged "as is" to the others.

In Excel (using VBA) the code reads the file line by line and imports portions of this data into the various cells. However the code isn't reading all the way to the bottom as its telling me it is beyond the EOF. So I have several questions:

1) How is the EOF determined?
2) Is there something that I can do in the merging to "create" a new EOF at the bottom of my merged file?

The code to merge the files looks like this (VB.net):

If fileCount = 3 Then
RestranName = getRestranName(0)
RestranName2 = getRestranName(1)
RestranName3 = getRestranName(2)
Dim readtxt() As String = File.ReadAllLines(RestranName)
'Deleted the actual file.
File.Delete(RestranName)
'Now time to read the array elements and save them in a file.
For i As Integer = readtxt.GetLowerBound(0) To readtxt.GetUpperBound(0) - 4
'Appending the line to the text file
My.Computer.FileSystem.WriteAllText(RestranName, readtxt(i), True)
If i < readtxt.GetUpperBound(0) - 4 Then
'Appending a new line into the text file.
My.Computer.FileSystem.WriteAllText(RestranName, vbCrLf, True)
End If
Next
My.Computer.FileSystem.WriteAllText(RestranName, pageCode, True)
Me.Cursor = Cursors.Default
Dim readtxt2() As String = File.ReadAllLines(RestranName2)
'Deleted the actual file.
File.Delete(RestranName2)
'Now time to read the array elements and save them in a file.
For i As Integer = readtxt2.GetLowerBound(0) To readtxt2.GetUpperBound(0) - 4
'Appending the line to the text file
My.Computer.FileSystem.WriteAllText(RestranName2, readtxt2(i), True)
If i < readtxt2.GetUpperBound(0) - 4 Then
'Appending a new line into the text file.
My.Computer.FileSystem.WriteAllText(RestranName2, vbCrLf, True)
End If
Next
My.Computer.FileSystem.WriteAllText(RestranName2, pageCode, True)
File.AppendAllText(RestranName, System.IO.File.ReadAllText(RestranName2))
File.AppendAllText(RestranName, File.ReadAllText(RestranName3))
File.Delete(RestranName2)
File.Delete(RestranName3)
End If

The VBA code that reads the file is this:

Open filePath For Input As #1
Do Until textRowNo = 8
'eat 7 rows...
Line Input #1, LineFromFile
endOfFile = Mid(LineFromFile, 56, 13)
If endOfFile = "End of Report" Then
Exit Do
End If
'this is the row counter
textRowNo = (textRowNo + 1)
Loop
Do Until eof(1)
'This begins at row #8.
Line Input #1, LineFromFile
endOfFile = Mid(LineFromFile, 56, 13)
If endOfFile = "End of Report" Then
Exit Do
End If
arrival = Mid(LineFromFile, 1, 9)
status = Trim(Mid(LineFromFile, 11, 3))
typeText = Mid(LineFromFile, 18, 1)
guestName = Trim(Mid(LineFromFile, 23, 28))
roomType = Trim(Mid(LineFromFile, 54, 5))
rateSched = Trim(Mid(LineFromFile, 60, 10))
rateText = Mid(LineFromFile, 71, 11)
roomRate = Val(rateText)
CCtype = Mid(LineFromFile, 93, 2)
CCNo = Mid(LineFromFile, 98, 9)

Dim LValue As Boolean
LValue = IsDate(arrival)
If LValue = False Then
Call ReportTopRows
Exit Sub
End If
'etc for row 8
textRowNo = (textRowNo + 1)

'row 9
If eof(1) Then
Exit Do
End If

Line Input #1, LineFromFile
endOfFile = Mid(LineFromFile, 56, 13)
If endOfFile = "End of Report" Then
Exit Do
End If
departure = Mid(LineFromFile, 1, 9)
source = Trim(Mid(LineFromFile, 48, 5))
agent = Trim(Mid(LineFromFile, 122, 9))

Cells(rowNumber, 1).Value = arrival
Cells(rowNumber, 2).Value = departure
Cells(rowNumber, 3).Value = status
Cells(rowNumber, 4).Value = typeText
Cells(rowNumber, 5).Value = guestName
Cells(rowNumber, 6).Value = roomType
Cells(rowNumber, 7).Value = rateSched
Cells(rowNumber, 8).Value = roomRate
Cells(rowNumber, 9).Value = CCtype
Cells(rowNumber, 10).Value = CCNo
Cells(rowNumber, 11).Value = source
Cells(rowNumber, 12).Value = agent
If arrival <> "" Then
los = Cells(rowNumber, 2).Value - Cells(rowNumber, 1).Value
Cells(rowNumber, 13).Value = los
End If
rowNumber = (rowNumber + 1)

'etc for row 9
textRowNo = (textRowNo + 1)

'row 10
If eof(1) Then Exit Do
Line Input #1, LineFromFile
endOfFile = Mid(LineFromFile, 56, 13)
If endOfFile = "End of Report" Then
Exit Do
End If
textHead = Trim(Mid(LineFromFile, 50, 15))

'this is a blank row - throw it away or it might be the end of file

If textHead = "Reservation" Then
Line Input #1, LineFromFile
If eof(1) Then Exit Do
Line Input #1, LineFromFile
If eof(1) Then Exit Do
Line Input #1, LineFromFile
If eof(1) Then Exit Do
Line Input #1, LineFromFile
If eof(1) Then Exit Do
Line Input #1, LineFromFile
If eof(1) Then Exit Do
Line Input #1, LineFromFile
If eof(1) Then Exit Do
textRowNo = (textRowNo + 5)
End If

textRowNo = (textRowNo + 1)
Loop
Close #1

Do you see anything that can help fix my problem?

In advance, thanks for your assistance.

Don
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,215,372
Messages
6,124,542
Members
449,169
Latest member
mm424

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top