Using Collection Objects


Objects that contain collections of objects are called collection objects. A collection object will have a plural name; for example, Channels. The objects it contains will have singular names; for example, Channel. The objects managed by the Channel Manager control do not have to be loaded or registered separately and are created by the Channel Manager.

All collection objects have an Item and Count property to make collections easy to manage.

Item is the default property for collection objects. This means that collection_object.Item(3) is the same as collection_object(3) and that both statements return the fourth object in the collection object. The first object in the collection is at index 0. Item is a read-only property that requires a subscript for the index into the collection.

Use the Set command in Visual Basic with collection objects. For example, to access a Channel object that is part of a Channels collection, use the following syntax:

Dim MyChannel
Set MyChannel = MyObject.Channels.Item(0)
Channel_Name = MyChannel.Name

to get the name of the first channel. Note that if you remove an item from the collection, you must use Set again. For example:


Dim Channels
Set Channels = MyObject.Channels
Channels.Open "Channel 1",7 
Channels.Open "Channel 2",7 
Channels.Open "Channel 3",7 
MsgBox Channels.Count
Channels(1).Close
Set Channels - MyObject.Channels
MsgBox Channels.Count

would not have the correct second channel count unless the second Set were used.

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.