Iterating Through a List

It is often useful to perform a series of operations on every object in a list.

Visual Basic

Use the Visual Basic For Each statement to iterate through all specific objects in a list. For example:

For Each oStoredProcedure in oSQLServer.ListStartupProcedures
    Debug.Print oStoredProcedure.Name
Next
C++

You can use the GetCount and GetItemByOrd functions of a list object to iterate through all specific objects in a list. Use the following syntax for GetCount:

pObjectList->GetCount ( &lCount );

For example:

LPSQLOLESTOREDPROCEDURELIST pStoredProcedureList;
LPSQLOLESTOREDPROCEDURE pStoredProcedure;
long i, lCount;
pSQLServer->ListStartupProcedures (&pStoredProcedureList);
pStoredProcedureList->GetCount (&lCount);
for (i = 0; i < lCount; i+)
{
    pStoredProcedureList->GetItemByOrd (i, &pStoredProcedure);
    // use the specific pDatabase object
}