Need help accessing the matches collection returned vbscript regex

D

Dave Jenkins

I am using the vbscript 5.0 regex support - here is a snippet of the code I'm
having problems with:

dim m as integer
dim matched
dim match_coll

Set match_coll = regex.Execute( [some text string] )

' can be multiple matches in a single sentence, if global search...
For m = 1 To match_coll.Count

matched = match_coll(m)
..
..
..

During execution, I get an error on the "matched = match_coll(m)" statement
- it complains:


Runtime error '5':
Invalid procedure call or argument

Apparently it's being caused by the part of the statemnt that reads
"match_coll(m)". I figured that if match_coll were a collection, I should be
able to iterate through it by an index - why can't I? (I know I could "for
each...", but I need to be able to interrupt this loop and restart it from
where it was interrupted - I don't know how to do that with "for each")

Can anyone help? Thanks!
 
D

Dave Jenkins

--
Dave Jenkins
K5KX


Dave Jenkins said:
I am using the vbscript 5.0 regex support - here is a snippet of the code I'm
having problems with:

dim m as integer
dim matched
dim match_coll

Set match_coll = regex.Execute( [some text string] )

' can be multiple matches in a single sentence, if global search...
For m = 1 To match_coll.Count

matched = match_coll(m)
.
.
.

During execution, I get an error on the "matched = match_coll(m)" statement
- it complains:


Runtime error '5':
Invalid procedure call or argument

Apparently it's being caused by the part of the statemnt that reads
"match_coll(m)". I figured that if match_coll were a collection, I should be
able to iterate through it by an index - why can't I? (I know I could "for
each...", but I need to be able to interrupt this loop and restart it from
where it was interrupted - I don't know how to do that with "for each")

I think I see part of the problem (at least I'm getting a little further
along in the code) - it appears that collections are indexed starting with
zero, and hence when I used an index of 1 to attempt to get the first element
of a 1-element collection, I was bombing out. Do you all agree?
 
D

Dave Jenkins

Thanks, Steve, for the good advice.

I am using VBA out of PPT, and hence the posting here. I feel like I'm
having more of a VBA problem, than VBScript. You may be right, though: The
regex documentation (scanty) says that the Execute method returns a
Collection. But when I type the returned object as a Collection, it bombs at
runtime. Further, the fact that I have to index starting from 0 kind of
tells me that he's returning an array - what do you think? Aren't
collections always indexed base 1? (I do have Option Base 0 set - does that
apply to Collections?)

Thanks for lending an ear...
 

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