I fill a collection with:
....
TROVA = GIORNO & "-" & NOMINATIVO & "-" & NUMCELLULARE
SCHIAVE = RIGA & "-" & COLONNA
COLLETT.Add Key:=SCHIAVE, Item:=TROVA
....
TROVA = GIORNO & "-" & NOMINATIVO & "-" & NUMCELLULARE
debug.print TROVA
01/08/2022-ARTURO-(+39)-78678611
debug.print SCHIAVE
1-4
now i have a varc=1 and varr=4, how to return the element of colletion, based this two var?
in my case i need:
01/08/2022-ARTURO-(+39)-78678611
peraphs i can use the key of collection and match with varc&"-"&varr to find?
or i need to use a dictionary...
note:
COLLETT is a Public var
..
find in a collection by key
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: find in a collection by key
Code: Select all
Debug.Print COLLETT(varr & "-" & varc)
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: find in a collection by key
tks!!!!!!!!!
WORK!
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: find in a collection by key
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: find in a collection by key
You could use code like this:
The Remove method deletes both the key and the item.
By the way, the Dictionary object has a method Exists that returns True if the specified key exists, and False otherwise.
Code: Select all
On Error Resume Next
Itm = COLLETT(varr & "-" & varc)
On Error GoTo 0
If Itm = "" Then
' Item does not exist
Else
' Item exists
End If
By the way, the Dictionary object has a method Exists that returns True if the specified key exists, and False otherwise.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: find in a collection by key
HansV wrote: ↑14 Feb 2022, 13:22You could use code like this:
The Remove method deletes both the key and the item.Code: Select all
On Error Resume Next Itm = COLLETT(varr & "-" & varc) On Error GoTo 0 If Itm = "" Then ' Item does not exist Else ' Item exists End If
By the way, the Dictionary object has a method Exists that returns True if the specified key exists, and False otherwise.
COLLET.REMOVE (varr & "-" & varc)
Is correct?
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: find in a collection by key
Yes, but you don't need the ( )
Code: Select all
COLLET.Remove varr & "-" & varc
Best wishes,
Hans
Hans