从函数返回对象数组 - VBA

Ped*_*tri 4 arrays excel vba function excel-vba

我需要从使用VBA创建的函数中"返回"一个对象数组.当我尝试将函数设置为数组时,它会给出一条错误消息,说

对象是必需的.

我不太习惯VBA,我无法解决这个问题.这是功能代码:

Function sortedList(listRange As Integer, tempList() As ship) As ship
   Dim temp As ship
   Set temp = Nothing

   For i = listRange - 10 To 1 Step -1

       For j = 2 To listRange - 10
            If tempList(j - 1).Arrival > tempList(j).Arrival Then
                Set temp = tempList(j - 1)
                Set tempList(j - 1) = tempList(j)
                Set tempList(j) = temp
            End If
        Next j
    Next i

    'return tempList - how?
    Set sortedList = tempList

End Function
Run Code Online (Sandbox Code Playgroud)

Ship是我创造的"阶级".tempListship我需要从函数返回的类的对象数组sortedList.

该功能有效,它只是我无法工作的返回部分.

谢谢您的帮助.如果需要更多信息,请告诉我!

Ror*_*ory 5

声明函数返回一个数组

Function sortedList(listRange As Integer, tempList() As ship) As ship()
Run Code Online (Sandbox Code Playgroud)

然后分配结果 Set

sortedList = tempList
Run Code Online (Sandbox Code Playgroud)