Jump to content

Autoit-DD (Get useful information about any Autoit variable)


tarretarretarre
 Share

Recommended Posts

About AutoIt-DD

AutoIt-DD is an carbon copy of Laravels dd helper. DD stands for "Dump and DIE" and is a great tool for debugging AutoIt variables

Features

  • Get useful information about any AutoIt variable
  • Nested Arrays and Scripting dictionaries
  • Multi DIM arrays
  • Great structure and colored output

Example

In Example.au3 you can run a fully featured example, but I also provided a print screen for you lazy people

Dowonload

 

Link to comment
Share on other sites

For convenience  sake you can put DD.au3 in your AutoIt install directory C:\Program Files (x86)\AutoIt3\Include That will cause "#include <DD.au3>" to be available in every .au3-file

Update, do this instead!

28 minutes ago, water said:

I suggest to save DD in the User Include Folder which you can specify with SciTEConfig.

 

Edited by tarretarretarre
Link to comment
Share on other sites

I suggest to save DD in the User Include Folder which you can specify with SciTEConfig.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

29 minutes ago, water said:

I suggest to save DD in the User Include Folder which you can specify with SciTEConfig.

Of course, I forgot about that. Thanks!

Inside Scite config (hotkey CTRL + 1) in the general 1 tab, you can set the User include folder.


image.png.086f5b0e3c6ecb4e97cbb1fbf1c0855d.png
 

Link to comment
Share on other sites

  • 3 years later...

I really liked this script with one exception - it doesn't work for a GUI script. SO! I went in and changed it so it builds a string of a variable and then shows it before returning. I hope everyone likes it. Also included the ZIP file with my file (ie: DDW.au3) which stands for DD Windows. :-) Updated the number to v1.1.0 because it is not really a new program. :-)



 

#cs
    Copyright (c) 2020 TarreTarreTarre <tarre.islam@gmail.com>
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
#ce
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
#include-once

; #FUNCTION# ====================================================================================================================
; Name ..........: DDW
; Description ...: Displays useful information about a variable or object in the console
; Syntax ........: DDW($any[, $exit = True])
; Parameters ....: $any                 - anything.
;                  $exit                - [optional] an boolean value. Default is True.
; Return values .: None
; Author ........: TarreTarreTarre and Mark Manning (only made changes)
; Modified ......: May 9, 2024
; Remarks .......: Made it so this works for MsgBox
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================

Global $__DDW_String = "";
Func DD($any, $exit = True)
    $__DDW_String = @crlf & "--->Starting Debug" & @crlf & @crlf;
    __DD($any, 0)
    $__DDW_String &= @crlf & "<---Exiting Debug" & @crlf;
    MsgBox( $MB_SYSTEMMODAL, "DDW Debug Information", $__DDW_String );
    If $exit Then Exit
EndFunc   ;==>DD

#Region Internals
Func __DD($any, $depth)

    Switch VarGetType($any)
        Case "Array"
            __DD_Array($any, $depth)
        Case "Object" And ObjName($any) == "Dictionary"
            $__DDW_String &= "- ";
            __DD_ScriptingDictionary($any, $depth)
        Case Else
            $__DDW_String &= (IsObj($any) ? '! ' : '> ');
            __DD_Other($any)
    EndSwitch

EndFunc   ;==>__DD

Func __DD_Array($array, $depth, $curI = Null, $curJ = Null, $ignoreTabs = False)

    Local Const $rows = UBound($array)
    Local Const $cols = UBound($array, 2)
    Local $cur, $oInfo, $cwColor

    If $cols == 0 Then
        $curI = VarGetType($curI) == "Int32" ? StringFormat("[%d] => ", $curI) : ""

        $__DDW_String &= _
            (">" & __GetTabs($depth, $ignoreTabs) & StringFormat('%s(Array:%d) [', $curI, $rows) & @LF);

        For $i = 0 To $rows - 1
            $cur = $array[$i]
            $oInfo = __GetDataInfo($cur)
            $cwColor = IsObj($cur) ? (ObjName($cur) == "Dictionary" ? '-' : '!') : '>'

            If IsArray($cur) Then
                __DD_Array($cur, $depth + 1, $i)
