如何获取多维数组某个特定键(数组下标)的所有值
1个回答
展开全部
这个只能通过一个变量累加,然后从中分解出下标值:
k = 0For Each myd In tdata i = k \衡羡 (UBound(tdata, 1) - LBound(tdata, 1) + 1) '第一维下标值咐猛拍 j = k Mod (UBound(tdata, 2) - LBound(tdata, 2) + 1) '第二维下标值 Print "tdata(" & i & "," & j & ")=" & myd k = k + 1Next
或者不用遍历,直接顺序读取即可(知昌在数组大小已知的情况下,遍历其实没啥意义了):
For j = LBound(tdata, 1) To UBound(tdata, 1) For i = LBound(tdata, 2) To UBound(tdata, 2) Print "tdata(" & i & "," & j & ")=" & tdata(i, j) NextNext
k = 0For Each myd In tdata i = k \衡羡 (UBound(tdata, 1) - LBound(tdata, 1) + 1) '第一维下标值咐猛拍 j = k Mod (UBound(tdata, 2) - LBound(tdata, 2) + 1) '第二维下标值 Print "tdata(" & i & "," & j & ")=" & myd k = k + 1Next
或者不用遍历,直接顺序读取即可(知昌在数组大小已知的情况下,遍历其实没啥意义了):
For j = LBound(tdata, 1) To UBound(tdata, 1) For i = LBound(tdata, 2) To UBound(tdata, 2) Print "tdata(" & i & "," & j & ")=" & tdata(i, j) NextNext
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询