String search & extraction from txt file

V

Varun

Folks,

I want to search a particular file (that is readable in notepad) for a
string. Here's what the contents of the file look like (the file has stuff
below and after the contents identified below).

$$attribute( "ARTWORK_DEFINITION_IDENTIFIER", "", , , , [0, 0]);
$$attribute( "ARTWORK_01_LAYER_DEFINITION", "PAD_1,SIGNAL_1", , , , [0, 0]);
$$attribute( "ARTWORK_02_LAYER_DEFINITION", "SIGNAL_2", , , , [0, 0]);
$$attribute( "ARTWORK_03_LAYER_DEFINITION", "POWER_1", , , , [0, 0]);
$$attribute( "ARTWORK_04_LAYER_DEFINITION", "POWER_2", , , , [0, 0]);
$$attribute( "ARTWORK_05_LAYER_DEFINITION", "POWER_3", , , , [0, 0]);
$$attribute( "ARTWORK_06_LAYER_DEFINITION", "PAD_2,SIGNAL_3", , , , [0, 0]);

I'd like to store SIGNAL_1, SIGNAL_2, POWER_1, POWER_2, POWER_3, SIGNAL_3
into an array. How can I go about doing this? The other versions of this
file can and will included additional ARTWORK layers i.e. it's not limited to
layer_06 and therefore it can go upto like 10 or 20 or 32 so need a way to
implement a For loop.

Here's what I have got so far:

Sub search_geoms_ascii()
Dim searchVar As String
Open "geoms_ascii" For Input As #1
searchVar = "ARTWORK_DEFINITION_IDENTIFIER"
Do While Not EOF(1)
Line Input #1, Data
If InStr(15, Data, searchVar) Then

'above line finds ARTWORK_DEFINITION_IDENTIFIER

'loop

'go to the following line now

'store SIGNAL_1 from this line into array

'repeat for all remaining lines

Else
MsgBox "Having problem processing geoms_ascii, exiting"
Exit Sub
End If
End Sub

Any pointers will be appreciated.

Thanks.
 
J

Joel

Use the split function to put your data into an array. The split works just
like Text-To-Columns


Sub search_geoms_ascii()
Dim searchVar As String
Open "geoms_ascii" For Input As #1
searchVar = "ARTWORK_DEFINITION_IDENTIFIER"
Do While Not EOF(1)
Line Input #1, Data
'Split line around commas
MyLine = split(Data,",")
'Get second item which contains feature type
MyType = MyLine(1)
'Remove the double quote (chr(34)) from the type
Mytype = Trim(Replace(MyType,chr(34),""))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top