;                $__DDW_String &= ("> " & $sTabs & "]" & @LF);
            ElseIf IsObj($cur) And ObjName($cur) == "Dictionary" Then
                $__DDW_String &= ("- " & __GetTabs($depth + 1) & StringFormat('[%d] => ', $i));
                __DD_ScriptingDictionary($cur, $depth + 1, True)
            Else
                $__DDW_String &= ($cwColor & " " & __GetTabs($depth + 1) & _
                    StringFormat('[%d] (%s:%s) => "%s"', $i, $oInfo.item("type"), _
                    $oInfo.item("length"), $oInfo.item("value")) & @LF);
            EndIf

        Next
    Else
        $curI = VarGetType($curI) == "Int32" ? ($depth == 1 ? StringFormat("[%d] => ", $curI) : StringFormat("[%d][%d] => ", $curI, $curJ)) : ""

        $__DDW_String &= (">" & __GetTabs($depth, $ignoreTabs) & _
            StringFormat('%s(Array:%d:%d) [', $curI, $rows, $cols) & @LF);

        For $i = 0 To $rows - 1
            For $j = 0 To $cols - 1
                $cur = $array[$i][$j]
                $oInfo = __GetDataInfo($cur)
                $cwColor = IsObj($cur) ? (ObjName($cur) == "Dictionary" ? '-' : '!') : '>'


                If IsArray($cur) Then
                    __DD_Array($cur, $depth + 1, $i, $j)
                ElseIf IsObj($cur) And ObjName($cur) == "Dictionary" Then
                    $__DDW_String &= ("- " & __GetTabs($depth + 1) & _
                        StringFormat('[%d][%d] => ', $i, $j));
                    __DD_ScriptingDictionary($cur, $depth + 1, True)
                Else
                    $__DDW_String &= ($cwColor & " " & __GetTabs($depth + 1) & _
                        StringFormat('[%d][%d] (%s:%s) => "%s"', $i, $j, $oInfo.item("type"), _
                        $oInfo.item("length"), $oInfo.item("value")) & @LF);
                EndIf

            Next
        Next

    EndIf

    $__DDW_String &= ("> " & __GetTabs($depth) & "]" & @LF);
EndFunc   ;==>__DD_Array

Func __DD_ScriptingDictionary($object, $depth, $ignoreTabs = False)

    $__DDW_String &= (__GetTabs($depth, $ignoreTabs) & _
        StringFormat('(Scripting.Dictionary:%d) {', $object.count()) & @LF), 5 );

    For $item In $object
        Local $key = $item
        Local $value = $object.item($key)
        Local $oInfo = __GetDataInfo($value)

        If IsObj($value) And ObjName($value) == "Dictionary" Then
            $__DDW_String &= (StringFormat("- " & __GetTabs($depth + 1) & "[%s] => ", $key));
            __DD_ScriptingDictionary($value, $depth + 1, True)
        ElseIf IsArray($value) Then
            $__DDW_String &= ("> " & __GetTabs($depth + 1) & StringFormat('[%s] => ', $key));
            __DD_Array($value, $depth + 1, Null, Null, True)
        Else
            $__DDW_String &= ("- " & __GetTabs($depth + 1) & _
                StringFormat('[%s] (%s:%s) => "%s"', $key, $oInfo.item("type"), _
                $oInfo.item("length"), $oInfo.item("value")) & @LF);
        EndIf

    Next

    $__DDW_String &= ("- " & __GetTabs($depth) & "}" & @LF);

EndFunc   ;==>__DD_ScriptingDictionary

Func __DD_Other($any)
    Local Const $oInfo = __GetDataInfo($any)

      $__DDW_String &= (StringFormat('(%s:%s) "%s"', $oInfo.item("type"), _
        $oInfo.item("length"), $oInfo.item("value")) & @LF);
EndFunc   ;==>__DD_Other

Func __GetDataInfo($any)
    Local Const $oRet = ObjCreate("Scripting.Dictionary")
    Local $type = VarGetType($any)
    Local $value = $any
    Local $length = StringLen($any)

    Switch $type
        Case "UserFunction"
            ContinueCase
        Case "Function"
            $value = FuncName($any)
            $length = StringLen($value)
        Case "Object"
            $type = ObjName($any)
            $length = ObjName($any, 2) ; Descriptobn
            $value = ObjName($any, 6) ; Clisid
        Case "String"
            Local $str = $any
            $str = StringReplace($str, @LF, "\LF")
            $str = StringReplace($str, @CR, "\CR")
            $str = StringReplace($str, @CRLF, "\CRLF")
            $str = StringReplace($str, @TAB, "\TAB")
            $value = $str
        Case "Binary"
            $value = BinaryLen($any)
        Case "Keyword" And $length == 0
            $value = "NULL"
    EndSwitch

    $oRet.add("type", $type)
    $oRet.add("length", $length)
    $oRet.add("value", $value)

    Return $oRet
