如何确定数组维数?

时间:2013-10-30 17:03:59

标签: arrays multidimensional-array autoit

如何确定数组维数?

如果您不知道它是否存在,则无法循环任何维度(无错误)。

3 个答案:

答案 0 :(得分:2)

从帮助文件:

UBound ( Array [, Dimension] )
Array The array variable which is being queried. 
Dimension [optional] Which dimension of a multi-dimensioned array to report the size of. Default is 1, which is the first dimension. If this parameter is 0, the number of subscripts in the array is returned. 

考虑到上述情况:

Local $myArray[10][20] ;element 0,0 to 9,19

For $i = 1 To UBound($myArray, 0)
    ConsoleWrite("Dimension: " & $i & " :" & UBound($myArray, $i) & @LF)
Next

答案 1 :(得分:0)

  

是的,我知道,当您需要处理复杂数据或带有模块的大型程序时,AutoIt并不是最好的

错了,但让我们保持主题;)

让我们使用2D数组作为例子。

要获取行数,请使用

$iRowCount = UBOUND($array)

要获取列数,请使用

$iColCount = UBOUND($array, 2)

需要总大小?

$iTotal = UBOUND($array) * UBOUND($array, 2)
编辑:还有什么更大的? Loopit

Local $iTotal = 1
For $i = 1 To UBOUND($array, 0)
    $iTotal*= UBOUND($array, $i)
Next

答案 2 :(得分:0)

  

“ ... 确定尺寸计数。

根据Documentation - Language Reference - UBound()的示例:

#include <AutoItConstants.au3>; $UBOUND_DIMENSIONS

Global $g_aArray[1]
ReDim $g_aArray[3][6][9]

ConsoleWrite('Array comprises ' & UBound($g_aArray, $UBOUND_DIMENSIONS) & ' dimensions.' & @CRLF)
相关问题