gpt4 book ai didi

arrays - 赋值左侧的函数调用必须返回 Variant 或 Object,在两个数组中查找公共(public)值

转载 作者:行者123 更新时间:2023-12-01 02:26:13 24 4
gpt4 key购买 nike

我有两个数组,我试图提取其中的公共(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

最佳答案

您的错误在这一行:

findUniques() = findUniques & "," & "astrArray1()"

您正在尝试为函数调用分配一个值,这没有意义。

您应该在函数的开头声明一个变量并继续添加该变量并最终返回它:
Function findUniques(astrArray1() As String, astrArray2() As String) As String

Dim blnMP5 As Boolean
blnMP5 = False
Dim counter1 As Long
Dim counter2 As Long
Dim uniquesString as String = ""

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
uniquesString = uniquesString & "," & "astrArray1()"
End If
End If
Next counter2
Next counter1

End Function

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com