
Collection.Count Property | 201
The Language
Reference
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Usage at a Glance
• If you do not specify a before or after value, the member is appended to the end
of the collection (in index order).
• If you do not specify a
key value, you will only be able to access the item by posi-
tion or by iteration using the
For Each...Next statement.
• The before or after argument can refer to an index or a key. For instance,
consider the following code:
Dim someNames As New Collection( )
someNames.Add("Donna", "111")
someNames.Add("Steve", "222")
someNames.Add("Bill", "333", "222")
MsgBox(someNames.Item(2))
This code adds “Bill” just before “Steve.” The following statement could also be
used to achieve the same ordering of items.
someNames.Add("Bill", "333", 2)
• Key values must be unique, or an error occurs.
• You can use named parameters to add items.
unitedStates.Add(Key:="MT", Item:="Montana")
Version Differences
Visual Basic 2005 adds support for generics to several collection-style classes. Generics
are discussed in Chapter 10.
See Also
Collection Class, Collection.Count Property, Collection.Item Property, Collection.
Remove Method
Collection.Count Property
Class
Microsoft.VisualBasic.Collection
Syntax
Dim result As Integer = objectVariable.Count
objectVariable (required; Collection)
The instance of a
Collection ...