Visual Basic Language Reference |
|
Removes a member from a Collection object.
Public Overloads Sub Remove(ByVal { Key As String | Index As Integer })
Parameters
- Key
- 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.
- Index
- 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 argument specified when the member referred to was added to the collection.
Exceptions/Errors
Exception type |
Error number |
Condition |
ArgumentException |
5 |
Key is invalid or not specified. |
IndexOutOfRangeException |
9 |
Index does not match an existing member of the collection. |
Remarks
If Index doesn't match an existing member of the collection, an error occurs.
Example
This example illustrates the use of the Remove method to remove objects from a Collection object, birthdays
.
Dim birthdays As New Collection()
birthdays.Add(New DateTime(2001, 1, 12), "Bill")
birthdays.Add(New DateTime(2001, 1, 13), "Joe")
birthdays.Remove(
1)
birthdays.Remove(
"Joe")
See Also
Add Method | ArgumentException | IndexOutOfRangeException
Applies to
Collection Object