Jump to content

Recommended Posts

Posted

It's a work in progress but it woks 😁

Ever worked with nested arrays before and wanted to see the whole tree structure to examine your array?
Now you can! With this handy little UDF:

#include <GuiTreeView.au3>
#include <GuiConstants.au3>

Local $A = [1, 2, 3]
Local $B = [['a', 'b', 'c'], ['d', $A, 'f'], ['g', 'h', 'i']]
Local $C = [$A, $B]

_NestedArrayDisplay($A)
_NestedArrayDisplay($B)
_NestedArrayDisplay($C)

; #FUNCTION# ====================================================================================================================
; Name ..........: _NestedArrayDisplay
; Description ...: For viewing nested array's in a treevieuw
; Syntax ........: _NestedArrayDisplay($array)
; Parameters ....: $array (a nested array)
; Return values .: None
; Author ........: TheAutomator
; Modified ......: First UDF, not modified yet
; Remarks .......: Can also display multidimensional array's
; Related .......: _ArrayDisplay
; Link ..........: None
; Example .......: Above this description
; ===============================================================================================================================

Func nested($thing, $node)
    If IsArray($thing) Then
        Local $inside
        If UBound($thing, 0) > 1 Then
            $inside = GUICtrlCreateTreeViewItem('[MULTID. ARRAY]', $node)
            For $X = 0 To UBound($thing, 1) - 1
                For $Y = 0 To UBound($thing, 2) - 1
                    nested($thing[$X][$Y], $inside)
                Next
            Next
        Else
            $inside = GUICtrlCreateTreeViewItem('[ARRAY]', $node)
            For $item In $thing
                If IsArray($item) Then
                    nested($item, $inside)
                Else
                    GUICtrlCreateTreeViewItem($item, $inside)
                EndIf
            Next
        EndIf
    Else
        GUICtrlCreateTreeViewItem($thing, $node)
    EndIf
EndFunc   ;==>nested

Func _NestedArrayDisplay($array)
    Local $temp_gui = GUICreate('Nested Array', 410, 410)
    Local $treeview = GUICtrlCreateTreeView(5, 5, 400, 400)
    nested($array, $treeview)
    GUISetState(@SW_SHOW, $temp_gui)
    _GUICtrlTreeView_Expand($treeview)
    While GUIGetMsg() <> $gui_event_close
    WEnd
    GUIDelete($temp_gui)
EndFunc   ;==>_NestedArrayDisplay

Enjoy, hope it's useful for you guys!

TheAutomator

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...