F
Fool
I think my problem is best explained without code, but I will provide
code if anyone thinks it might help.
My Goal: To search for several different strings in a document, and
then store all matches to each string in a collection of ranges.
My Solution: I have a Main sub that:
* Defines a search string and a collection
* Passes the search string and collection (both by reference)
to a Search sub
The Search sub then:
* Finds all ranges matching that string
* Adds the matched ranges to the collection.
* Exits when no more matches are found.
Control passes back to the Main sub, which changes the search string
and calls Search again. Finally, when all search strings are done, all
ranges in the collection are printed to a text file.
OK, here's the problem.
The Search function prints every "hit" to the debug window just before
it adds that hit to the collection - so I can see that it's grabbing
the appropriate ranges. And it does. They're all different and they
all look right.
However, when the program finally prints the collection's range text
to a text file, ranges are duplicated. For example, if I searched for
C*T in one search, and then searched for H*T on the next search, I'll
see things like this in the debug window:
CAT
COT
COAT
HAT
HOT
HOST
However, when the range text from the collection is printed out at the
end, I see this:
COAT
COAT
COAT
HOST
HOST
HOST
I have used collections and ranges before with no troubles, but I have
never passed them back and forth by reference. I wonder if this may be
the problem.
If a likely problem jumps out at you, please post. Otherwise I'll post
code and see if that helps.
Thank you kindly, in advance!
Fool
code if anyone thinks it might help.
My Goal: To search for several different strings in a document, and
then store all matches to each string in a collection of ranges.
My Solution: I have a Main sub that:
* Defines a search string and a collection
* Passes the search string and collection (both by reference)
to a Search sub
The Search sub then:
* Finds all ranges matching that string
* Adds the matched ranges to the collection.
* Exits when no more matches are found.
Control passes back to the Main sub, which changes the search string
and calls Search again. Finally, when all search strings are done, all
ranges in the collection are printed to a text file.
OK, here's the problem.
The Search function prints every "hit" to the debug window just before
it adds that hit to the collection - so I can see that it's grabbing
the appropriate ranges. And it does. They're all different and they
all look right.
However, when the program finally prints the collection's range text
to a text file, ranges are duplicated. For example, if I searched for
C*T in one search, and then searched for H*T on the next search, I'll
see things like this in the debug window:
CAT
COT
COAT
HAT
HOT
HOST
However, when the range text from the collection is printed out at the
end, I see this:
COAT
COAT
COAT
HOST
HOST
HOST
I have used collections and ranges before with no troubles, but I have
never passed them back and forth by reference. I wonder if this may be
the problem.
If a likely problem jumps out at you, please post. Otherwise I'll post
code and see if that helps.
Thank you kindly, in advance!
Fool