VB中,用array输入一个数组,将其变为2维数组,下标从1开始,下面程序为什么提示“下标越界” 10
PrivateSubForm_Load()DimB1AsVariant,iAsInteger,jAsIntegerB1=Array(1,2,3,4,5,6,7,8)For...
Private Sub Form_Load()
Dim B1 As Variant, i As Integer, j As Integer
B1 = Array(1, 2, 3, 4, 5, 6, 7, 8)
For i = 1 To 2
For j = 1 To 4
B1(i, j) = B1((i - 1) * 4 + j - 1)
Next j
Next i
End Sub
已解决 展开
Dim B1 As Variant, i As Integer, j As Integer
B1 = Array(1, 2, 3, 4, 5, 6, 7, 8)
For i = 1 To 2
For j = 1 To 4
B1(i, j) = B1((i - 1) * 4 + j - 1)
Next j
Next i
End Sub
已解决 展开
1个回答
展开全部
用Array得到数组都是一维数组,并且是从0开始的。
你可以这样
Dim B1 As Variant, i As Integer, j As Integer, B2() As Variant
B1 = Array(1, 2, 3, 4, 5, 6, 7, 8)
ReDim B2(1 To 2, 1 To UBound(B1) \ 2 + 1)
For i = 1 To 2
For j = 1 To 4
B2(i, j) = B1((i - 1) * 4 + j - 1)
Next j
Next i
你可以这样
Dim B1 As Variant, i As Integer, j As Integer, B2() As Variant
B1 = Array(1, 2, 3, 4, 5, 6, 7, 8)
ReDim B2(1 To 2, 1 To UBound(B1) \ 2 + 1)
For i = 1 To 2
For j = 1 To 4
B2(i, j) = B1((i - 1) * 4 + j - 1)
Next j
Next i
追问
vb 中能直接输入二维多维数组吗?必须得用上述的方法将其变为多维的?
追答
是的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询