我在一个程序中创建了一个数组,这是最终结果,我想在新程序中利用这些结果作为计算的输入。有没有办法将多维数组作为参数传递到另一个过程?您如何将它放入调用中以及如何在将要使用的过程中定义参数?
由于
答案 0 :(得分:3)
通过用括号修饰例程参数来传递单维数组;
sub a()
dim x(1, 1) As long
x(0, 0) = 1
x(1, 1) = 4
process x
end sub
sub process(arr() As long)
Msgbox arr(0, 0)
Msgbox arr(1, 1)
end sub
答案 1 :(得分:0)
这是你追求的那种东西吗?
Sub AAATest()
''''''''''''''''''''''''
' Dynamic array to hold
' the result.
''''''''''''''''''''''''
Dim ReturnArr() As Long
Dim Ndx1 As Long
Dim Ndx2 As Long
Dim NumDims As Long
''''''''''''''''''''''''''
' call the function to get
' the result array.
''''''''''''''''''''''''''
ReturnArr = ReturnMulti()
NumDims = NumberOfArrayDimensions(Arr:=ReturnArr)
Select Case NumDims
Case 0
'''''''''''''''''''
' unallocated array
'''''''''''''''''''
Case 1
''''''''''''''''''''''''''
' single dimensional array
''''''''''''''''''''''''''
For Ndx1 = LBound(ReturnArr) To UBound(ReturnArr)
Debug.Print ReturnArr(Ndx1)
Next Ndx1
Case 2
'''''''''''''''''''''''''''
' two dimensional array
'''''''''''''''''''''''''''
For Ndx1 = LBound(ReturnArr, 1) To UBound(ReturnArr, 1)
For Ndx2 = LBound(ReturnArr, 2) To UBound(ReturnArr, 2)
Debug.Print ReturnArr(Ndx1, Ndx2)
Next Ndx2
Next Ndx1
Case Else
''''''''''''''''''''''
' too many dimensions
''''''''''''''''''''''
End Select
End Sub
Function ReturnMulti() As Long()
''''''''''''''''''''''''''''''''''''
' Returns a mutli-dimensional array.
''''''''''''''''''''''''''''''''''''
Dim A(1 To 2, 1 To 3) As Long
'''''''''''''''''''''''''''''
' put in some values.
'''''''''''''''''''''''''''''
A(1, 1) = 100
A(1, 2) = 200
A(1, 3) = 300
A(2, 1) = 400
A(2, 2) = 500
A(2, 3) = 600
ReturnMulti = A()
End Function