Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
string extraction not working. SteveDB1 Excel Programming 4 September 2nd 08 09:46 PM
Text string extraction Geoffric Excel Worksheet Functions 5 December 19th 07 07:18 PM
A Macro to search a string in a Word file Farooq Sheri Excel Programming 2 January 27th 06 04:53 AM
String Extraction... iceberg27 Excel Worksheet Functions 2 October 15th 05 04:28 AM
Search a text file for a string crazybass2 Excel Programming 2 June 21st 05 12:53 AM


All times are GMT +1. The time now is 09:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"