O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Collection.Count Property

Class

Microsoft.VisualBasic.Collection

Syntax

                  objectvariable.Count
objectvariable (required; Collection Object)

Object variable referring to a Collection object

Description

Returns an Integer containing the number of members in the collection

Rules at a Glance

Collections are 1-based; that is, the index of the first element of a collection is 1. In contrast, arrays are 0-based; the index of the first element of an array is 0.

Example

For i = 1 To colMyCollection.Count
    Set colSubCollection = colMyCollection.Item(CStr(i))
    MsgBox colSubCollection.Item("Name")
    Set colSubCollection = Nothing
Next i

Programming Tips and Gotchas

Because collections are 1-based, you can iterate the members of a collection by using index values ranging from 1 to the value of objectvariable .Count.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required