I have a list of items in a file (data.txt) with titles as shown here in this example:
BASE
1. Cost
2. Weight
3. etc…
SLAB
1. Volume
2. Mass
3. etc…
MT_FRAME
1. Cost
2. etc…
I have another file (specifics.txt) that contains the titles of the only items that I’m interested in, for example:
SLAB
BASE
MT_FRAME
The titles in “specifics.txt” are not arranged in any particular order. I want to get the information from “data.txt” based on the order that is listed in “specifics.txt”. I know how to do this using VBA. The problem is that I don’t want to do multiple sweeps through “data.txt” for each title printed in “specifics.txt”. Rather, I’m looking for a solution using a single sweep through the file “data.txt”. The main reason for this is because “data.txt” can be thousands of records long, ie, with hundred of titles, and I will be looking for probably 10 specific titles.
Right now I have the following code that does multiple sweeps searching for the title “SLAB”:
R = 1
C = 1
f = FreeFile
Do While Not EOF(f)
Line Input #f, strLine
If blnFoundName Then
‘ Get category value
intPos2 = InStr(strLine, “1.”)
If intPos2 > 0 Then
ActiveCell.Cells(R, C + 1) = strLine
C = C + 1
blnFoundName = False
End If
Else
‘ Check for the occurance of the title “SLAB”
intPos1 = InStr(strLine, “SLAB”)
If intPos1 > 0 Then
blnFoundName = True
R = R + 1
End If
End If
Loop