1、UBond函数求数组的最大索引号
Sub UseUBound()
Dim a As Variant
a = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
MsgBox "the biggest number of index is:" & UBound(a)
End Sub
UBound(name of array) '返回数组的最大索引号'
2、LBound函数求数组的最小索引号
用法同UBound
LBound(name of array) '返回数组的最小索引号'
Sub dwarr()
Dim arr(1 To 10, 1 To 100) As Integer
Dim a As Integer, b As Integer
a = UBound(arr, 1)
b = UBound(arr, 2) 'Chr(13)相当于回车键,用于换行,13是ASCII码'
MsgBox "第一维的最大索引号是:" & a & Chr(13) & _ '_表示换行,下一句与本句是同一句,_是连接符'
"第二维的最大索引号是:" & b
End Sub
3、用Join函数将一维数组合并成字符串
Join函数是将数组中的元素使用指定分隔符连接成一个新的字符串,与Split函数的作用相反
Sub Jointest()
Dim a As Variant
Dim txt As String
a = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
txt = Join(a, "@")
'将数组a中的元素以@为分隔符合并成一个字符串,将结果保存到变量txt中'
MsgBox txt
End Sub
使用方法
join(数组名,"分隔符")