Re: Checking for a named member of a collection?
From: onedaywhen (onedaywhen_at_fmail.co.uk)
Date: 04/16/04
- Next message: Tushar Mehta: "Re: Charting changes in altitude"
- Previous message: mqfnun_at_ed.shawcable.net: "Sisters Handjob 144"
- Next in thread: Tushar Mehta: "Re: Checking for a named member of a collection?"
- Maybe reply: Tushar Mehta: "Re: Checking for a named member of a collection?"
- Reply: onedaywhen: "Re: Checking for a named member of a collection?"
- Messages sorted by: [ date ] [ thread ]
Date: 16 Apr 2004 04:07:39 -0700
What I usually do is:
Set myObject = Nothing
On Error Resume Next
Set myObject = myCollection("someKey")
On Error Goto 0
If myObject Is Nothing Then
'Handle missing member
End If
' code continues...
--
"Jim S." <anonymous@discussions.microsoft.com> wrote in message news:<1a57301c42322$62bc8a00$a601280a@phx.gbl>...
> 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.
- Next message: Tushar Mehta: "Re: Charting changes in altitude"
- Previous message: mqfnun_at_ed.shawcable.net: "Sisters Handjob 144"
- Next in thread: Tushar Mehta: "Re: Checking for a named member of a collection?"
- Maybe reply: Tushar Mehta: "Re: Checking for a named member of a collection?"
- Reply: onedaywhen: "Re: Checking for a named member of a collection?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|