问题描述
我想将数组的一部分传递给子程序!
Sub main()
Dim i(10) As Byte
Dim j As Integer
For j = LBound(i) To UBound(i)
i(j) = j
Next
Call subr(i())
End Sub
Sub subr(i() As Byte)
Dim j As Integer
For j = LBound(i) To UBound(i)
Debug.Print i(j)
Next
End Sub
本示例将整个数组传递给 subr 并打印出来。
我想要这样的东西(不起作用):
Call subr(i(L_index to U_index))
L_index 和 U_index 确定要通过的范围。
解决方法
唯一的方法是复制你感兴趣的数组的跨度 in,而是传递数组和范围:
Call subr(i(),3,5)
Sub subr(arr() As Byte,startIndex As Long,endIndex As Long)
For i = startIndex To endIndex
Debug.Print arr(i)
Next
End Sub