J
Jim S.
Greetings,
Is there an elegent way to check if a specific, named
object is a (current) member of a collection? I'd like to
be able to say, for example:
If myCollection.IsMember("someKey") Then
...
Else
...
End If
I know I can try to access the member, trapping the "The
item with the specified name wasn't found" error and
branching off of that, such as:
Err.Clear
On Error Resume Next
Set myObject = myCollection("someKey")
If Err.Number = &H80070057 Then
...
ElseIf Err.Number <> 0 Then
MsgBox ("Error " & Err.Number & _
": " & Err.Description)
Exit Sub
End If
On Error GoTo 0
but that seems somewhat ugly. I suppose I could also do:
found = False
For Each memberObject In myCollection
If memberObject.Name = "someKey" Then
found = True
Exit For
End If
Next
but that seems ugly too. Am I missing something obvious?
Thanks,
Jim S.
Is there an elegent way to check if a specific, named
object is a (current) member of a collection? I'd like to
be able to say, for example:
If myCollection.IsMember("someKey") Then
...
Else
...
End If
I know I can try to access the member, trapping the "The
item with the specified name wasn't found" error and
branching off of that, such as:
Err.Clear
On Error Resume Next
Set myObject = myCollection("someKey")
If Err.Number = &H80070057 Then
...
ElseIf Err.Number <> 0 Then
MsgBox ("Error " & Err.Number & _
": " & Err.Description)
Exit Sub
End If
On Error GoTo 0
but that seems somewhat ugly. I suppose I could also do:
found = False
For Each memberObject In myCollection
If memberObject.Name = "someKey" Then
found = True
Exit For
End If
Next
but that seems ugly too. Am I missing something obvious?
Thanks,
Jim S.