Count Property (CDONTS Messages Collection)

The Count property returns the number of Message objects in the collection, or a very large number if the exact count is not available. Read-only.

Syntax

collMessages.Count 
 

Data Type

Long

Remarks

The use of the Item property in conjunction with the Count property in a large collection can be seen in the following example.

Example

This code fragment searches for a Message object with subject "Bonus":

Dim i As Integer ' loop index / object counter 
Dim collMessages As Messages ' assume collection already provided 
Dim objMessage As Message 
If collMessages Is Nothing Then 
    MsgBox "Messages collection object is invalid" 
    ' Exit 
ElseIf 0 = collMessages.Count Then ' collection is empty 
    MsgBox "No messages in collection" 
    ' Exit 
End If 
' look for message about "Bonus" in collection 
For i = 1 To collMessages.Count Step 1 
    Set objMessage = collMessages.Item(i) 
    ' or collMessages(i) since Item is default property 
    If objMessage Is Nothing Then ' end of collection 
        MsgBox "No such message found in collection" 
        Exit For 
    ElseIf 0 = StrComp(objMsg.Subject, "Bonus") Then 
    ' or objMessage since Subject is default property 
        MsgBox "Desired message is at index " & i 
        Exit For 
    End If 
Next i