Jump to content

New UDF: _ArrayPrint


Recommended Posts

I'm posting this as I didn't see it anywhere, and couldn't find anything that was close enough that I could use. This simplifies the output and you can feed it out through ConsoleWrite or a MsgBox (console preferrable) so you can see what's going on inside your arrays, including nested ones. Enjoy!

; #FUNCTION# ;============================================================================;
;
; Name...........: _ArrayPrint
; Description ...: Recursively walk the input array to expose all data contained
;                  in a human readable format
; Syntax.........: _ArrayPrint($asArrayIn, $sLeftMargin, $iNestLevel)
; Parameters ....: $asArrayIn   - Array/String input for the function to walk through
;                  $sLeftMargin - Characters to use to make the left margin, Default: @TAB
;                  $iNestLevel  - Internal tracking of nested depth, please do not set
; Return values .: Success - Human readable walk of entire $asArrayIn
;                  Failure - Returns -1
; Author ........: Cynagen
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
;
; ;=======================================================================================;
func _ArrayPrint($_array,$_margin=@TAB,$_nest=0)
    if $_array = "" then return -1
    Local $_out, $_tab
    if isarray($_array) Then
        for $t = 1 to $_nest
            $_tab = $_tab & $_margin
        next
        $_out = "Array(" & @CRLF
        for $p = 0 to UBound($_array) - 1
            $_out &= $_tab & $_margin & "[" & $p & "] => " & _ArrayPrint($_array[$p],$_margin,$_nest+1)
        Next
        $_out &= $_tab & ")" & @CRLF
    Else
        $_out = $_array & @CRLF
    EndIf
    return $_out
EndFuncoÝ÷ Ù«­¢+Øì±Ð½¹µ¥µ¹Í¥½¸ÉÉäáµÁ±(¥¹±Õ±Ðí}ÉÉåAÉ¥¹Ð¹ÔÌÐì(ÀÌØí}ѱôÍÑÉ¥¹ÍÁ±¥Ð ÅÕ½ÐìÀÄÈÌÐÔØÜàå    
!%)-159=AEIMQUY]aehÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤)}ÉÉåIÙÉÍ ÀÌØí}ѱ¤)½¹Í½±Ýɥѡ}ÉÉåAÉ¥¹Ð ÀÌØí}ѱ¤¤)}ÉÉåA½À ÀÌØí}ѱ¤)½¹Í½±Ýɥѡ}ÉÉåAÉ¥¹Ð ÀÌØí}ѱ¤¤)}ÉÉåIÙÉÍ ÀÌØí}ѱ¤)½¹Í½±Ýɥѡ}ÉÉåAÉ¥¹Ð ÀÌØí}ѱ¤oÝ÷ Ù«­¢+Øì9Íѽ5ձѥ¥µ¹Í¥½¹°ÉÉäáµÁ±(¥¹±Õ±ÐíÉÉä¹ÔÌÐì(¥¹±Õ±Ðí}ÉÉåAÉ¥¹Ð¹ÔÌÐì(ÀÌØí}ѱôÍÑÉ¥¹ÍÁ±¥Ð ÅÕ½ÐìÀÄÈÌÐÔØÜàå 
!%)-159=AEIMQUY]aehÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤ì=ÕÈÍѱ(ÀÌØí}ѱÈô}ÉÉå
ÉÑ ÀÌØí}ѱ°ÀÌØí}ѱ¤ì±ÐÉÉä(ÀÌØí}ѱÌô}ÉÉå
ÉÑ ÀÌØí}ѱȰÀÌØí}ѱ¤ìµÕ±Ñ¥¥µ¹Í¥½¹°ÉÉä)½¹Í½±Ýɥѡ}ÉÉåAÉ¥¹Ð ÀÌØí}ѱ̤¤ì]¡Ð¥ÝÐü

I'd love feedback please, this is the first snippet of standalone code I've posted here besides helping out with another script, and some long-overdue code for a project I thought stalled.

Edited by Cynagen

Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums.

Link to comment
Share on other sites

Tested with your examples; looks good!

See also _ArrayWalk UDF by Saunders: ;http://www.autoitscript.com/forum/index.php?s=&showtopic=53390&view=findpost&p=410283

Thank you, and I see there is an _ArrayWalk now, it doesn't seem to be added to the included UDFs with my version of AutoIt though. (Admittedly i'm running an older version because a newer version blew up a few important scripts for me, certain functions stopped working altogether.) My walker is based more closely to the PHP function print_r(); which does a recursive walk of arrays. It's VERY helpful for figuring out what's wrong with your array.

Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums.

Link to comment
Share on other sites

Any chance somebody could move this thread to Example Scripts?

Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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