londonkiwi
Programmer
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]
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]