【发布时间】:2019-12-02 12:34:07
【问题描述】:
当我在 Split 函数上使用 UBound 函数时,它返回 n-1(n 是数组的长度),但是当我在长度为 1 的数组上使用 UBound 函数时,它返回 n。
Dim arr1(1) As String, arr2 as Variant
arr1(0) = "test"
Debug.print "UBound(arr1): " & UBound(arr1)
arr2 = Split("test1/test2", "/")
Debug.print "UBound(arr2): " & UBound(arr2)
返回:
UBound(arr1): 1
UBound(arr2): 1
arr1 的长度为 1,arr2 的长度为 2,但 UBound 两者都返回 1?
【问题讨论】:
-
不是 arr1 的长度为 2,因为数组是从零开始的吗?
-
Ubound不是“长度”(必须),而是数组维度的最大索引。 -
@TimWilliams 我同意。我应该更好地措辞,现在删除评论。
-
...所以 UBound 仅在下限为 1 时等于任何数组维度的长度(通常为零,除非您使用多单元格范围的 .Value 获取数组属性)