Returns or sets the zero-based index of the current match when there are multiple matches.
Syntax
[form!]VSFlexString.MatchIndex[ = value As Long ]
Remarks
Looking for a pattern in a string may result in several matches. Setting MatchIndex to a value between zero and MatchCount - 1 defines the current match to be used by the MatchString, MatchStart, and MatchLength properties.
For example:
fs.Text = "The quick brown fox jumped over the lazy dog."
fs.Pattern = "[qbf][a-z]*"
Debug.Print "Matches found: "; fs.MatchCount
For i = 0 To fs.MatchCount - 1
fs.MatchIndex = i
Debug.Print " "; fs.MatchString; fs.MatchLength
Next
This code produces the following output:
Matches found: 3
quick 5
brown 5
fox 3
Note that you can also specify the index as an optional parameter when referring to these properties. Doing so will automatically set the MatchIndex property to the new index. For example:
fs.Text = "The quick brown fox jumped over the lazy dog."
fs.Pattern = "[qbf][a-z]*"
Debug.Print "Matches found: "; fs.MatchCount
For i = 0 To fs.MatchCount - 1
Debug.Print " "; fs.MatchString(i); fs.MatchIndex
Next
This code produces the following output:
Matches found: 3
quick 0
brown 1
fox 2
Data Type
Long