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

Write only certain lines into new Text File 1

Status
Not open for further replies.

jcw5107

Technical User
Jan 31, 2007
66
US
I have a text file that each line starts with:
TC
PR
EO
FC
CK
I need to write to a new text file only the lines that start with EO, TC, or CK - AND - the very next line for each EO, TC, or CK
Below is what I'm working with...
Any suggestions or examples would be much appreciated..!!
Thanks in advance..!!
jcw5107

Sub NewUnAssignedTasks()
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Dim strLine 'As Variant
Dim strType As Variant
Dim MyString As String
Dim strImportFile As String
Dim strNewfile As String
Set db = CurrentDb
strImportFile = "D:\UPSDATA\NewTaskNos.txt"
strNewfile = "D:\UPSDATA\NewTaskNos.txt"
Open "D:\UPSDATA\NewUnAssignedTaskNos.txt" For Input As #1
Open strImportFile For Output As #2
Do Until EOF(1)
Line Input #1, strLine
If Left(strLine, 2) = "EO" _
Or Left(strLine, 2) = "TC" _
Or Left(strLine, 2) = "CK" Then
strType = strLine
Print #2, strType
End If
Loop
Close #1
Close #2
End Sub
 
Hi...

You already have your conditional statement, add code to read and write the next line.......

If Left(strLine, 2) = "EO" _
Or Left(strLine, 2) = "TC" _
Or Left(strLine, 2) = "CK" Then
strType = strLine
Print #2, strType
Line Input #1, strType
Print #2, strType
End If
 
lewds,

Man..!! "If it was a snake it would have bit me...!!"
Ha..!!
Thanks so much..! That is exactly what I needed..!!
Awesome..!!
Star for ya..!!

jcw5107
 
You may wish to consider:

[tt]If InStr("EO,TC,CK", Left(strLine, 2)) > 0 Then[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top