My function handles 1d and 2d arrays, and also 0-based and 1-based arrays. It creates a GUI Form (that is sizable and maximizable) with a listview on it that displays the array with the index numbers listed down the side.
;===============================================================================
;
; Function Name: _ArrayBox()
; Description: Shows an array in a GUI window. Improved version of _ArrayDisplay
; Parameter(s): $Array - An array, 1d or 2d, 0-based or 1-based
; $ArrayBase - 1 or 0 - tells what base the array is
; $sTitle - the title to put on the output window
; $Width, $Height, $Left, $Top - Set the size and position of the output window
; Requirement(s): $Array must be 1d or 2d. If 1-based, then arraysize is assumed to be $Array[0] or $Array[0][0]
; Return Value(s): -1 = $Array is not an array, error=1
; Author(s): Mike Ratzlaff <mike@ratzlaff.org>
; Revision: 20050620A
;
;===============================================================================
;
Func _ArrayBox(ByRef $Array, $ArrayBase = 1, $sTitle = 'Array Box', $Width = 200, $Height = 200, $Left = -1, $Top = -1)
Dim $AllDone = 0, $msg, $i, $j, $ArrayDimensions = UBound($Array, 0)
Dim $hndForm_Main, $hndListView_Display
If $ArrayDimensions = 0 Then
SetError(1)
Return -1
EndIf
;Setup
If $ArrayBase <> 0 Then $ArrayBase = 1
If $ArrayBase Then
Select
Case $ArrayDimensions = 1
$ArrayMax = $Array[0]
Case $ArrayDimensions = 2
$ArrayMax = $Array[0][0]
EndSelect
Else
$ArrayMax = UBound($Array, 1) - 1
EndIf
;Create GUI
If $Height < 100 Then $Height = 100
If $Width < 100 Then $Width = 100
$hndForm_Main = GUICreate($sTitle, $Width, $Height, $Left, $Top, BitOR($WS_POPUP, $WS_CAPTION, $WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_EX_DLGMODALFRAME))
;Create List Box
If $ArrayDimensions = 1 Then
$sTemp = 'Index|Value'
ElseIf $ArrayDimensions = 2 Then
$sTemp = 'Index'
For $i = 0 To UBound($Array, 2) - 1
$sTemp = $sTemp & '|' & $i
Next
EndIf
$hndListView_Display = GUICtrlCreateListView($sTemp, 0, 0, $Width, $Height-24, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL))
GUICtrlSetResizing($hndListView_Display, BitOR($GUI_DockLeft, $GUI_DockTop, $GUI_DockRight, $GUI_DockBottom))
;Create Controls, Show GUI
$hndButton_Close = GUICtrlCreateButton('&Close',$Width-80,$Height-24,80,24)
GUICtrlSetResizing($hndButton_Close, BitOR($GUI_DockRight, $GUI_DockBottom, $GUI_DockSize))
GUICtrlSetState($hndButton_Close, $GUI_DefButton)
GUISetState (@SW_SHOW, $hndForm_Main)
;Display Array
Select
Case $ArrayDimensions = 1 ;1-Dimensional Array
For $i = $ArrayBase To $ArrayMax
GUICtrlCreateListViewItem($i & '|' & $Array[$i], $hndListView_Display)
Next ;$i
Case $ArrayDimensions = 2 ;2-Dimensional Array
For $i = $ArrayBase To $ArrayMax
$sTemp=$Array[$i][0]
for $j = 1 To UBound($Array, 2) - 1
$sTemp = $sTemp & '|' & $Array[$i][$j]
Next ;$j
GUICtrlCreateListViewItem('[' & $i & ']|' & $sTemp, $hndListView_Display)
Next ;$i
Case Else ;Unhandled Type
EndSelect
;Wait for user to close box
Do
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
$AllDone = 1
Case $msg = $hndButton_Close
$AllDone = 1
EndSelect
Until $AllDone
GUIDelete($hndForm_Main)
Return 0
EndFunc
Tell me what you think!