EndFunc   ;==>__GetDataInfo

Func __GetTabs($depth, $ignoreTabs = False)
    If $ignoreTabs Then Return ""
    Local $sTabs
    For $i = 0 To $depth - 1
        $sTabs &= "    " ; @TAB
    Next

    Return $sTabs
EndFunc   ;==>__GetTabs
#EndRegion Internals

 

Autoit-DD-1.1.0.zip

Link to comment
Share on other sites

Well, I tried to delete the above post - but I can't. SO - here is another one. In this I changed the file name from DDW.au3 to WinDD.au3. I did this because I realized most (if not all) Windows based functions start with "Win" or "_Win". So I changed it to WinDD. Anyway, Here it is:
 

#cs
    Copyright (c) 2020 TarreTarreTarre <tarre.islam@gmail.com>
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
#ce
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
#include-once

; #FUNCTION# =========================================================================================================
; Name ..........: WinDD
; Description ...: Displays useful information about a variable or object in the console
; Syntax ........: WinDD($any[, $exit = True], $timeout=0)
; Parameters ....: $any                 - anything.
;                  $exit                - [optional] an boolean value. Default is True.
; Return values .: None
; Author ........: TarreTarreTarre and Mark Manning (only made changes)
; Modified ......: May 9, 2024
; Remarks .......: Made it so this works for MsgBox
; Related .......:
; Link ..........:
; Example .......: No
; ===================================================================================================================

Global $__WinDD_String = "";
Func WinDD($any, $exit = True, $timeout=0)    ;    0 = YOU have to close the dialog
    $__WinDD_String = @crlf & "--->Starting Debug" & @crlf & @crlf;
    __WinDD($any, 0)
    $__WinDD_String &= @crlf & "<---Exiting Debug" & @crlf;
    MsgBox( $MB_SYSTEMMODAL, "WinDD Debug Information", $__WinDD_String, $timeout );
    If $exit Then Exit
EndFunc   ;==>WinDD

#Region Internals
Func __WinDD($any, $depth)

    Switch VarGetType($any)
        Case "Array"
            __WinDD_Array($any, $depth)
        Case "Object" And ObjName($any) == "Dictionary"
            $__WinDD_String &= "- ";
            __WinDD_ScriptingDictionary($any, $depth)
        Case Else
            $__WinDD_String &= (IsObj($any) ? '! ' : '> ');
            __WinDD_Other($any)
    EndSwitch

EndFunc   ;==>__WinDD

Func __WinDD_Array($array, $depth, $curI = Null, $curJ = Null, $ignoreTabs = False)

    Local Const $rows = UBound($array)
    Local Const $cols = UBound($array, 2)
    Local $cur, $oInfo, $cwColor

    If $cols == 0 Then
        $curI = VarGetType($curI) == "Int32" ? StringFormat("[%d] => ", $curI) : ""

        $__WinDD_String &= _
            (">" & __GetTabs($depth, $ignoreTabs) & StringFormat('%s(Array:%d) [', $curI, $rows) & @LF);

        For $i = 0 To $rows - 1
            $cur = $array[$i]
            $oInfo = __GetDataInfo($cur)
            $cwColor = IsObj($cur) ? (ObjName($cur) == "Dictionary" ? '-' : '!') : '>'

            If IsArray($cur) Then
                __WinDD_Array($cur, $depth + 1, $i)
