The TitleMatch object implements the following PropertyGet statements to make standard properties and methods of the private m_items collection available to the LitCritC objects.
The Count property is not used by the CML/LitCrit application. The code that copies the members of the m_items collection into the ListView control on the Choose Title dialog box uses the enumerator provided by the For…Next statement enabled by the collection object's NewEnum property. Following is a code fragment that shows you how the Count property of the collection object can be used instead of the NewEnum property.
Dim objSearchCML As New TitleMatch
Dim Item As MSComctlLib.ListItem
Dim subItem As MSComctlLib.ListItem
objSearchCML.LoadCollection txtTitle.Text, txtAuthors, optMedia(SelectedMedia).Tag, Logon, Server
For Counter = 1 to objSearchCML.Count
With objSearch.Item(Counter)
Set Item = lvwSearch.ListItems.Add()
Item.SmallIcon = .ReviewStatus
Set Item.Tag = objSearch.Item(Counter)
Item.Text = .Title
Item.SubItems(1) = .Authors
Item.SubItems(2) = .MediaType
Item.SubItems(3) = .Published
End With
Next
The purpose of the Item property is to make the Item method of the m_items collection object available to the CML/LitCrit application. At this time this property is not used by the application. The following lines from the code fragment in the Count topic shows you how the Item property can be used. The Counter value is the numeric value of the index.
For Counter = 1 to objSearchCML.Count
With objSearch.Item(Counter)
The parameter passed to the TitleMatch.Index property can be a numeric or a string value. A numeric Index specifies the position of a member (Item) in the collection and it must be a number from 1 to the value of the collection's Count property. Passing a string expression as an index locates the member of the collection by the key argument specified when the member referred to was added to the collection.
The NewEnum property returns the collection's IEnumVARIANT interface that allows the For…Next statement to iterate through the m_items collection. You can't write an enumerator in Visual Basic, but since the m_items object is based on the Collection object, the enumerator of the Collection object knows how to enumerate the items (FoundTitle objects) that the m_items collection is holding. The code in the cmdFind_Click event of the frmChooseTitle (the Choose Title dialog box) uses For…Next, enabled by the NewEnum property. The code in the cmdFind_Click event of frmChooseTitle shows how the _NewEnum method is used to implement the For…Next statement.
To make the NewEnum property work properly
Important In order for your collection classes to work with For Each … Next, you must provide a hidden NewEnum method with the correct procedure ID.
The Microsoft® Visual Studio® product documentation contains detailed information about working with the Collection object.