Can't assign array result of function to an array

試著忘記壹切 提交于 2021-02-17 06:05:58

问题


I'm trying to assign array result of function to an array. It works fine, if i try to assign one element of result array to my array, but it returns error while trying to assign whole result array to my array ("Can't assign to array").

Sub test()
Dim lol(6) as Double
lol = Hehe2()
End Sub

Function Hehe2() As Double()
Dim Zliczacz(1 To 6) As Double
Zliczacz(1) = 1 / 2
Zliczacz(2) = 1 / 2
Zliczacz(3) = 1 / 2
Zliczacz(4) = 1 / 2
Zliczacz(5) = 1 / 2
Zliczacz(6) = 1 / 2
Hehe2 = Zliczacz()
End Function

回答1:


You can only assign one array to another if the receiving array is declared as dynamic and of the same type. Yours is fixed, so it won't work. You need to use:

Dim lol() as Double


来源:https://stackoverflow.com/questions/34317067/cant-assign-array-result-of-function-to-an-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!