Displays a 1D or 2D array in a ListView to aid debugging
#include <Debug.au3>
_DebugArrayDisplay ( Const ByRef $aArray [, $sTitle = "DebugArray" [, $sArrayRange = "" [, $iFlags = 0 [, $vUser_Separator = Default [, $sHeader = Default [, $iDesired_Colwidth = Default [, $hUser_Function = ""]]]]]]] )
$aArray | Array to display |
$sTitle | [optional] Title for dialog. Default = "DebugArray". |
$sArrayRange | [optional] Range of rows/columns to display. Default ("") = entire array. (See below for details) |
$iFlags | [optional] Determine UDF options. Add required values together $ARRAYDISPLAY_COLALIGNLEFT (0) = (default) Column text alignment - left $ARRAYDISPLAY_TRANSPOSE (1) = Transposes the array (2D only) $ARRAYDISPLAY_COLALIGNRIGHT (2) = Column text alignment - right $ARRAYDISPLAY_COLALIGNCENTER (4) = Column text alignment - center $ARRAYDISPLAY_VERBOSE (8) = Verbose - display MsgBox on error and splash screens during processing of large arrays $ARRAYDISPLAY_NOROW (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. |
$iDesired_Colwidth | [optional] If positive Max width to which a ListView column will expand to show content. Default = 350 pixels. If Negative all columns, except the first one set to 55, will be set to Abs($iDesired_Colwidth). |
$hUser_Function | [optional] A variable assigned to the user defined function to run. Default = none. See remarks. |
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) 3 - @error is set when the function is called, a _DebugReport() |
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.
Although there are no limits on the size of the array to be displayed, there is a Windows control limitation which means that the LitView headers and columns do not align if there are more than approximately 600.
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 |
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 $hUser_Function. This function is entirely separate from the UDF and must be created and coded by the user - see below. The button is not displayed if no function is specified. |
Exit script | Exit the script immediately. |
#include <Debug.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"]
_DebugArrayDisplay($aArray_1D, "1D display")
; Create 2D array to display
Local $aArray_2D[25][15]
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
_DebugArrayDisplay($aArray_2D, "2D display")
$aArray_2D[5][5] = "A longer item to show column expansion"
_DebugArrayDisplay($aArray_2D, "Expanded column - custom titles - no buttons or 'Row' column", Default, 32 + 64, Default, "AA|BB|CC|DD|EE|FF|GG|HH|II|JJ")
; Assign the user function to a variable to pass as a parameter
Local $hUserFunction = _UserFunc
$aArray_2D[5][5] = "Column alignment set to right"
_DebugArrayDisplay($aArray_2D, "Range set - right align - copy column width - user function", "3:7|4:9", 2, 15, "AA|BB|CC|DD|EE|FF", Default, $hUserFunction)
_DebugArrayDisplay($aArray_2D, "Range set - transposed", "3:7|4:9", 1, Default, "AA|BB|CC|DD|EE|FF") ; Note no col names as transposed
$aArray_2D[5][5] = "Column alignment set to left"
Opt("GUIDataSeparatorChar", "!")
_DebugArrayDisplay($aArray_2D, "! Header separator", "3:7|4:9", Default, Default, "AA!BB!CC!DD!EE!FF")
; Create non-array variable to force error - MsgBox displayed as $iFlags set
Local $vVar = 0, $iRet, $iError
$iRet = _DebugArrayDisplay($vVar, "No MsgBox on Error")
$iError = @error
MsgBox(0, "_DebugArrayDisplay() Error", "return without internal Msgbox $iret =" & $iRet & " @error=" & $iError)
$iRet = _DebugArrayDisplay($vVar, "MsgBox on Error", Default, 8)
$iError = @error
MsgBox(0, "_DebugArrayDisplay() Error", "return internal Msgbox with no force Exit $iret =" & $iRet & " @error=" & $iError)
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
_DebugArrayDisplay($aSelected, "Selected cols")
EndFunc ;==>_UserFunc