Text file to array for searching

  • Thread starter christophercbrewster via OfficeKB.com
  • Start date
C

christophercbrewster via OfficeKB.com

I have some code working quite well but it includes some clunky code that I'd
like to do in a better way. There's a text file containing a tab-delimited
table of strings. The way it works now is to copy the file contents into a
Word scratch document and convert the tabbed table to a Word table. Then it
searches for a flag in column 1 and uses strings in columns 2 and 3 to do
some processing.

It seems that the real way to do this is to split the tabbed table to a 2-D
array. Then search the elements to perform this sequence:

1. Look for the flag string in column 1
2. When the flag is found, change that element's value to empty
3. Read the values of elements 2 and 3 in the same row
4. [further processing]
5. Loop to find next flag

So my questions are:

- Is there a good way to make a tabbed text table into a 2-D character array,
without having to use Word's table facility?

- Is there a good way to quickly search an array for an element and then work
with related elements? It would be nice to do this without a loop that
increments through the rows and does "if element value equals search string,
then do such-and-such". I'd rather do something that's closer to "find the
next flag and do such-and-such".

Thanks for advice.

--
Christopher Brewster
Lockheed Martin, Eagan MN

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200812/1
 
C

Cindy M.

Hi Christophercbrewster,
- Is there a good way to make a tabbed text table into a 2-D character array,
without having to use Word's table facility?
I don't know of any functions that will return 2-D arrays. But the SPLIT
function will return a 1-D array, so you could make an array of arrays, then do
something with that. It would certainly be faster than parsing a Word table in
the Word object model.
- Is there a good way to quickly search an array for an element and then work
with related elements? It would be nice to do this without a loop that
increments through the rows and does "if element value equals search string,
then do such-and-such". I'd rather do something that's closer to "find the
next flag and do such-and-such".
What VBA offers is limited, I think, in comparison to the .NET Framework.

You could set up a User defined Type, then create an array of the individual
Type objects.

You could create a Collection. The advantage of a Collection over an array is
that you can use the "Key" value to "look up" individual members.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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