返回值中的数组(0)是无效的
Function Distinct(a() As Long) As Long()
Dim i As Long
Dim ii As Long
Dim b() As Long
Dim bExist As Boolean
ReDim b(0) As Long
For i = LBound(a) To UBound(a)
bExist = False
For ii = LBound(b) To UBound(b)
If b(ii) = a(i) Then bExist = True: Exit For
Next
If bExist = False Then
ReDim Preserve b(UBound(b) + 1) As Long
b(UBound(b)) = a(i)
End If
Next
Distinct = b
End Function
Function Distinct(a() As String) As String()
Dim i As Long
Dim ii As Long
Dim b() As String
Dim bExist As Boolean
ReDim b(0) As String
For i = LBound(a) To UBound(a)
bExist = False
For ii = LBound(a) To UBound(a)
If b(ii) = a(i) Then bExist = True: Exit For
Next
If bExist = False Then
ReDim Preserve b(UBound(b) + 1) As String
b(UBound(b)) = a(i)
End If
Next
Distinct = b
End Function