Leaderboard
Popular Content
Showing content with the highest reputation on 05/08/2025 in all areas
-
_StringToTable() – Convert Text\array to a text formatted table The _StringToTable() function allows you to convert structured text (like tab-separated data), or array into a formatted, aligned table using Unicode box-drawing characters. Ideal for displaying readable output in console-based tools or logs. Example1: string to table Local $sData = _ "Company" & @TAB & "Contact" & @TAB & "Revenue" & @CRLF & _ "Alfreds Futterkiste" & @TAB & "Maria Anders" & @TAB & "1200" & @CRLF & _ "Centro Moctezuma" & @TAB & "Francisco Chang" & @TAB & "950" & @CRLF & _ "Island Trading" & @TAB & "Helen Bennett" & @TAB & "15800" ConsoleWrite(_StringToTable($sData, 3, @TAB, "L,C,R") & @CRLF) ┌──────────────────────┬───────────────────┬──────────┐ │ Company │ Contact │ Revenue │ ├──────────────────────┼───────────────────┼──────────┤ │ Alfreds Futterkiste │ Maria Anders │ 1200 │ │ Centro Moctezuma │ Francisco Chang │ 950 │ │ Island Trading │ Helen Bennett │ 15800 │ └──────────────────────┴───────────────────┴──────────┘ Example2: array to table ; Make example array Local $aArray[10][5] For $i = 0 To 9 For $j = 0 To 4 $aArray[$i][$j] = $i & "-" & $j Next Next ;_ArrayDisplay($aArray, "example array") ; Make header and insert to array (when needed) Local $sHeader = "Column 0|Column 1|Column 2|Column 3|Column 4" _ArrayInsert($aArray, 0, $sHeader) If @error Then Exit MsgBox(16, "@error: " & @error, "Something went wrong with _ArrayInsert()") Local $sOut = _StringToTable($aArray, 3, @TAB, "C,C,C,C,C") ConsoleWrite($sOut & @CRLF & @CRLF) ┌──────────┬──────────┬──────────┬──────────┬──────────┐ │ Column 0 │ Column 1 │ Column 2 │ Column 3 │ Column 4 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │ 0-0 │ 0-1 │ 0-2 │ 0-3 │ 0-4 │ │ 1-0 │ 1-1 │ 1-2 │ 1-3 │ 1-4 │ │ 2-0 │ 2-1 │ 2-2 │ 2-3 │ 2-4 │ │ 3-0 │ 3-1 │ 3-2 │ 3-3 │ 3-4 │ │ 4-0 │ 4-1 │ 4-2 │ 4-3 │ 4-4 │ │ 5-0 │ 5-1 │ 5-2 │ 5-3 │ 5-4 │ │ 6-0 │ 6-1 │ 6-2 │ 6-3 │ 6-4 │ │ 7-0 │ 7-1 │ 7-2 │ 7-3 │ 7-4 │ │ 8-0 │ 8-1 │ 8-2 │ 8-3 │ 8-4 │ │ 9-0 │ 9-1 │ 9-2 │ 9-3 │ 9-4 │ └──────────┴──────────┴──────────┴──────────┴──────────┘ Example4: Example floating point format $sData = "" ; from https://www.autoitscript.com/forum/topic/212833-json-udf-using-json-c/#findComment-1542670 $sData &= " name | time[ms] | factor | Std. Dev | Std. Err. | min | max | range |" & @CRLF $sData &= " StringRegExp only | 1.691 | 1 | 0.351 | 0.035 | 1.304 | 3.167 | 1.863 |" & @CRLF $sData &= " jq UDF | 32.933 | 19.48 | 2.929 | 0.293 | 29.308 | 43.169 | 13.861 |" & @CRLF $sData &= " JsonC-UDF | 51.086 | 30.21 | 3.205 | 0.321 | 45.625 | 63.46 | 17.835 |" & @CRLF $sData &= " pure AutoIt JSON-UDF | 97.916 | 57.9 | 5.685 | 0.569 | 86.362 | 113.467 | 27.105 |" & @CRLF $sData &= " JSMN-based JSON-UDF | 108.248 | 64.01 | 5.512 | 0.551 | 99.029 | 130.864 | 31.835 |" & @CRLF $sOut = _StringToTable($sData, 3, "|", "L,3,2,3,3,3,3,3") ConsoleWrite($sOut & @CRLF & @CRLF) ┌──────────────────────┬──────────┬────────┬──────────┬───────────┬────────┬─────────┬────────┐ │ name │ time[ms] │ factor │ Std. Dev │ Std. Err. │ min │ max │ range │ ├──────────────────────┼──────────┼────────┼──────────┼───────────┼────────┼─────────┼────────┤ │ StringRegExp only │ 1.691 │ 1.00 │ 0.351 │ 0.035 │ 1.304 │ 3.167 │ 1.863 │ │ jq UDF │ 32.933 │ 19.48 │ 2.929 │ 0.293 │ 29.308 │ 43.169 │ 13.861 │ │ JsonC-UDF │ 51.086 │ 30.21 │ 3.205 │ 0.321 │ 45.625 │ 63.460 │ 17.835 │ │ pure AutoIt JSON-UDF │ 97.916 │ 57.90 │ 5.685 │ 0.569 │ 86.362 │ 113.467 │ 27.105 │ │ JSMN-based JSON-UDF │ 108.248 │ 64.01 │ 5.512 │ 0.551 │ 99.029 │ 130.864 │ 31.835 │ └──────────────────────┴──────────┴────────┴──────────┴───────────┴────────┴─────────┴────────┘ Thanks to pixelsearch's magic filter on Regex pattern allowing the user to have the possibility to indicate not only [LRClrc] or [0-9] but also any valid StringFormat expression (starting with %). A big thank you to pixelsearch 🏆 for his contribution Made with ❤️ for readable and elegant output. ; https://www.autoitscript.com/forum/topic/212876-_stringtotable/ ;---------------------------------------------------------------------------------------- ; Title...........: _StringToTable.au3 ; Description.....: Converts a string to a formatted table with alignment and frame options. ; AutoIt Version..: 3.3.16.1 Author: ioa747 Script Version: 0.6 ; Note............: Testet in Win10 22H2 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <Array.au3> #include <String.au3> Example1() ; Example string to table ;~ Example2() ; Example 2D array to table ;~ Example3() ; Example 1D array to table ;~ Example4() ; Example floating point format ;~ Example5() ; Example for new frame style ;~ Example6() ; Example StringFormat expression ;~ Example7() ; Example from clopboard ;--------------------------------------------------------------------------------------- Func Example1() ; Example string to table Local $sSum, $sOut Local $sData = _ "Company" & @TAB & "Contact" & @TAB & "Revenue" & @CRLF & _ "Alfreds Futterkiste" & @TAB & "Maria Anders" & @TAB & "1200" & @CRLF & _ "Centro Moctezuma" & @TAB & "Francisco Chang" & @TAB & "950" & @CRLF & _ "Island Trading" & @TAB & "Helen Bennett" & @TAB & "15800" $sOut = _StringToTable($sData, 0, @TAB, "L,C,R") ConsoleWrite($sOut & @CRLF & @CRLF) $sSum &= $sOut & @CRLF & @CRLF $sOut = _StringToTable($sData, 1, @TAB, "L,C,R") ConsoleWrite($sOut & @CRLF & @CRLF) $sSum &= $sOut & @CRLF & @CRLF $sOut = _StringToTable($sData, 2, @TAB, "L,C,R") ConsoleWrite($sOut & @CRLF & @CRLF) $sSum &= $sOut & @CRLF & @CRLF & @CRLF $sSum &= "Notes: For the correct display of output, it is recommended to use a MonoSpace font." & @CRLF $sSum &= "Window MonoSpace font: Consolas, DejaVu Sans Mono, Courier New, Lucida Console" & @CRLF ClipPut($sSum) ShellExecute("notepad.exe") WinWaitActive("[CLASS:Notepad]", "", 5) Sleep(100) Send("^v") EndFunc ;==>Example1 ;--------------------------------------------------------------------------------------- Func Example2() ; Example 2D array to table ; Make example array Local $aArray[10][5] For $i = 0 To 9 For $j = 0 To 4 $aArray[$i][$j] = $i & "-" & $j Next Next ;_ArrayDisplay($aArray, "example array") ; Make header and insert to array (when needed) Local $sHeader = "Column 0|Column 1|Column 2|Column 3|Column 4" _ArrayInsert($aArray, 0, $sHeader) If @error Then Exit MsgBox(16, "@error: " & @error, "Something went wrong with _ArrayInsert()") Local $sOut = _StringToTable($aArray, 3, -1, "C,C,C,C,C") ConsoleWrite($sOut & @CRLF & @CRLF) ClipPut($sOut) ShellExecute("notepad.exe") WinWaitActive("[CLASS:Notepad]", "", 5) Sleep(100) Send("^v") EndFunc ;==>Example2 ;--------------------------------------------------------------------------------------- Func Example3() ; Example 1D array to table Local $sMonth = "Months, January, February, March, April, May, June, July, August, September, October, November, December" Local $aMonth = StringSplit($sMonth, ", ", 3) Local $sOut = _StringToTable($aMonth, 3, -1, "C") ConsoleWrite($sOut & @CRLF & @CRLF) ClipPut($sOut) ShellExecute("notepad.exe") WinWaitActive("[CLASS:Notepad]", "", 5) Sleep(100) Send("^v") EndFunc ;==>Example3 ;--------------------------------------------------------------------------------------- Func Example4() ; Example floating point format Local $sData = "" ; from https://www.autoitscript.com/forum/topic/212833-json-udf-using-json-c/#findComment-1542670 $sData &= " name | time[ms] | factor | Std. Dev | Std. Err. | min | max | range |" & @CRLF $sData &= " StringRegExp only | 1.691 | 1 | 0.351 | 0.035 | 1.304 | 3.167 | 1.863 |" & @CRLF $sData &= " jq UDF | 32.933 | 19.48 | 2.929 | 0.293 | 29.308 | 43.169 | 13.861 |" & @CRLF $sData &= " JsonC-UDF | 51.086 | 30.21 | 3.205 | 0.321 | 45.625 | 63.46 | 17.835 |" & @CRLF $sData &= " pure AutoIt JSON-UDF | 97.916 | 57.9 | 5.685 | 0.569 | 86.362 | 113.467 | 27.105 |" & @CRLF $sData &= " JSMN-based JSON-UDF | 108.248 | 64.01 | 5.512 | 0.551 | 99.029 | 130.864 | 31.835 |" & @CRLF Local $sOut = _StringToTable($sData, 3, "|", "L,3,2,3,3,3,3,3") ConsoleWrite($sOut & @CRLF & @CRLF) ClipPut($sOut) ShellExecute("notepad.exe") WinWaitActive("[CLASS:Notepad]", "", 5) Sleep(100) Send("^v") EndFunc ;==>Example4 ;--------------------------------------------------------------------------------------- Func Example5() ; Example for new frame style Local $sData = "" ; from https://www.autoitscript.com/forum/topic/212833-json-udf-using-json-c/#findComment-1542670 $sData &= " name | time[ms] | factor | Std. Dev | Std. Err. | min | max | range |" & @CRLF $sData &= " StringRegExp only | 1.691 | 1 | 0.351 | 0.035 | 1.304 | 3.167 | 1.863 |" & @CRLF $sData &= " jq UDF | 32.933 | 19.48 | 2.929 | 0.293 | 29.308 | 43.169 | 13.861 |" & @CRLF $sData &= " JsonC-UDF | 51.086 | 30.21 | 3.205 | 0.321 | 45.625 | 63.46 | 17.835 |" & @CRLF $sData &= " pure AutoIt JSON-UDF | 97.916 | 57.9 | 5.685 | 0.569 | 86.362 | 113.467 | 27.105 |" & @CRLF $sData &= " JSMN-based JSON-UDF | 108.248 | 64.01 | 5.512 | 0.551 | 99.029 | 130.864 | 31.835 |" & @CRLF Local $sOut = _DblFrame($sData, "|", "L,3,2,3,3,3,3,3") ConsoleWrite($sOut & @CRLF & @CRLF) ClipPut($sOut) ShellExecute("notepad.exe") WinWaitActive("[CLASS:Notepad]", "", 5) Sleep(100) Send("^v") EndFunc ;==>Example5 ;--------------------------------------------------------------------------------------- Func Example6() ; Example StringFormat expression ; Make example array Local $aArray[10][6] For $i = 0 To 9 For $j = 0 To 5 $aArray[$i][$j] = $i & "." & $j If $j > 2 Then $aArray[$i][$j] = $i * 1000000 Next Next ;_ArrayDisplay($aArray, "example array") ; Make header and insert to array (when needed) Local $sHeader = "Column 0|Column 1|Column 2|Column 3|Column 4|Column 5" _ArrayInsert($aArray, 0, $sHeader) If @error Then Exit MsgBox(16, "@error: " & @error, "Something went wrong with _ArrayInsert()") ; accept any valid string format expression (starting with %) Local $sOut = _StringToTable($aArray, 3, -1, "%03i,2,3,0,%#08x,%06x") ConsoleWrite($sOut & @CRLF & @CRLF) ClipPut($sOut) ShellExecute("notepad.exe") WinWaitActive("[CLASS:Notepad]", "", 5) Sleep(100) Send("^v") EndFunc ;==>Example6 ;--------------------------------------------------------------------------------------- Func Example7() ; Example from clopboard ; ### First copy the following to the clipboard, and then run example 7 ### ;name time[ms] factor Std. Dev Std. Err. min max range ;StringRegExp only 1.691 1.00 0.351 0.035 1.304 3.167 1.863 ;jq UDF 32.933 19.48 2.929 0.293 29.308 43.169 13.861 ;JsonC-UDF 51.086 30.21 3.205 0.321 45.625 63.460 17.835 ;pure AutoIt JSON-UDF 97.916 57.90 5.685 0.569 86.362 113.467 27.105 ;JSMN-based JSON-UDF 108.248 64.01 5.512 0.551 99.029 130.864 31.835 Local $sData = ClipGet() Sleep(100) Local $sOut = _StringToTable($sData) ConsoleWrite($sOut & @CRLF & @CRLF) EndFunc ;==>Example7 ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: _StringToTable ; Description....: Converts a string or array to a formatted table with alignment and frame options. ; Syntax.........: _StringToTable( $vString [, $iFrame = 2 [, $sSeparator = @TAB [, $sAlign = ""]]] ) ; Parameters.....: $vString - The input string or array containing data values. ; $iFrame - [optional] Frame type (0=NoFrame, 1=FrameNoHeader, 2=FrameAndHeader. (Default is 2) ; $sSeparator - [optional] Separator used in the input string. (Default is @TAB) ; $sAlign - [optional] Alignment options for each column "L,R,C,[0-9],[%..]". (Default is "" (left-aligned)) ; L=Left, R=Right, C=Center, [0-9]=digits after decimal point, [%..]=Any valid StringFormat(starting with %) ; Return values..: The formatted table as a string. ; Author ........: ioa747 ; Notes .........: For the correct display of output, it is recommended to use a MonoSpace font. ; Window MonoSpace font: Consolas, DejaVu Sans Mono, Courier New, Lucida Console ; Link ..........: https://www.autoitscript.com/forum/topic/212876-_stringtotable/ ; Dependencies...: __FormatCell() ;-------------------------------------------------------------------------------------------------------------------------------- Func _StringToTable($vString, $iFrame = 2, $sSeparator = @TAB, $sAlign = "") ;Local $hTimer = TimerInit() If $iFrame < 0 Or $iFrame > 2 Or $iFrame = Default Then $iFrame = 2 If $sSeparator = Default Or $sSeparator = -1 Then $sSeparator = @TAB ; Convert array to string If IsArray($vString) Then Local $b2D = (UBound($vString, 0) = 1 ? False : True) If Not $b2D Then _ArrayColInsert($vString, 1) $vString = _ArrayToString($vString, $sSeparator) EndIf ;Prepare string $vString = StringRegExpReplace($vString, "(\r\n|\n)", @CRLF) $vString = StringReplace($vString, $sSeparator & @CRLF, @CRLF) $vString = StringReplace($vString, @CRLF & $sSeparator, @CRLF) $vString = StringStripCR(StringRegExpReplace($vString, "(\r\n)$", "")) ;ConsoleWrite($vString & @CRLF) Local $aRows = StringSplit($vString, @LF, 1) If $aRows[0] = 0 Then Return SetError(1, 0, "") Local $aTable[UBound($aRows)][0] Local $iLen, $iCols = 0 ; initialize rows and columns For $i = 1 To $aRows[0] Local $aCols = StringSplit($aRows[$i], $sSeparator, 1) If $i = 1 Then $iCols = $aCols[0] ReDim $aTable[$aRows[0]][$iCols] Else If $aCols[0] < $iCols Then ReDim $aCols[$iCols + 1] ;** EndIf For $j = 0 To $iCols - 1 $aTable[$i - 1][$j] = StringStripWS($aCols[$j + 1], 3) Next Next ; find the max column widths Local $aColWidths[$iCols] For $j = 0 To $iCols - 1 $aColWidths[$j] = 0 For $i = 0 To UBound($aTable) - 1 $iLen = StringLen($aTable[$i][$j]) If $aColWidths[$j] < $iLen Then $aColWidths[$j] = $iLen Next Next ; Alignment initialize Local $aAlign[$iCols] If $sAlign <> "" Then Local $aFormat Local $aRawAlign = StringSplit($sAlign, ",", 2) Local $iRawCnt = UBound($aRawAlign) For $j = 0 To $iCols - 1 If $j >= $iRawCnt Then $aAlign[$j] = "L" Else $aAlign[$j] = StringStripWS($aRawAlign[$j], 3) $aFormat = StringRegExp($aAlign[$j], "^([LRClrc]|[0-9]|%[\-+0\x20#]?\d*(?:\.\d+)?[diouxXeEfgGs])$", 3) Select Case (Not IsArray($aFormat)) Or UBound($aFormat) > 1 $aAlign[$j] = "L" Case StringIsAlpha($aFormat[0]) ; LRClrc => nothing to do Case Else ; 0-9 OR %... (StringFormat indicated by user) ; re-find the max column widths For $i = 0 To UBound($aTable) - 1 $iLen = StringLen(StringFormat( _ (StringIsDigit($aFormat[0]) ? ("%." & $aAlign[$j] & "f") : $aAlign[$j]), _ $aTable[$i][$j])) If $iLen > $aColWidths[$j] Then $aColWidths[$j] = $iLen Next EndSelect EndIf Next Else For $j = 0 To $iCols - 1 $aAlign[$j] = "L" Next EndIf Local Const $TL = "┌", $TR = "┐", $BL = "└", $BR = "┘", $H = "─", $V = "│", _ $C = "┼", $TH = "┬", $CH = "┴", $LH = "├", $RH = "┤" Local $bHeader = ($iFrame = 2) Local $bBorder = ($iFrame = 1 Or $iFrame = 2) Local $sPre = ($iFrame = 0 ? "" : " ") Local $sResult = "" ; Top border If $bBorder Then $sResult &= $TL For $j = 0 To $iCols - 1 $sResult &= _StringRepeat($H, $aColWidths[$j] + 2) $sResult &= ($j < $iCols - 1) ? $TH : $TR Next $sResult &= @LF EndIf ; Header row If $bHeader Then $sResult &= $V For $j = 0 To $iCols - 1 $sResult &= $sPre & __FormatCell($aTable[0][$j], $aColWidths[$j], $aAlign[$j]) & " " If $j < $iCols - 1 Then $sResult &= $V Next $sResult &= $V & @LF ; Header separator $sResult &= $LH For $j = 0 To $iCols - 1 $sResult &= _StringRepeat($H, $aColWidths[$j] + 2) $sResult &= ($j < $iCols - 1 ? $C : $RH) Next $sResult &= @LF EndIf ; Data rows For $i = ($bHeader ? 1 : 0) To UBound($aTable) - 1 If $bBorder = 2 Then $sResult &= $V For $j = 0 To $iCols - 1 $sResult &= $sPre & __FormatCell($aTable[$i][$j], $aColWidths[$j], $aAlign[$j]) & " " If $j < $iCols - 1 Then $sResult &= $bBorder ? $V : "" Next If $bBorder Then $sResult &= $V $sResult &= @LF Next ; Bottom border If $bBorder Then $sResult &= $BL For $j = 0 To $iCols - 1 $sResult &= _StringRepeat($H, $aColWidths[$j] + 2) $sResult &= ($j < $iCols - 1) ? $CH : $BR Next EndIf ;$sResult = BinaryToString(StringToBinary($sResult, 4), 1) ; * ?? ;ConsoleWrite("> processed in: " & Round(TimerDiff($hTimer)) & " ms " & @LF) Return $sResult EndFunc ;==>_StringToTable ;--------------------------------------------------------------------------------------- Func __FormatCell($text, $width, $align) ; internal Switch $align Case "L" Return StringFormat("%-" & $width & "s", $text) Case "R" Return StringFormat("%" & $width & "s", $text) Case "C" Local $pad = $width - StringLen($text) Local $left = Floor($pad / 2) Local $right = $pad - $left Return _StringRepeat(" ", $left) & $text & _StringRepeat(" ", $right) Case Else ; 0-9 OR %... (StringFormat indicated by user) If StringRegExp($text, "^[+\-]?(\d*\.\d+|\d+\.?)$") Then ; numeric column (data) Return StringFormat("%" & $width & "s", StringFormat( _ (StringIsDigit($align) ? ("%." & $align & "f") : $align), _ $text)) Else ; numeric column (header) align header usually to right (or to left if "%-" found) Return StringFormat("%" & _ ((StringLeft($align, 2) = "%-") ? "-" : "") & _ $width & "s", $text) EndIf EndSwitch EndFunc ;==>__FormatCell ;--------------------------------------------------------------------------------------- Func _DblFrame($vString, $sSeparator = @TAB, $sAlign = "") ; * style template Local $sData = _StringToTable($vString, 3, $sSeparator, $sAlign) Local $aData = StringSplit($sData, @LF, 3) Local $iCnt = UBound($aData) - 1 Local $sOut For $i = 0 To $iCnt Switch $i Case 0 $aData[$i] = StringReplace($aData[$i], "┌", "╔", 1, 2) $aData[$i] = StringReplace($aData[$i], "─", "═", 0, 2) $aData[$i] = StringReplace($aData[$i], "┬", "╤", 0, 2) $aData[$i] = StringReplace($aData[$i], "┐", "╗", -1, 2) Case 2 $aData[$i] = StringReplace($aData[$i], "├", "╟", 1, 2) $aData[$i] = StringReplace($aData[$i], "┤", "╢", -1, 2) Case $iCnt $aData[$i] = StringReplace($aData[$i], "└", "╚", 1, 2) $aData[$i] = StringReplace($aData[$i], "─", "═", 0, 2) $aData[$i] = StringReplace($aData[$i], "┴", "╧", 0, 2) $aData[$i] = StringReplace($aData[$i], "┘", "╝", -1, 2) Case Else $aData[$i] = StringReplace($aData[$i], "│", "║", 1, 2) $aData[$i] = StringReplace($aData[$i], "│", "║", -1, 2) EndSwitch $sOut &= $aData[$i] & @CRLF Next $sOut = StringReplace($sOut, @CRLF, "", -1, 2) Return $sOut EndFunc ;==>_DblFrame ;--------------------------------------------------------------------------------------- Please, every comment is appreciated! leave your comments and experiences here! Thank you very much Relative: https://www.autoitscript.com/forum/topic/211237-treestructuredir/2 points
-
_StringToTable
Musashi and one other reacted to SOLVE-SMART for a topic
First of all and to clarify: I don't see this as a competition - just in case you folks would think of this regarding @ioa747 and me 😆 . I agree. I guess extending the border styles (frame types) is just a gimmick. Nevertheless, I played a bit with my version of DataToTable.au3 which lead to v0.2.0. In the README.md section output-result you can see a fourth border style "4=BorderAndHeaderEdgesWithAccent" as a example. In the CHANGELOG.md you will find how I changed it. To achieve the styling above (shared by @argumentum) it would lead to some more code adjustments, but at the moment I don't have the desire to implement it - sorry @WildByDesign 😅 . Best regards Sven2 points -
_StringToTable
Musashi and one other reacted to WildByDesign for a topic
My initial thought with this was to make some elegant and beautiful MsgBox's, particularly About dialogs, etc. But I realized that the output from _stringtotable simply wasn't lining up properly in a MsgBox. So I decided try it with the ExtMsgBox UDF since it has more customizing options. That also came up all scrambled. Until... I realized that I would need to use a monospaced font like in other projects. Cascadia Mono didn't look as nice. So I did Consolas and it looked great. Basically, the following code was added: #include "ExtMsgBox.au3" _ExtMsgBoxSet(1, 4, 0x202020, 0xe0e0e0, -1, "Consolas", 1200, 1200) _ExtMsgBox (0, 0, "_ExtMsgBox", $sOut) The _ExtMsgBox (0, 0, "_ExtMsgBox", $sOut) just needed to be adapted into the right area of examples, of course. Screenshots: So this opens up some nice possibilities for my usage of it. Thanks again for sharing this. Also, @SOLVE-SMART I am going to follow your progress on this as well.2 points -
I'm closing this topic as I have found a solution. Basically, in the app I'm flipping between my regular domain, and the global domain, and the flipping action was not properly setting things up in the initial go-from-regular-to-global-domain action. This was causing the AD query to fail. Thanks to everyone who may have already looked at this issue, and I'm now sorry that I brought this up. Bob1 point
-
_StringToTable
ioa747 reacted to argumentum for a topic
╔══════════════════════╤══════════╤════════╤══════════╤═══════════╤════════╤═════════╤════════╗ ║ name │ time[ms] │ factor │ Std. Dev │ Std. Err. │ min │ max │ range ║ ╟──────────────────────┼──────────┼────────┼──────────┼───────────┼────────┼─────────┼────────╢ ║ StringRegExp only │ 1.691 │ 1.00 │ 0.351 │ 0.035 │ 1.304 │ 3.167 │ 1.863 ║ ║ jq UDF │ 32.933 │ 19.48 │ 2.929 │ 0.293 │ 29.308 │ 43.169 │ 13.861 ║ ║ JsonC-UDF │ 51.086 │ 30.21 │ 3.205 │ 0.321 │ 45.625 │ 63.460 │ 17.835 ║ ║ pure AutoIt JSON-UDF │ 97.916 │ 57.90 │ 5.685 │ 0.569 │ 86.362 │ 113.467 │ 27.105 ║ ║ JSMN-based JSON-UDF │ 108.248 │ 64.01 │ 5.512 │ 0.551 │ 99.029 │ 130.864 │ 31.835 ║ ╚══════════════════════╧══════════╧════════╧══════════╧═══════════╧════════╧═════════╧════════╝ ..that takes more coding ( edited by hand above ). The question is: how far is this going to be taken ?, ... the original is good as far as prettifying a table to separate the content from the header and delimiting columns. Other than that, what's the use ?. My 2 cents1 point -
_StringToTable
Musashi reacted to argumentum for a topic
╔══════════════════════╦══════════╦════════╦══════════╦═══════════╦════════╦═════════╦════════╗ ║ name ║ time[ms] ║ factor ║ Std. Dev ║ Std. Err. ║ min ║ max ║ range ║ ╠══════════════════════╬══════════╬════════╬══════════╬═══════════╬════════╬═════════╬════════╣ ║ StringRegExp only ║ 1.691 ║ 1.00 ║ 0.351 ║ 0.035 ║ 1.304 ║ 3.167 ║ 1.863 ║ ║ jq UDF ║ 32.933 ║ 19.48 ║ 2.929 ║ 0.293 ║ 29.308 ║ 43.169 ║ 13.861 ║ ║ JsonC-UDF ║ 51.086 ║ 30.21 ║ 3.205 ║ 0.321 ║ 45.625 ║ 63.460 ║ 17.835 ║ ║ pure AutoIt JSON-UDF ║ 97.916 ║ 57.90 ║ 5.685 ║ 0.569 ║ 86.362 ║ 113.467 ║ 27.105 ║ ║ JSMN-based JSON-UDF ║ 108.248 ║ 64.01 ║ 5.512 ║ 0.551 ║ 99.029 ║ 130.864 ║ 31.835 ║ ╚══════════════════════╩══════════╩════════╩══════════╩═══════════╩════════╩═════════╩════════╝ ... ... Local Const $TL = "╔", $TR = "╗", $BL = "╚", $BR = "╝" Local Const $H = "═", $V = "║", $C = "╬" Local Const $TH = "╦", $CH = "╩", $LH = "╠", $RH = "╣" ... ...1 point -
_StringToTable
ioa747 reacted to WildByDesign for a topic
Would you be willing to add another $iFrame option? If possible, it would be good to have an option that does a border for only the outer frame of the table.1 point -
_StringToTable
argumentum reacted to ioa747 for a topic
I added the ability for 1D array, and floating point as format , to control digits after decimal point [0-3]f e.g. 0f, for no decimal point, , 2f for 2 digits after decimal point1 point -
_ArrayToMdTable
SOLVE-SMART reacted to ioa747 for a topic
_ArrayToMdTable Converts an array to a markdown table format | Item | In Stock | Price | | :---------------- | :------: | ----: | | Python Hat | True | 23.99 | | SQL Hat | True | 23.99 | | Codecademy Tee | False | 19.99 | | Codecademy Hoodie | False | 42.99 | @SOLVE-SMART I did it on the occasion of your suggestion. I modified it to better suit the requirements of Markdown, and to be more readable. ; https://www.autoitscript.com/forum/topic/212883-_arraytomdtable ;---------------------------------------------------------------------------------------- ; Title...........: _ArrayToMdTable ; Description.....: Converts an array to a markdown table format. ; AutoIt Version..: 3.3.16.1 Author: ioa747 Script Version: 1.0 ; Note............: Testet in Win10 22H2 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <Array.au3> #include <String.au3> Example1() ; Example 2D array to table Example2() ; Example 1D array to table ;--------------------------------------------------------------------------------------- Func Example1() ; Example 2D array to table Local $aData[5][3] = [["Item", "In Stock", "Price"], _ ["Python Hat", "True", "23.99"], _ ["SQL Hat", "True", "23.99"], _ ["Codecademy Tee", "False", "19.99"], _ ["Codecademy Hoodie", "False", "42.99"]] Local $sTable = _ArrayToMdTable($aData, "L,C,R") ConsoleWrite($sTable) EndFunc ;==>Example1 ;--------------------------------------------------------------------------------------- Func Example2() ; Example 1D array to table Local $sMonth = "Months, January, February, March, April, May, June, July, August, September, October, November, December" Local $aMonth = StringSplit($sMonth, ", ", 3) $sMonth = _ArrayToMdTable($aMonth, "C") ConsoleWrite($sMonth) EndFunc ;==>Example2 ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: _ArrayToMDtable ; Description....: Converts an array to a Markdown table format. ; Syntax.........: _ArrayToMdTable( $aArray [, $sAlign = "" ] ) ; Parameters.....: $aArray - The array to be converted. ; $sAlign - [optional] Alignment options for each column (e.g., "L,R,C"). (Default is "" (left-aligned)) ; Return values..: The formatted table as a string. ; Author ........: ioa747 ; Notes .........: This function takes a array and converts it into a Markdown table. ; It calculates the width of each column based on the longest string in that column. ; Link ..........: ; Dependencies...: __FormatCell() ;------------------------------------------------------------------------------------------------------------------------------------ Func _ArrayToMdTable($aArray, $sAlign = "") Local $sTable = "" Local $b2D = (UBound($aArray, 0) = 1 ? False : True) ; if $aArray = 1D => force 2D (Insert extra coloumn) If Not $b2D Then _ArrayColInsert($aArray, 1) Local $iRowCount = UBound($aArray, 1) Local $iColCount = UBound($aArray, 2) Local $aColWidths[$iColCount] Local $aAlign[$iColCount] ; get max width For $j = 0 To $iColCount - 1 $aColWidths[$j] = 0 For $i = 0 To $iRowCount - 1 $aColWidths[$j] = $aColWidths[$j] > StringLen($aArray[$i][$j]) ? $aColWidths[$j] : StringLen($aArray[$i][$j]) Next Next ; Alignment initialize If $sAlign <> "" Then Local $aRawAlign = StringSplit($sAlign, ",", 2) Local $iRawCnt = UBound($aRawAlign) For $j = 0 To $iColCount - 1 If $j >= $iRawCnt Then $aAlign[$j] = "L" Else $aAlign[$j] = StringStripWS(StringUpper($aRawAlign[$j]), 3) If Not StringRegExp($aAlign[$j], "^[LRC]$") Then $aAlign[$j] = "L" EndIf Next Else For $j = 0 To $iColCount - 1 $aAlign[$j] = "L" Next EndIf ; Create the header row For $i = 0 To $iColCount - 1 $sTable &= "| " & __FormatCell($aArray[0][$i], $aColWidths[$i], $aAlign[$i]) & " " Next $sTable &= "|" & @CRLF ; Create the alignment row $sTable &= "|" For $i = 0 To $iColCount - 1 Switch $aAlign[$i] Case "L" $sTable &= " :" & _StringRepeat("-", $aColWidths[$i] - 1) & " " Case "R" $sTable &= " " & _StringRepeat("-", $aColWidths[$i] - 1) & ": " Case "C" $sTable &= " :" & _StringRepeat("-", $aColWidths[$i] - 2) & ": " Case Else $sTable &= " " & _StringRepeat("-", $aColWidths[$i]) & " " EndSwitch $sTable &= "|" Next $sTable &= @CRLF ; Create the data rows For $i = 1 To $iRowCount - 1 For $j = 0 To $iColCount - 1 $sTable &= "| " & __FormatCell($aArray[$i][$j], $aColWidths[$j], $aAlign[$j]) & " " Next $sTable &= "|" & @CRLF Next ; remove the extra coloumn If Not $b2D Then $sTable = StringRegExpReplace($sTable, "(\| \||\| : \||\| :: \|)", "|") Return $sTable EndFunc ;==>_ArrayToMdTable ;--------------------------------------------------------------------------------------- Func __FormatCell($text, $width, $align) ; internal Switch $align Case "R" Return StringFormat("%" & $width & "s", $text) Case "C" Local $pad = $width - StringLen($text) Local $left = Floor($pad / 2) Local $right = $pad - $left Return _StringRepeat(" ", $left) & $text & _StringRepeat(" ", $right) Case Else ; "L" Return StringFormat("%-" & $width & "s", $text) EndSwitch EndFunc ;==>__FormatCell ;--------------------------------------------------------------------------------------- Please, every comment is appreciated! leave your comments and experiences here! Thank you very much1 point -
_ArrayToMdTable
ioa747 reacted to SOLVE-SMART for a topic
Well done @ioa747 👌 . Funny because I wrote in the other thread here about how I did rewrote your _StringToTable UDF. I am pretty sure I will review your new feature and will add it in a similar style to my DataToTable UDF. Thanks 😀 . Best regards Sven1 point -
1 point
-
get handle with RegExp RegExpQuickTester 2.5p will help put all the ClassNameNN keys here old and new here you can put your filter (Search pattern) an, in live time, test the pattern, and see which cases it catches, and readjust it here it shows which cases it catches here I have put '3 - Retum array of global matches' here you can use it as a storage space (for copying and pasting) Until now we use CLASSNN which is CLASS & INSTANCE ControlClick($hWnd, "", "WindowsForms10.Window.8.app.0.1a52015_r22_ad11") WindowsForms10.Window.8.app.0.1a52015_r22_ad11 = WindowsForms10.Window.8.app.0.1a52015_r22_ad1 & 1 now we will go to logic ; ControlClick($hWnd, "", "[REGEXPCLASS:<>; INSTANCE:<>]") ; where REGEXPCLASS:<> we put *2 the 'Search pattern' ; where INSTANCE:<> we put the instance e.g. 1 ControlClick($hWnd, "", "[REGEXPCLASS:WindowsForms10\.Window\.8\.app\.0\..*._r.*._ad1 ; INSTANCE:1]") ; Wait 3 seconds for the ShareX - Editor menu window to appear. Local $hWnd = WinWait("ShareX - Editor menu", "", 3) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hWnd = ' & $hWnd & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ; Retrieve the handle of the MenuBar control in ShareX - Editor menu" Local $hCtrMenuBar = ControlGetHandle($hWnd, "", "[REGEXPCLASS:WindowsForms10\.Window\.8\.app\.0\..*._r.*._ad1; INSTANCE:1]") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hCtrMenuBar = ' & $hCtrMenuBar & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ControlClick($hWnd, "", $hCtrMenuBar ) here I must emphasize that we behave differently in Handle controls than Handle windows ShellExecute(@WindowsDir & '\hh.exe', 'ms-its:' _ & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 2, -1) - 1) & "\AutoIt.chm" _ & '::/html/intro/controls.htm') ShellExecute(@WindowsDir & '\hh.exe', 'ms-its:' _ & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 2, -1) - 1) & "\AutoIt.chm" _ & '::/html/intro/windowsadvanced.htm') with windows handle: ; Until now we use CLASS or TITLE ; WinWait("[CLASS:<>; TITLE:<>]") WinWait("[CLASS:WindowsForms10.Window.808.app.0.1a52015_r22_ad1]") ; now we will go to logic ; WinWait("[REGEXPCLASS:<>; REGEXPTITLE:<>]") ; WinWait("[REGEXPCLASS:<>; TITLE:<>]") ; WindowsForms10\.Window\..*808*.\.app\.0\..*._r.*._ad1 WinWait("[REGEXPCLASS:WindowsForms10\.Window\..*808*.\.app\.0\..*._r.*._ad1]")1 point