的StackOverflow,
以下子程序旨在:
当代码成功运行时,它无法将计算应用于作为参数传递的字典中的每个值(ByRef)。
请说明我可能出错的地方。我还尝试将其写为递归子例程但没有成功。
Private Sub ApproxiamteGeometricReturns(ByRef LogReturnDictionary As Variant)
For Each Item In LogReturnDictionary.Items
If TypeName(Item) = "Double()" Then
For Each i In Item
i = ApproximateGeometricReturn(i)
Next
Else
Item = ApproximateGeometricReturn(Item)
End If
Next
End Sub
任何建议都会受到热烈欢迎。感谢。
答案 0 :(得分:0)
Private Sub ApproxiamteGeometricReturns(ByRef LogReturnDictionary As Variant)
For Each keyName In LogReturnDictionary.Keys
If TypeName(LogReturnDictionary(keyName)) = "Double()" Then
Dim arr As Variant: arr = LogReturnDictionary(keyName)
Dim index As Integer
For index = LBound(arr) To UBound(arr)
arr(index) = ApproximateGeometricReturn(arr(index))
Next
LogReturnDictionary(keyName) = arr
Else
LogReturnDictionary(keyName) = ApproximateGeometricReturn(LogReturnDictionary(keyName))
End If
Next
End Sub