Modify

#3695 closed Feature Request (Completed)

Func _SQLite_Display2DResult($aResult, $iCellWidth = 0, $bReturn = False, $sDelim_Col = "", $sDelim_Row = @CRLF)

Reported by: argumentum Owned by: J-Paul Mesnage
Milestone: 3.3.15.4 Component: Standard UDFs
Version: Severity: None
Keywords: _SQLite_Display2DResult Cc:

Description

; #FUNCTION# ====================================================================================================================
; Author ........: piccaso (Fida Florian)
; Modified.......: jchd, argumentum (02.03.19 - added flexibility)
; ===============================================================================================================================
Func _SQLite_Display2DResult($aResult, $iCellWidth = 0, $bReturn = False, $sDelim_Col = "", $sDelim_Row = @CRLF)
	If Not IsArray($aResult) Or UBound($aResult, $UBOUND_DIMENSIONS) <> 2 Or $iCellWidth < 0 Then Return SetError(1, 0, "")
	Local $aiCellWidth
	If $iCellWidth = 0 Or $iCellWidth = Default Then
		Local $iCellWidthMax
		Dim $aiCellWidth[UBound($aResult, $UBOUND_COLUMNS)]
		For $iRow = 0 To UBound($aResult, $UBOUND_ROWS) - 1
			For $iCol = 0 To UBound($aResult, $UBOUND_COLUMNS) - 1
				$iCellWidthMax = StringLen($aResult[$iRow][$iCol])
				If $iCellWidthMax > $aiCellWidth[$iCol] Then
					$aiCellWidth[$iCol] = $iCellWidthMax
				EndIf
			Next
		Next
	EndIf
	Local $sOut = "", $iCellWidthUsed
	For $iRow = 0 To UBound($aResult, $UBOUND_ROWS) - 1
		For $iCol = 0 To UBound($aResult, $UBOUND_COLUMNS) - 1
			If $iCellWidth = 0 Then
				$iCellWidthUsed = $aiCellWidth[$iCol]
			Else
				$iCellWidthUsed = $iCellWidth
			EndIf
			$sOut &= StringFormat(" %-" & $iCellWidthUsed & "." & $iCellWidthUsed & "s ", $aResult[$iRow][$iCol]) & $sDelim_Col
		Next
		$sOut &= $sDelim_Row
		If Not $bReturn Then
			__SQLite_Print($sOut)
			$sOut = ""
		EndIf
	Next
	If $bReturn Then Return $sOut
EndFunc   ;==>_SQLite_Display2DResult

This version has the possibility to declare Column and Row delimitation.

Test code is at https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/?do=findComment&comment=1417567

This change is not code braking.

Attachments (0)

Change History (3)

comment:1 by J-Paul Mesnage, on May 15, 2020 at 4:24:37 PM

Owner: set to J-Paul Mesnage
Status: newassigned

comment:2 by J-Paul Mesnage, on May 17, 2020 at 7:37:55 AM

Milestone: 3.3.15.4
Resolution: Completed
Status: assignedclosed

Added by revision [12326] in version: 3.3.15.4

comment:3 by argumentum, on Jun 24, 2020 at 4:15:24 PM

..there was a missing Default(s), so I added them all. ..and other tweaks.

; #FUNCTION# ====================================================================================================================
; Author ........: piccaso (Fida Florian)
; Modified.......: jchd, argumentum
; ===============================================================================================================================
Func _SQLite_Display2DResult($aResult, $iCellWidth = 0, $bReturn = False, $sDelim_Col = "", $sDelim_Row = @CRLF)
	If Not IsArray($aResult) Or UBound($aResult, $UBOUND_DIMENSIONS) <> 2 Or $iCellWidth < 0 Then Return SetError(1, 0, "")
	Local $aiCellWidth
	If $iCellWidth = Default Then $iCellWidth = 0
	If $sDelim_Col = Default Then $sDelim_Col = ""
	If $sDelim_Row = Default Then $sDelim_Row = @CRLF
	If $iCellWidth = 0 Or $iCellWidth = Default Then
		Local $iCellWidthMax
		Dim $aiCellWidth[UBound($aResult, $UBOUND_COLUMNS)]
		For $iRow = 0 To UBound($aResult, $UBOUND_ROWS) - 1
			For $iCol = 0 To UBound($aResult, $UBOUND_COLUMNS) - 1
				$iCellWidthMax = StringLen($aResult[$iRow][$iCol])
				If $iCellWidthMax > $aiCellWidth[$iCol] Then
					$aiCellWidth[$iCol] = $iCellWidthMax
				EndIf
			Next
		Next
	EndIf
	Local $sOut = "", $iCellWidthUsed
	Local $iUBound_ROWS = UBound($aResult, $UBOUND_ROWS) - 1
	Local $iUBound_COLS = UBound($aResult, $UBOUND_COLUMNS) - 1
	For $iRow = 0 To $iUBound_ROWS
		For $iCol = 0 To $iUBound_COLS
			If $iCellWidth = 0 Then
				$iCellWidthUsed = $aiCellWidth[$iCol]
			Else
				$iCellWidthUsed = $iCellWidth
			EndIf
			$sOut &= StringFormat(" %-" & $iCellWidthUsed & "." & $iCellWidthUsed & "s ", $aResult[$iRow][$iCol])
			If $iCol <> $iUBound_COLS Then $sOut &= $sDelim_Col
		Next
		$sOut &= $sDelim_Row
		If Not $bReturn Then
			__SQLite_Print($sOut)
			$sOut = ""
		EndIf
	Next
	If $bReturn Then
		If $sDelim_Col <> "" Then $sOut = StringTrimRight($sOut, StringLen($sDelim_Row))
		Return $sOut
	EndIf
EndFunc   ;==>_SQLite_Display2DResult

Modify Ticket

Action
as closed The owner will remain J-Paul Mesnage.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.