我有两个数组,我试图提取其中的公共(public)值,函数 findUniques 应该返回连接并用逗号分隔的字符串(它们是名称)。我想我很接近,但我找不到出了什么问题。我在第 10 行出现错误

Function findUniques(astrArray1() As String, astrArray2() As String) As String

    Dim blnMP5 As Boolean
    blnMP5 = False
    Dim counter1 As Long
    Dim counter2 As Long

    For counter1 = LBound(astrArray1) To UBound(astrArray1)
        For counter2 = LBound(astrArray1) To UBound(astrArray2)
            If astrArray1(counter1) = astrArray2(counter2) Then
                blnMP5 = False
                If blnMP5 = True Then
                    findUniques() = findUniques & "," & "astrArray1()"
                End If
            End If
        Next counter2
    Next counter1

End Function

最佳答案

声明一个变量来保存您正在构建的字符串

    Dim tempString as string
并在第 10 行添加此内容
    tempString = tempString & "," &  astrArray1(counter1)
最后
    findUniques = tempString
End function

关于arrays - 赋值左侧的函数调用必须返回 Variant 或 Object,在两个数组中找到公共(public)值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16157111/

10-10 09:42