Несоответствие типов при попытке сортировать коллекцию - PullRequest
0 голосов
/ 17 ноября 2018

Я не могу на всю жизнь, пока я получаю несоответствие типов при сортировке коллекции, в которой уже есть объект.

Может кто-нибудь объяснить, почему произошла ошибка, ниже приведен код, который я использую для сортировки коллекции.

Private Sub SortItems(combinedItems As Collection)
    Dim counter As Integer, _
        counter2 As Integer, _
        temp As Variant, _
        tempColleciton As New Collection, _
        currentSortItem As SortItem, _
        nextSortItem As SortItem, _
        sortDirection As SortType

        sortDirection = SortOrder

    For counter = 1 To combinedItems.Count - 1
        For counter2 = counter + 1 To combinedItems.Count
            Set currentSortItem = combinedItems(counter)
            Set nextSortItem = combinedItems(counter2)
            If currentSortItem.Key > nextSortItem.Key Then
                combinedItems.Remove counter2

                If sortDirection = Ascending Then
                    combinedItems.Add nextSortItem, nextSortItem, counter 'error occurs here if Ascending
                Else
                    combinedItems.Add nextSortItem, nextSortItem, After:=counter 'error occurs here if Decending
                End If

            End If
        Next counter2
    Next counter

End Sub

1 Ответ

0 голосов
/ 17 ноября 2018

Вы пытаетесь использовать объект в качестве ключа в коллекции?

combinedItems.Add nextSortItem, nextSortItem, counter

Попробуйте использовать:

combinedItems.Add nextSortItem, nextSortItem.Key, counter
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...