devxlogo

Remove an Object From a Collection When the Index and Key Are Unknown

This can be done by using the is operator. Here is a simple function demonstrating this method:

 Public Function RemoveObject(Collection As Collection, Object As Object)Dim vTemp As ObjectDim Index As Integer    Index = 1    For Each vTemp In Collection        If vTemp Is Object Then            Collection.Remove Index        Else            Index = Index + 1        End If    NextEnd FunctionIf there is only a single instance in the collecion, you can add an exit for:Public Function RemoveObject(Collection As Collection, Object As Object)Dim vTemp As ObjectDim Index As Integer    Index = 1    For Each vTemp In Collection        If vTemp Is Object Then            Collection.Remove Index            Exit For        Else            Index = Index + 1        End If    NextEnd Function

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Seasoned Architects Evaluate New Tech

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.