Collection Object.
Removes a member from a Collection object.
object.Remove(index)
The Remove method syntax has the following object qualifier and part:
Part |
Description |
object |
Required. An object expression that evaluates to an object in the Applies To list. |
index |
Required. An expression that specifies the position of a member of the collection. If a numeric expression, index must be a number from 1 to the value of the collection’s Count property. If a string expression, index must correspond to the key specified when the member being referred to was added to the collection. |
If the value provided as index does not match any existing member of the collection, an error occurs.
Add Method.
This example illustrates the use of the Remove method to remove objects from a Collection object, MyClasses. This code removes the object whose index is 1 on each iteration of the loop.
Dim NumNum = 1 To MyClasses.Count MyClasses.Remove 1 ' Remove the first object each time ' through the loop until there are ' no objects left in the collection.Num
The following example shows how to use the Remove method to delete items from a Collection object colThings. User-defined collections are indexed numerically. For a user-defined collection, the default base index is 1. Since collections are automatically reindexed when an item is removed, the following code removes the first member on each iteration.
Note that you can use the For Each...Next syntax to manipulate items in a collection.
For Each objMine in colThings objThings.Remove 1objMine