【问题标题】:VBA Word How do I pass part of an array to a subroutine?VBA Word 如何将数组的一部分传递给子程序?
【发布时间】:2021-04-09 12:39:48
【问题描述】:

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

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 确定要通过的范围。

【问题讨论】:

    标签: arrays vba ms-word subroutine


    【解决方案1】:

    这样做的唯一方法是复制您感兴趣的数组的跨度 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-11
      • 2016-12-26
      • 2021-04-17
      相关资源
      最近更新 更多