Collecting Your Objects

One big advantage of using classes is that they lend themselves very nicely to using the Collection object. You've seen collection objects earlier in the book, such as Workbooks and Worksheets. The Collection object is an easy-to-use, generic object that you can use to contain a group of objects.

The advantage of using a collection of objects will be more apparent later on when you look at reading/writing to external data sources. For now, imagine a scenario in which you need to hold more than one Loan object in memory. By using the Collection object and classes, this is easily achieved.

Listing 11.6 demonstrates how to use the Collection object. The first procedure, TestCollection-Object, calls the CollectLoanObjects procedure to retrieve a Collection object that contains all of the loans in the list starting just below the range named LoanListStart. Then TestCollectionObject iterates through all of the loans in the Collection object and outputs the loan number and payment amount to the Immediate window.

0 0

Post a comment