VBA Word 如何将数组的一部分传递给子例程?

VBA Word How do I pass part of an array to a subroutine?

我想将数组的一部分传递给子程序!

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_indexU_index决定传递的范围。

唯一的方法是复制你感兴趣的数组的跨度 在,而是传递数组和范围:

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