Name
Collection.Add Method
Class
Microsoft.VisualBasic.Collection
Syntax
objectvariable.Add item[,key, before, after]
-
objectvariable(required; Collection Object) The name of the Collection object to which an item is to be added
-
item(required; Object) An object of any type that specifies the member to add to the collection
-
key(optional; String) A unique string expression that specifies a key string that can be used, instead of a positional index, to access a member of the collection
-
before(optional; Object) The member to be added placed in the collection before the member identified by the
beforeargument (more on this in Section )-
after(optional; Object) The member to be added placed in the collection after the member identified by the
afterargument (more on this in Section )
Description
Adds an object to a collection
Rules at a Glance
If you do not specify a
beforeoraftervalue, the member is appended to the end of the collection (in index order).If you do not specify a
keyvalue, you cannot access this member using akey, but instead must access it either by using its ordinal number or by enumerating all the members of the collection with theForEach...Nextconstruct. Thus, keys are highly recommended.The
beforeorafterargument can refer to an index or a key. For instance, consider the following code:Dim c As New Collection( ) c.Add("donna", "111") c.Add("steve", "222") 'c.Add("bill", "333", "222") 'c.Add("bill", "333", 2) MsgBox(c.Item(2))Both of the commented lines ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access