Hier eine kleine UDF, um ein Array in der Console auszugeben.
_ArrayDisplayConsole:
Spoiler anzeigen
#include-once
#include <String.au3>
; #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
Beispiel:
[autoit]
#include "_ArrayDisplayConsole.au3"
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"]]
_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)
Global $avArray3 = StringSplit(WinGetClassList("", ""), @LF)
_ArrayDisplayConsole($avArray3, 20)
Gruß,
UEZ