我在以下子测试()中收到“按引用参数类型不匹配”错误:
Public Function GetOtherDict(k As String, dict As Dictionary) As Dictionary
Dim otherDict As New Dictionary
curItem = dict.Item(k)
otherDict.Add curItem, curItem
Set GetOtherDict = otherDict
End Function
Public Sub Test()
Dim dict As New Dictionary
dict.Add "a", 1
dict.Add "b", 2
For Each k In dict.Keys
Dim otherDict As Dictionary
Dim curKey As String
curKey = k
Set otherDict = GetOtherDict(k, dict)
Next
End Sub
当我GetOtherDict
用curKey
参数而不是参数调用函数时k
,错误消失了。
你能告诉我为什么我需要这个多余的声明吗?