vb 如何定义一个未知大小一维数组?
可以的,先定义一个动态数组:dim a() as string到使用的地方,再重定义上下限:
n=15
redim a(1 to n) ',当然,n 在重定义前就要确定
如果a中放了数据了,还要增加上限,还可以用 ReDim Preserve 语句来扩充数组:
a(15)=15
ReDim Preserve a(UBound(a) + 10) '只增加上限,不改变元素值
转发的,浏览器上的问题复制粘贴过来的,不知道对否,欢迎讨论!
Dim aaa() As String i = 2 ReDim Preserve aaa(i) '初始化数组的数量,0 - 2 三个数组 aaa(0) = "000" aaa(1) = "111" aaa(2) = "222" ReDim Preserve aaa(i + 1) '增加一个数组 aaa(3) = "333" MsgBox aaa(0) & " " & aaa(1) & " " & aaa(2) & " " & aaa(3)
'此代码不可临时增加数组 Dim aaa() As String i = 2 ReDim aaa(0 To i) '初始化数组的数量,0 - 2 三个数组 aaa(0) = "000" aaa(1) = "111" aaa(2) = "222" MsgBox aaa(0) & " " & aaa(1) & " " & aaa(2)
[此贴子已经被作者于2021-2-4 19:28编辑过]