Skip to main content
3 of 4
added some more answer.
Malachi
  • 29.1k
  • 11
  • 87
  • 188

can't you just change this

For Each item In mCollection
    If IsObject(item) And Not compareByDefaultProperty Then
        If item Is itemToSearchFor Then
            Contains = True
            Exit Function
        End If
    Else
        If item = itemToSearchFor Then
            Contains = True
            Exit Function
        End If
    End If
Next item

to this

For Each item In mCollection
    If  item = itemToSearchFor Then
        Contains = True
        Exit Function
    Else If item Is itemToSearchFor And Not CompareByDefaultProperty Then
        Contains = True
        Exit Function
    End If
Next item

you would get rid of one level of nesting.

I think that if you did it this way you could even get rid of the CompareByDefaultProperty flag from this function.


I am not really sure what the `CompareByDefaultProperty` flag is doing here, I would think that if there was a Default property to compare that you would exit the function right there if that is true and use a different function to compare the default properties.

am I missing something?


down a little bit you have some nested if statements again that I think you could un-nest a little bit

    For Each item In mCollection
        If IsEmpty(result) Then
            result = item
        Else
            If item < result Then
                result = item
            End If
        End If
    Next item

so like this instead

    For Each item In mCollection
        If IsEmpty(result) Then
            result = item
        Else If item < result Then
            result = item
        End If
    Next item

that will do the same thing with less nesting.

this can be done in both the Min and Max functions

Malachi
  • 29.1k
  • 11
  • 87
  • 188