This recipe will describe how to implement a mechanism that is able to execute any operation for objects of any class repeatedly, until a condition is met or until the whole queue of objects is processed. The condition can be any expression that results in a Boolean value.
Create a new function library (for instance, cls.Iterator.vbs
), and associate it with your test. In this recipe, we shall use the code from the previous recipe, Implementing function pointers.
Proceed with the following steps:
In the function library, write the following code:
Class Iterator Public Default Function Run(ByRef oCollection, _ ByRef ptrFunction, _ ByVal dicArgs, _ ByVal sExitCondition) Dim count, items, ix, str, dicResults 'Create a Dictionary to store the results for each iteration Set dicResults = CreateObject("Scripting.Dictionary") 'Get the collection count...