SortedList: ContainsValue

ContainsValue

Determines whether a SortedList object contains a specific value.



 Public Function ContainsValue(
	  ByRef Value As Variant ) As Boolean

Parameters

Value
[ByRef] Variant. The value to locate for in the SortedList object.

Return Values

Boolean -  True if the SortedList object contains an element with the specified Value; otherwise, False.

Remarks

This method performs a linear search; therefore, the average execution time is proportional to Count. That is, this method is an O(n) operation, where n is Count.

Examples

The following code example shows how to determine whether a SortedList object contains a specific element.

Public Sub Main()
    Dim List As New SortedList
    Dim TempArray() As String
    Dim TargetArray() As DictionaryEntry
    Dim i As Long
    
    List.Add 2, "cats"
    List.Add 3, "in"
    List.Add 1, "napping"
    List.Add 4, "the"
    List.Add 0, "three"
    List.Add 5, "barn"
    
    TempArray = NewStrings("The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog")
    ReDim TargetArray(0 To 14)
    
    For i = 0 To UBound(TargetArray)
        If i <= UBound(TempArray) Then
            Set TargetArray(i) = NewDictionaryEntry(i, TempArray(i))
        Else
            Set TargetArray(i) = NewDictionaryEntry(i, "")
        End If
    Next
    
    Debug.Print "The target Array contains the following (before and after copying):"
    PrintValues TargetArray
    
    List.CopyTo TargetArray, 6
    
    PrintValues TargetArray
End Sub

Private Sub PrintValues(ByRef Arr() As DictionaryEntry)
    Dim i As Long
    
    For i = LBound(Arr) To UBound(Arr)
        Debug.Print " "; Arr(i).Value;
    Next
    
    Debug.Print
End Sub

' The code produces the following output.
'
'    The target Array contains the following (before and after copying):
'     The quick brown fox jumped over the lazy dog
'     The quick brown fox jumped over three napping cats in the barn

See Also

Project CorLib Overview

Class SortedList Overview

Contains

ContainsKey