Remove Method (Collection Object)
Removes an element from a Collection object.
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 Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.
When Remove deletes an element from a collection, it decrements the collection's Count Property (Collection Object) by one. It also decrements the Index value of every element that formerly followed the deleted element in the collection.
If an element was added to the collection without a Key, you must use its Index to remove it.
This example illustrates the use of the Remove method to remove objects from a Collection Object (Visual Basic) in the variable birthdays.
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)