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")FUNCTIONRx$(Pattern$, MainStr$)DIMvbrxASOBJECTDIMMatchesASOBJECTDIMRetStr$DIMTmp$DIMi vbrx=CREATEOBJECT("VBScript.RegExp")WITHvbrx .Pattern=Pattern$' Set pattern..IgnoreCase=True' Set case insensitivity..GLOBAL=True' Set global applicability.ENDWITHSETMatches=vbrx.Execute(MainStr$)FOR EACHMatchINMatches' 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$NEXTSETMatches=NOTHINGSETvbrx=NOTHINGFUNCTION=RetStr$ENDFUNCTION