Remove Method (Collection Object)
Removes an element from a Collection object.
A unique String expression that specifies a key string that can be used, instead of a positional index, to access an element of the collection. Key must correspond to the Key argument specified when the element was added to the collection.
A numeric expression that specifies the position of an element of the collection. Index must be a number from 1 through the value of the collection's .
|Exception type||Error number||Condition|
Key is invalid or not specified.
Index does not match an existing element of the collection.
See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the.) However, when possible, you should consider replacing such error control with .
This example illustrates the use of the Remove method to remove objects from ain the variable birthdays.
Dim birthdays As New Collection() birthdays.Add(New DateTime(2001, 1, 12), "Bill") birthdays.Add(New DateTime(2001, 1, 13), "Joe") birthdays.Add(New DateTime(2001, 1, 14), "Mike") birthdays.Add(New DateTime(2001, 1, 15), "Pete") ... birthdays.Remove(1) birthdays.Remove("Mike")
Following the four calls to the Add method, the Count property contains 4, element "Bill" has index value 1, and element "Pete" has index value 4.
Following the first call to Remove, Count is 3, element "Bill" is deleted, and element "Pete" has index value 3.
Following the second call to Remove, Count is 2, element "Mike" is deleted, and element "Pete" has index value 2.
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)