BCX COM Interface
FOR EACH ... NEXT statement
Purpose: FOR EACH ... NEXT
iterates statements for each element in a collection.
Note well that FOR EACH ... NEXT
can be invoked only with COM/ActiveX objects
Syntax: FOR EACH Element IN Collection Statements NEXT [Element] Parameters:
|
Here is a simple example that shows how BCX COM
uses FOR EACH
to iterate
through a collection to find, in a string,
matches to a pattern.
BCX_SHOW_COM_ERRORS
(
TRUE)
'---------------[ R E S U L T S ] ------------------
'
' Match found at position 0. Match Value is 'IS1'.
' Match found at position 4. Match Value is 'is2'.
' Match found at position 8. Match Value is 'IS3'.
' Match found at position 12. Match Value is 'is4'.
'
'---------------------------------------------------
(
"is."
,"IS1 is2 IS3 is4"
)
FUNCTION
Rx$(
Pattern$, MainStr$)
DIM
vbrxAS
OBJECTDIM
MatchesAS
OBJECTDIM
RetStr$DIM
Tmp$DIM
i vbrx=
CREATEOBJECT
(
"VBScript.RegExp"
)
WITH
vbrx .Pattern=
Pattern$' Set pattern.
.IgnoreCase=
True' Set case insensitivity.
.GLOBAL=
True' Set global applicability.
END
WITH
SET
Matches=
vbrx.Execute(
MainStr$)
FOR EACH
MatchIN
Matches' Iterate Matches collection.
RetStr$=
RetStr$+
"Match found at position "
i=
Match.FirstIndex RetStr$=
RetStr$+
STR$
(
i)
+
". Match Value is '"
Tmp$=
Match.Value RetStr$=
RetStr$+
Tmp$+
"'."
+
CRLF$
NEXT
SET
Matches=
NOTHING
SET
vbrx=
NOTHING
FUNCTION
=
RetStr$END
FUNCTION