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!

Reformat Text File 2

Status
Not open for further replies.

jcw5107

Technical User
Jan 31, 2007
66
US
I have a text file that needs a bunch of "junk" removed from it before I import it into my d/base...
There are 3 types of lines that I need -
1. Any line that starts with "N#*"
2. Any line that starts with "Acc*"
3. Any line that the 1st character starts at position 13

The text file is generated from our mainframe system and has all the header info, page numbers, employee info, etc..
The core data that I need is in a fixed width format, just need to clean all the other stuff out. The biggest problem I'm having is printin' out the lines that don't have a character (blank spaces) until the 13th position from the left.
Below is an example of what I'm working with...
Any suggestion or examples would be the huckleberry..!!
Thanks in advance..!!
jcw5107

Sub deletestuff()
Dim strLine 'As Variant
Dim strType As Variant
Dim strImportFile As String
strImportFile = "D:\UPSDATA\ASSIGNEDTASKS.txt"
Open "D:\UPSDATA\ASSIGNED TASKS SUMMARY.txt" For Input As #1
Open strImportFile For Output As #2
Do Until EOF(1)
Line Input #1, strLine
If Left(strLine, 4) Like "N###*" _
Or Left(strLine, 3) Like "Acc*" _
Or left(strLine, 13) <> " " Then
strType = strLine
Print #2, strType
End If
Loop
Close #1
Close #2
End Sub
 
something like this ?
If Left(strLine, 4) Like "N###" _
Or Left(strLine, 3) = "Acc" _
Or Left(strLine, 13) Like Space(12) & "?" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

YES..!!
Just like that..!!
Thank you so much..!!!!!
Star for you..!!
jcw5107
 
PHV,

I need to take this one step further...
with same text file, on each line, I need to delete/remove text from position 98 on...
Position 98 on the text file is a Number and will always be in the same place when we "download" new text files from our mainframe system. I just don't need the text on each line from position 98 on..
Any examples or suggestion...?
I just can't seem to get it to work myself or find a post that fits my needs...!!
Thanks in advance.. Again..!!
jcw5107
 
Hi..

Print #2, Left(strType,97)

This should net you the first 97 charactors of the selected string.

Hope this helps......
 
Lewds,

Awesome..!!
Thank you that did the trick...!
I love it...!!
Thanks..!
jcw5107
 
What I would do is
1)Create a link in my access Db to this text file.
2)Create a query with this Sql

Code:
Select Left(myfieldname,97)
from ASSIGNEDTASKS 
where 
Left(myfieldname, 4) Like "N###" 
Or Left(myfieldname, 3) = "Acc" 
Or Left(myfieldname, 12) = Space(12)

Code:
Sub deletestuff()
docmd.Transfertext acExportFixed ,"ASSIGNEDTASKS Link Specification","myQueryName" ,"D:\UPSDATA\ASSIGNED TASKS SUMMARY.txt"
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top