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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input Past End of File Error ...HELP

Status
Not open for further replies.

londonkiwi

Programmer
Sep 25, 2000
83
NZ
This code was greatfully developed for us/me by swilliams. I have modified it, but now get an Input past end of line. The code is below, and a sample input and output file.

I would appreciate any advice/help

INPUT DATA

21 1014 1015 2628594 6612435
22 1014 1015 2628623 6612381
23 1014 1015 2628673 6612307
.....etc


OUTPUT DATA (Hopefully!)

2628594 6612435
2628623 6612381
2628673 6612307

Private Sub Command1_Click()

Dim lCounter As Long
Dim lLine As Long
Dim sLine As String
Dim sNewLine As String
Dim FileNumRead As Integer
Dim FileNumWrite As Integer
Dim lData1, lData2, lData3, lData4, lData5 As Integer

Dim i As Integer

Dim sFileName As String
sFileName = App.Path & "\readmif.mif"
Dim sNewFile As String
sNewFile = App.Path & "\writemid.mid"
FileNumRead = FreeFile

Open sFileName For Input As #FileNumRead
FileNumWrite = FreeFile
Open sNewFile For Output As #FileNumWrite

lLine = 0

Do Until Right(sLine, 21) = vbCr Or Right(sLine, 21) = vbCrLf Or EOF(FileNumRead) ' want to find the end of file
Line Input #FileNumRead, sLine
Loop
Line Input #FileNumRead, sLine ' get first line of data

Do Until EOF(FileNumRead)
' code here to process line of data, setting sData1-sData5
If UCase(Left(Trim(sLine), 2)) = "21" Then
i = 1
Do Until Mid(sLine, i, 1) = " " 'get data1, I need this data to use when creating another file
lData1 = lData1 & Mid(sLine, i, 1)
i = i + 1
Loop
i = i + 1
Do Until Mid(sLine, i, 1) = " "
lData2 = lData2 & Mid(sLine, i, 1) 'get data2, I need this data to use when creating another file
i = i + 1
Loop
i = i + 1
Do Until Mid(sLine, i, 1) = " "
lData3 = lData3 & Mid(sLine, i, 1) 'get data3 , as above comment
i = i + 1
Loop
i = i + 1
Do Until Mid(sLine, i, 1) = " "
lData4 = lData4 & Mid(sLine, i, 1) 'get data4
i = i + 1
Loop
i = i + 1
Do Until Mid(sLine, i, 1) = vbCr Or Mid(sLine, i, 1) = vbLf
lData5 = lData5 & Mid(sLine, i, 1) 'get data5
i = i + 1
Loop

Line Input #FileNumRead, sLine ' get next line to see what number to begin output with

Print #FileNumWrite, lData4 & " " & lData5

lData1 = 0: lData2 = 0: lData3 = 0: lData4 = 0: lData5 = 0
Else
If lLine = 0 Then
lLine = -1
Else
lLine = 0
End If
Line Input #FileNumRead, sLine ' get next line to see what number to begin output with
End If
Loop

Close #FileNumRead
Close #FileNumWrite

MsgBox "Completed Reading MIF (readmif) and Writing MID (writemid)"

End Sub




[sig][/sig]
 
You have two file reads after the EOF is encountered. The second "Line Input #FileNumRead, sLine" doesn't appear to do anything but force the program to skip a line in the file. You can probably eliminate the error and retain the program's current functionality by removing that line and changing the last "Line Input" statement to:

If Not EOF(FileNumRead) Then
[tab]Line Input #FileNumRead, sLine
End If

It's still buggy. You are only using every other line of data.
[sig]<p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>Don't sit down. It's time to dig another one.[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top