Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
String search & extraction from txt file
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. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
String search & extraction from txt file
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),"")) "Varun" wrote: 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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
string extraction not working. | Excel Programming | |||
Text string extraction | Excel Worksheet Functions | |||
A Macro to search a string in a Word file | Excel Programming | |||
String Extraction... | Excel Worksheet Functions | |||
Search a text file for a string | Excel Programming |