chris-uk-lad
08-05-2008, 11:43 PM
Hi.
Im running this code atm which reads in a text file and outputs it in a different format in another txt file. The line altered depends upon the first 2 characters in that line (either DB DJ or T).
Public Function Textfile()
Dim strLine As String
Dim manLine As String
Dim start As String
Dim smallStart As String
Open "C:\Input.txt" For Input As #1
Open "C:\Output.txt" For Output As #2
Line Input #1, strLine
Do While Not EOF(1)
start = Left(strLine, 2)
smallStart = Left(strLine, 1)
If start = "DB" Then
manLine = Left(strLine, 90) & Mid(strLine, 91, 20) & Mid(strLine, 131)
Print #2, manLine
ElseIf start = "DJ" Then
manLine = Left(strLine, 22) & Mid(strLine, 23, 28) & Mid(strLine, 73, 28) _
& Mid(strLine, 123, 28) & Mid(strLine, 173, 28) & Mid(strLine, 223)
Print #2, manLine
ElseIf smallStart = "T" Then
manLine = Left(strLine, 76) & Mid(strLine, 115, 2)
Print #2, manLine
Else
Print #2, strLine
End If
Line Input #1, strLine
Loop
Print #2, strLine
Close #1
Close #2
End Function
The 'start' variable never even reads in T_ to even check it against, DJ being the last picked up amount in the sample:
H208
DA02
DB02
DJ08
T004
Is this an EOF problem? Not sure if this is because its a single character instead of a double, or because its the last file in the txt doc.
Im running this code atm which reads in a text file and outputs it in a different format in another txt file. The line altered depends upon the first 2 characters in that line (either DB DJ or T).
Public Function Textfile()
Dim strLine As String
Dim manLine As String
Dim start As String
Dim smallStart As String
Open "C:\Input.txt" For Input As #1
Open "C:\Output.txt" For Output As #2
Line Input #1, strLine
Do While Not EOF(1)
start = Left(strLine, 2)
smallStart = Left(strLine, 1)
If start = "DB" Then
manLine = Left(strLine, 90) & Mid(strLine, 91, 20) & Mid(strLine, 131)
Print #2, manLine
ElseIf start = "DJ" Then
manLine = Left(strLine, 22) & Mid(strLine, 23, 28) & Mid(strLine, 73, 28) _
& Mid(strLine, 123, 28) & Mid(strLine, 173, 28) & Mid(strLine, 223)
Print #2, manLine
ElseIf smallStart = "T" Then
manLine = Left(strLine, 76) & Mid(strLine, 115, 2)
Print #2, manLine
Else
Print #2, strLine
End If
Line Input #1, strLine
Loop
Print #2, strLine
Close #1
Close #2
End Function
The 'start' variable never even reads in T_ to even check it against, DJ being the last picked up amount in the sample:
H208
DA02
DB02
DJ08
T004
Is this an EOF problem? Not sure if this is because its a single character instead of a double, or because its the last file in the txt doc.