;                $__WinDD_String &= ("> " & $sTabs & "]" & @LF);
            ElseIf IsObj($cur) And ObjName($cur) == "Dictionary" Then
                $__WinDD_String &= ("- " & __GetTabs($depth + 1) & StringFormat('[%d] => ', $i));
                __WinDD_ScriptingDictionary($cur, $depth + 1, True)
            Else
                $__WinDD_String &= ($cwColor & " " & __GetTabs($depth + 1) & _
                    StringFormat('[%d] (%s:%s) => "%s"', $i, $oInfo.item("type"), _
                    $oInfo.item("length"), $oInfo.item("value")) & @LF);
            EndIf

        Next
    Else
        $curI = VarGetType($curI) == "Int32" ? ($depth == 1 ? StringFormat("[%d] => ", $curI) : StringFormat("[%d][%d] => ", $curI, $curJ)) : ""

        $__WinDD_String &= (">" & __GetTabs($depth, $ignoreTabs) & _
            StringFormat('%s(Array:%d:%d) [', $curI, $rows, $cols) & @LF);

        For $i = 0 To $rows - 1
            For $j = 0 To $cols - 1
                $cur = $array[$i][$j]
                $oInfo = __GetDataInfo($cur)
                $cwColor = IsObj($cur) ? (ObjName($cur) == "Dictionary" ? '-' : '!') : '>'


                If IsArray($cur) Then
                    __WinDD_Array($cur, $depth + 1, $i, $j)
                ElseIf IsObj($cur) And ObjName($cur) == "Dictionary" Then
                    $__WinDD_String &= ("- " & __GetTabs($depth + 1) & _
                        StringFormat('[%d][%d] => ', $i, $j));
                    __WinDD_ScriptingDictionary($cur, $depth + 1, True)
                Else
                    $__WinDD_String &= ($cwColor & " " & __GetTabs($depth + 1) & _
                        StringFormat('[%d][%d] (%s:%s) => "%s"', $i, $j, $oInfo.item("type"), _
                        $oInfo.item("length"), $oInfo.item("value")) & @LF);
                EndIf

            Next
        Next

    EndIf

    $__WinDD_String &= ("> " & __GetTabs($depth) & "]" & @LF);
EndFunc   ;==>__WinDD_Array

Func __WinDD_ScriptingDictionary($object, $depth, $ignoreTabs = False)

    $__WinDD_String &= (__GetTabs($depth, $ignoreTabs) & _
        StringFormat('(Scripting.Dictionary:%d) {', $object.count()) & @LF), 5 );

    For $item In $object
        Local $key = $item
        Local $value = $object.item($key)
        Local $oInfo = __GetDataInfo($value)

        If IsObj($value) And ObjName($value) == "Dictionary" Then
            $__WinDD_String &= (StringFormat("- " & __GetTabs($depth + 1) & "[%s] => ", $key));
            __WinDD_ScriptingDictionary($value, $depth + 1, True)
        ElseIf IsArray($value) Then
            $__WinDD_String &= ("> " & __GetTabs($depth + 1) & StringFormat('[%s] => ', $key));
            __WinDD_Array($value, $depth + 1, Null, Null, True)
        Else
            $__WinDD_String &= ("- " & __GetTabs($depth + 1) & _
                StringFormat('[%s] (%s:%s) => "%s"', $key, $oInfo.item("type"), _
                $oInfo.item("length"), $oInfo.item("value")) & @LF);
        EndIf

    Next

    $__WinDD_String &= ("- " & __GetTabs($depth) & "}" & @LF);

EndFunc   ;==>__WinDD_ScriptingDictionary

Func __WinDD_Other($any)
    Local Const $oInfo = __GetDataInfo($any)

      $__WinDD_String &= (StringFormat('(%s:%s) "%s"', $oInfo.item("type"), _
        $oInfo.item("length"), $oInfo.item("value")) & @LF);
EndFunc   ;==>__WinDD_Other

Func __GetDataInfo($any)
    Local Const $oRet = ObjCreate("Scripting.Dictionary")
    Local $type = VarGetType($any)
    Local $value = $any
    Local $length = StringLen($any)

    Switch $type
        Case "UserFunction"
            ContinueCase
        Case "Function"
            $value = FuncName($any)
            $length = StringLen($value)
        Case "Object"
            $type = ObjName($any)
            $length = ObjName($any, 2) ; Descriptobn
            $value = ObjName($any, 6) ; Clisid
        Case "String"
            Local $str = $any
            $str = StringReplace($str, @LF, "\LF")
            $str = StringReplace($str, @CR, "\CR")
            $str = StringReplace($str, @CRLF, "\CRLF")
            $str = StringReplace($str, @TAB, "\TAB")
            $value = $str
        Case "Binary"
            $value = BinaryLen($any)
        Case "Keyword" And $length == 0
            $value = "NULL"
    EndSwitch

    $oRet.add("type", $type)
    $oRet.add("length", $length)
    $oRet.add("value", $value)

    Return $oRet
EndFunc   ;==>__GetDataInfo

Func __GetTabs($depth, $ignoreTabs = False)
    If $ignoreTabs Then Return ""
    Local $sTabs
    For $i = 0 To $depth - 1
        $sTabs &= "    " ; @TAB
    Next

    Return $sTabs
EndFunc   ;==>__GetTabs
#EndRegion Internals

Same filename though but that's because it is inside of the directory.

Autoit-DD-1.1.0.zip

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

×
×
  • Create New...