Function Reference


_ArrayDisplay

Displays a 1D or 2D array in a ListView

#include <Array.au3>
_ArrayDisplay ( Const ByRef $aArray [, $sTitle = "ArrayDisplay" [, $sArrayRange = "" [, $iFlags = 0 [, $vUser_Separator = Default [, $sHeader = Default [, $iMax_ColWidth = Default [, $iAlt_Color = Default [, $hUser_Function = ""]]]]]]]] )

Parameters

$aArray Array to display
$sTitle [optional] Title for dialog. Default = "ArrayDisplay".
$sArrayRange [optional] Range of rows/columns to display. Default ("") = entire array. (See below for details)
$iFlags [optional] Determine UDF options. Add required values together
    0 = (default) Column text alignment - left
    1 = Transposes the array
    2 = Column text alignment - right
    4 = Column text alignment - center
    8 = Verbose - display MsgBox on error and splash screens during processing of large arrays
    16 = Only 'Copy' buttons displayed
    32 = No buttons displayed
    64 = No 'Row' column displayed
$vUser_Separator [optional] Sets column display option when copying data to clipboard.
    Character = Delimiter between columns.
    Number = Fixed column width - longer items will be truncated.
    Default = Current separator character (usually "|").
$sHeader [optional] Column names in header (string of names separated by current separator character - usually "|"). Default see Remarks.
$iMax_Colwidth [optional] Max width to which a ListView column will expand to show content. Default = 350 pixels.
$iAlt_Color [optional] ListView alternate rows set to defined color. Default = all rows ListView background color.
$hUser_Function [optional] A variable assigned to the user defined function to run. Default = none. See remarks.

Return Value

Success: 1
Failure: 0 and @error flag set as follows:
@error: 1 - $aArray is not an array
2 - $aArray has too many dimensions (only 1D and 2D supported)

Remarks

If the function is passed a non-array variable or an array of more than 2 dimensions the function returns an error and the script continues. If the "verbose" parameter is set in $iFlags a MsgBox will be displayed which offers the chance to exit the script immediately or to continue the script with the normal error return.

Only 65525 rows of an array can be displayed - this is an AutoIt limitation on the total number of controls that can be displayed in a GUI - and an abitrary display limit of 250 columns has also been set. If the user tries to display an array larger than these limits an "*" is added to the truncated dimension value which will be displayed in red text. Note that using $iArrayRange to determine the elements to be displayed allows arrays larger than the display limits to be displayed in sections.

The $sArrayRange parameter syntax is as follows:

"7" Show rows 0-7 with all columns
"7:" Show rows 7-end with all columns
"|7" Show all rows with columns 0-7
"|7:" Show all rows with columns 7-end
"7|7" Show rows 0-7 with columns 0-7
"5:7" Show rows 5-7 with all columns
"|5:7" Show all rows with columns 5-7
"7|5:7" Show rows 0-7 with columns 5-7
"5:7|7" Show rows 5-7 with columns 0-7
"5:7|5:7" Show rows 5-7 with columns 5-7

Any column values are ignored for 1D arrays.

$sHeader names (separated by the current separator character) will be used for as many columns as there are names. If no, or not enough, custom names are specified then the default header of "Row|Col0" for 1D arrays or "Row|Col0|Col1|...|Col n" for 2D is substituted.

The 4 buttons at the bottom of the dialog have the following functions:
Copy Data & Hdr/Row Copy the array or the selected row(s) to the clipboard adding full header and row identification.
Copy Data Only Copy the array or the selected row(s) to the clipboard with no header or row identification.
Run User Func Run the user-defined function passed in $sUser_Function. This function is entirely separate from the UDF and must be created and coded by the user to accept 2 (and only 2) parameters which will be provided by the UDF itself: the full array being displayed and a 1D array holding the selected rows indices with a count in the [0] element. These parameters can then be used inside the user function as required. The button is not displayed if no function is specified.
Exit script Exit the script immediately.

The $iFlags parameter enables some or all of these buttons to be hidden.

If all buttons are displayed the array dimensions are displayed at lower left. They are in red text if any the following occur: row/column truncation, array transposition, or displaying only a range of elements - a tooltip displays the particular occurence(s).

If the "verbose" parameter is set in $iFlags a splash dialog is displayed during initial processing when the array to display has more than 10000 elements. A similar dialog is displayed when the "Copy Data" buttons are used on a 10000+ element display - if this is likely to occur consideration should be given to using a "User Function" to store the array for later processing.

An array element containing another array is displayed as {Array}.

Example

#include <Array.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()

    ; Create 1D array to display
    Local $aArray_1D[5] = ["Item 0", "Item 1", "A longer Item 2 to show column expansion", "Item 3", "Item 4"]

    _ArrayDisplay($aArray_1D, "1D display")
    _ArrayDisplay($aArray_1D, "1D display transposed - 'Copy' buttons only", Default, 1 + 16) ; No buttons displayed

    ; Create 2D array to display
    Local $aArray_2D[75][255]
    For $i = 0 To UBound($aArray_2D) - 1
        For $j = 0 To UBound($aArray_2D, 2) - 1
            $aArray_2D[$i][$j] = "Item " & StringFormat("%02i", $i) & StringFormat("%02i", $j)
        Next
    Next

    _ArrayDisplay($aArray_2D, "2D display") ; Note columns truncated
    _ArrayDisplay($aArray_2D, "2D display transposed", Default, 1) ; Note all array elements displayed

    ReDim $aArray_2D[20][10]
    $aArray_2D[5][5] = "A longer item to show column expansion"
    _ArrayDisplay($aArray_2D, "Expanded column - custom titles - alternate line color - no buttons or 'Row' column", Default, 32 + 64, Default, "AA|BB|CC|DD|EE|FF|GG|HH|II|JJ", Default, 0xDDFFDD)

    ; Assign the user function to a variable to pass as a parameter
    Local $hUserFunction = _UserFunc

    $aArray_2D[5][5] = "Column alignment set to right"
    _ArrayDisplay($aArray_2D, "Range set - right align - copy column width - user function", "3:7|4:9", 2, 15, "AA|BB|CC|DD|EE|FF", Default, Default, $hUserFunction)
    _ArrayDisplay($aArray_2D, "Range set - right align - copy column width - transposed", "3:7|4:9", 3, 15, "AA|BB|CC|DD|EE|FF") ; Note no col names as transposed

    ; Create non-array variable to force error - MsgBox displayed as $iFlags set
    Local $vVar = 0
    _ArrayDisplay($vVar, "MsgBox on Error", Default, 8)

EndFunc   ;==>Example

; Note that the user function MUST have TWO parameters even if you do not intend to use both of them
Func _UserFunc($aArray_2D, $aSelected)

    ; But if a parameter is not used do this to prevent an Au3Check warning
    #forceref $aArray_2D

    _ArrayDisplay($aSelected, "Selected cols")

EndFunc   ;==>_UserFunc