Count Property (Visual Basic)

Applies To

Collection Object.

Description

Returns the number of members in a collection. Not available at design time; read-only at run time.

Syntax

object.Count

The object qualifier is an object expression that evaluates to an object in the Applies To list.

See Also

Add Method, Item Method, Remove Method.

Example

This example uses the Collection object’s Count property to specify how many iterations are required to remove all the elements of the collection called MyClasses. When collections are numerically indexed, the base is 1 by default. Since collections are reindexed automatically when a removal is made, the following code removes the first member on each iteration.


Dim NumNum = 1 To MyClasses.Count    ' Remove name from the collection.
    MyClasses.Remove 1    ' Default collection numeric indexes    ' begin at 1.

See also the Count property (Microsoft Access) example.