一维数组怎么转为二维数组啊
将一个一维数组a(9)中各元素按行的顺序放入二维数组b(3,3)
b(1,1)=a(1)
b(2,1)=a(2)
b(3,1)=a(3)
b(1,2)=a(4)
......
这种的吗?
如果数组下标都是1开始的,那么可以使用 CopyMemory
如:
程序代码:
Option Explicit Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Private Sub Command1_Click() Dim a(1 To 9) As Long Dim b(1 To 3, 1 To 3) As Long Dim i As Long For i = 1 To 9 a(i) = i * 10 + Rnd() * 10 Next i Call CopyMemory(b(1, 1), a(1), 4 * 9) End Sub
如果不是,老老实实写循环一个一个的赋值吧。