chris_uk_lad
08-05-2008, 11:54 AM
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).
Option Compare Database
Option Explicit
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
Else
If 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
Else
If smallStart = "T" Then
manLine = Left(strLine, 76) & Mid(strLine, 115, 2)
Print #2, manLine
Else
Print #2, strLine
End If
End If
End If
Line Input #1, strLine
Loop
Print #2, strLine
Close #1
Close #2
End Function
The problem that i have is that once it reaches the end of the file (last line is the only occurance of a T starting line) it doesnt read the T and just ends the function. Not sure if this is because its a single character instead of a double, or because its the last file in the txt doc.
All help appreciated.
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).
Option Compare Database
Option Explicit
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
Else
If 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
Else
If smallStart = "T" Then
manLine = Left(strLine, 76) & Mid(strLine, 115, 2)
Print #2, manLine
Else
Print #2, strLine
End If
End If
End If
Line Input #1, strLine
Loop
Print #2, strLine
Close #1
Close #2
End Function
The problem that i have is that once it reaches the end of the file (last line is the only occurance of a T starting line) it doesnt read the T and just ends the function. Not sure if this is because its a single character instead of a double, or because its the last file in the txt doc.
All help appreciated.