1
我有兩個不同的函數需要訪問同一個數組(該數組不是常數;只要函數在表單中的某個單元格內使用,它就會被編輯和追加)。重用函數數組
我想使這個數組可用於他們兩個。該數組需要是多維的(或者是一個可以包含多個元素的UDT,就像我在下面的代碼中嘗試的那樣),並且它需要能夠動態調整大小。這裏有一些示例代碼(編輯了一下),但它似乎不能正常工作。
Option Base 1
Private Type PathsArray
Nodes() As String
End Type
' Instantiate the global array
Dim Paths(1 To 1) As PathsArray
Function SETTWENTY()
' Increase size of the array, preserving the current elements already inside it
ReDim Preserve Paths(1 To UBound(Paths) + 1)
' Make the inner array be 20 elements long
ReDim Preserve Paths(UBound(Paths)).Nodes(1 to 20)
' Return something random
GETPATH = UBound(Paths)
End Function
Function SETTHIRTY()
' Increase size of the array, preserving the current elements already inside it
ReDim Preserve Paths(1 To UBound(Paths) + 1)
' Make the inner array be 30 elements long
ReDim Preserve Paths(UBound(Paths)).Nodes(1 to 30)
' Return something random
GETPATH = UBound(Paths)
End Function
任何人都知道爲什麼這不起作用?
感謝您的詳細解釋!我設法解決您的幫助問題! – Steve