Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FIND IN DICTIONARY WHITOUTH loop 1

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
425
IT
Code:
...
 Set DICT = CreateObject("Scripting.Dictionary")
    DICT.RemoveAll

    For K = 0 To UBound(STRDBROWS, 2)
        ARR_FESTIVI(K) = STRDBROWS(0, K) & ANNO & "-" & STRDBROWS(1, K)
        KY = STRDBROWS(0, K) & ANNO
        ITM = STRDBROWS(1, K)
        DICT.Add KY, ITM
    Next K
...

now how to find by key in DICTIONARY, and return the related item?
 
TKS, bro.

How to check if item not exists based key?
 
By using ContainsKey() and ContainsValue() methods, we can check whether the specified key/value elements exist in the dictionary or not. In case, if it exists these methods will return True otherwise False.

If that's implemented in whatever version you is.
 
>If that's implemented in whatever version you is.

Sal21 is using a VBScript dictionary in VB6. It does not have ContainsKey() or ContainsValue() methods

But it isn't too hard to craft one, as long as we remember a minor quirk of the Dictionary object (which is that referencing a non-existent key silently creates that key ...)

Code:
[COLOR=blue]Public Function ContainsKey(Dict As Object, Key As Variant) As Boolean
    Dim oldcount As Long
    oldcount = Dict.Count
    If Dict.Item(Key) <> "" And Dict.Count = oldcount Then
        ContainsKey = True
    Else
        Dict.Remove (Key)
    End If
End Function[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top