_ArrayDisplayConsole v0.92 build 2015-01-25 beta

  • Hier eine kleine UDF, um ein Array in der Console auszugeben.

    _ArrayDisplayConsole:

    Spoiler anzeigen
    [autoit]


    #include-once
    #include <String.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _ArrayDisplayConsole
    ; Description ...: Displays given 1D or 2D array in the console only
    ; Syntax ........: _ArrayDisplayConsole($avArray[, $iColumnWidth = 24[, $iItemLimit = -1[, $bDisplayCRNo = True[,
    ; $bDisplayValueBorders = False[, $sValueBorderChar = "*"[, $bShowBorder = False[, $sBorderChar = "|"[,
    ; $bCenter = False]]]]]]]])
    ; Parameters ....: $avArray - Array to display
    ; $iColumnWidth - [optional] String length of each cell
    ; $iItemLimit - [optional] Maximum number of lines (rows) to show
    ; $bDisplayCRNo - [optional] Display column / row numbers
    ; $bDisplayValueBorders - [optional] Display border around the array value to see any white space
    ; $sValueBorderChar - [optional] value border character
    ; $bShowBorder - [optional] show the border of the cell
    ; $sBorderChar - [optional] border of the cell
    ; $bCenter - [optional] center the text in the columns
    ; Return values .: Success - 1
    ; Failure - 0, sets @error:
    ; | 1 - $avArray is not an array
    ; | 2 - $avArray has too many dimensions (only up to 2D supported)
    ; Author ........: UEZ
    ; Version .......: 0.92 build 2015-01-25 beta
    ; Modified ......:
    ; Remarks .......: If an array is found within the array it will be displayed as [ARRAY PTR]
    ; Related .......: UBound, IsArray, StringFormat, StringLeft, StringLen, ConsoleWrite
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _ArrayDisplayConsole($avArray, $iColumnWidth = 24, $iItemLimit = -1, $bDisplayCRNo = True, $bDisplayValueBorders = False, $sValueBorderChar = "*", $bShowBorder = False, $sBorderChar = "|", $bCenter = False)
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)
    Local $iDimension = UBound($avArray, 0), $iUBound = UBound($avArray, 1) - 1, $iSubMax = UBound($avArray, 2) - 1
    If $iDimension > 2 Then Return SetError(2, 0, 0)
    If $iColumnWidth < 1 Or $iColumnWidth = Default Then $iColumnWidth = 24
    Local $iH, $iW, $iLenUBound = StringLen($iUBound), $sText, $iBorder = 1, $sArray = "[ARRAY PTR]"
    If $bShowBorder Then
    $iBorder = 0
    Else
    $sBorderChar = ""
    EndIf
    If $bDisplayCRNo And $iSubMax > -1 Then
    ConsoleWrite(StringFormat("%-" & $iLenUBound + 2 & "s", " "))
    For $iW = 0 To $iSubMax
    $sText = "[" & StringLeft($iW, $iColumnWidth) & "]"
    Switch $bCenter
    Case True
    ConsoleWrite(StringFormat("%-" & $iColumnWidth + $sBorderChar & "s", _StringRepeat(" ", $iColumnWidth / 2 - 1) & $sText) & $sBorderChar )
    Case False
    ConsoleWrite(StringFormat("%-" & $iColumnWidth + $sBorderChar & "s", $sText) & $sBorderChar)
    EndSwitch
    Next
    ConsoleWrite(@CRLF)
    EndIf
    If $iItemLimit > 0 Then $iUBound = $iItemLimit - 1
    Switch $iDimension
    Case 1
    For $iH = 0 To $iUBound
    If $bDisplayCRNo Then ConsoleWrite(StringFormat("[%0" & $iLenUBound & "s] ", StringLeft($iH, $iColumnWidth)))
    If $bDisplayValueBorders Then
    Switch IsArray($avArray[$iH])
    Case False
    $sText = $sValueBorderChar & StringLeft($avArray[$iH], $iColumnWidth) & $sValueBorderChar
    Case True
    $sText = StringLeft($sArray, $iColumnWidth) & $sValueBorderChar
    EndSwitch
    Switch $bCenter
    Case True
    ConsoleWrite(StringFormat("%-" & $iColumnWidth + $sBorderChar & "s", _StringRepeat(" ", ($iColumnWidth - StringLen($sText) + $sBorderChar) / 2) & $sText) & $sBorderChar)
    Case False
    ConsoleWrite(StringFormat("%-" & $iColumnWidth + $sBorderChar & "s", $sText) & $sBorderChar)
    EndSwitch
    Else
    Switch IsArray($avArray[$iH])
    Case False
    $sText = StringLeft($avArray[$iH], $iColumnWidth)
    Case True
    $sText = StringLeft($sArray, $iColumnWidth)
    EndSwitch
    Switch $bCenter
    Case True
    ConsoleWrite(StringFormat("%-" & $iColumnWidth + $sBorderChar & "s", _StringRepeat(" ", ($iColumnWidth - StringLen($sText) + $sBorderChar) / 2) & $sText) & $sBorderChar)
    Case False
    ConsoleWrite(StringFormat("%-" & $iColumnWidth + $sBorderChar & "s", $sText) & $sBorderChar)
    EndSwitch
    EndIf
    ConsoleWrite(@CRLF)
    Next
    Case 2
    For $iH = 0 To $iUBound
    If $bDisplayCRNo Then ConsoleWrite(StringFormat("[%0" & $iLenUBound & "s]", StringLeft($iH, $iColumnWidth)))
    For $iW = 0 To $iSubMax
    If $bDisplayValueBorders Then
    Switch IsArray($avArray[$iH][$iW])
    Case False
    $sText = $sValueBorderChar & StringLeft($avArray[$iH][$iW], $iColumnWidth) & $sValueBorderChar
    Case True
    $sText = $sValueBorderChar & StringLeft($sArray, $iColumnWidth) & $sValueBorderChar
    EndSwitch
    Switch $bCenter
    Case True
    ConsoleWrite(StringFormat("%-" & $iColumnWidth + $sBorderChar & "s", _StringRepeat(" ", ($iColumnWidth - StringLen($sText) + 1) / 2) & $sText) & $sBorderChar)
    Case False
    ConsoleWrite(StringFormat("%-" & $iColumnWidth + $sBorderChar & "s", $sText) & $sBorderChar)
    EndSwitch
    Else
    Switch IsArray($avArray[$iH][$iW])
    Case False
    $sText = StringLeft($avArray[$iH][$iW], $iColumnWidth)
    Case True
    $sText = StringLeft($sArray, $iColumnWidth)
    EndSwitch
    Switch $bCenter
    Case True
    ConsoleWrite(StringFormat("%-" & $iColumnWidth + $sBorderChar & "s", _StringRepeat(" ", ($iColumnWidth - StringLen($sText) + 1) / 2) & $sText) & $sBorderChar)
    Case False
    ConsoleWrite(StringFormat("%-" & $iColumnWidth + $sBorderChar & "s", $sText) & $sBorderChar)
    EndSwitch
    EndIf
    Next
    ConsoleWrite(@CRLF)
    Next
    EndSwitch
    ConsoleWrite(@CRLF)
    Return 1
    EndFunc

    [/autoit]

    Beispiel:

    [autoit]


    #include "_ArrayDisplayConsole.au3"

    [/autoit][autoit][/autoit][autoit]

    Global $avArray0[1] = ["Test"]

    [/autoit][autoit][/autoit][autoit]

    Global $avArray1[3][5] = [["Andy", "Eukalyptus", "BugFix", "Oscar", "minx"], _
    ["Tweaky", "AsperinJunkie", "pee", "", $avArray0], _
    ["water", "Sprenger120", "chesstiger", "GunFood", "Techmix"]]

    [/autoit][autoit][/autoit][autoit]

    _ArrayDisplayConsole($avArray1, 28, -1, True, False, "*", True, "|", True)

    [/autoit][autoit][/autoit][autoit]

    ConsoleWrite(@CRLF)

    [/autoit][autoit][/autoit][autoit]

    Global $avArray2[6] = ["Cheater Dieter", "Mars", $avArray0, "funkey", "name22", "Raupi"]
    _ArrayDisplayConsole($avArray2, 15)

    [/autoit][autoit][/autoit][autoit]

    Global $avArray3 = StringSplit(WinGetClassList("", ""), @LF)
    _ArrayDisplayConsole($avArray3, 20)

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (25. Januar 2015 um 21:55)

  • Sehr fein! :thumbup:

    • Offizieller Beitrag

    Coole Sache das :thumbup:

  • Wie sagt Enie van de Meiklokjes immer: Geiler Scheiß!

  • Naja, einen wirklichen Nutzen gegenüber der _ArrayDisplay() Funktion sehe ich jetzt nicht wirklich. Viel mehr würde mir eine Array-Konsolen Ausgabe mir beim Debuggen tierisch auf dem Leim gehen. Wenn dann überprüft man Array's in Schleifen um zu sehen ob da irgendwelche Fehlerhaften Eingaben etc. geschehen. 20x eine komplette Array Darstellung in der Konsole ist da nicht so vorteilhaft. Welchen nutzen soll das also noch haben wenn ich mal bescheiden nachfragen darf!? :)

    Ach ja, ich vermisse immer noch eine Funktion die mir 64D Arrays anzeigen kann. Ich hab da leider noch keine praktische Darstellungsform gefunden, arbeite aber schon mal öfters mit denen. Hast du nicht was in deinem Zauberkasten? :D

  • Es kommt auf die Anwendung an. Z.B. kannst du _ArrayDisplay in einer WM Funktion vergessen, wenn du ein Array debuggen willst.

    Oder du könntest den Output in eine Datei "pumpen", etc.

    Du könntest auch die Ausgabe mit $iItemLimit  limitieren, wobei momentan nicht ein Bereich angegeben werden kann.

    64D erinnert mich an Analysis über den R^n Raum...arbeite daran. :P

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