Jump to content

How to represent a variable with a string


Recommended Posts

func P($Var)
    ConsoleWrite(X($Var) & " = [" & $Var & "]" & @CRLF)
endfunc
;Here, X represents an unknown built-in function or UDF

for examples:

local $sString=""
$sString=string(12345679*9)
P($sString)

After the function P runs,  the following results are expected:

$sString = [111111111]

So the problem is, how to automatically transform the variable name in quotation marks with different function parameters.

$aa=123*11
P($aa) 
==>$aa = [1353]

$bb=Zef & "||" & $aa
P($bb) 
==>$bb = [Zef||1353]

What may be described above is not too clear. Take the hotel as an example, to put it simply:

the variable-name is like the hotel room-number, and the guest is like a variable-value. The guest is uncertain, has been changing, and the room-number is actually fixed, but how to get the room-number?

Edited by Letraindusoir
Link to comment
Share on other sites

  • Developers

Please post a script which demonstrates your issue, because your question doesn't really make that clear.

by the way: a string never contains the doublequotes unless you add them to it!

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@Jos

Sorry if I intrude, but it seems that the OP would like to display the name of the variable passed as parameter to the function, so, whenever he use the fuction, he knows both variable name and value :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

30 minutes ago, Earthshine said:

so do that by logging it to console or log file in the function called. Autoit does not support Reflection so it can't do what you can do in Python or C#

Yes, because I see this use of the print function in Python, I feel convenient, so I hope to achieve the same effect in Autoit.

Link to comment
Share on other sites

Similar to above problem, how to convert a particular form of string into an array, such as the following:

local $sTring='[["0x990033", "0xcc6699", "0xff6699", "0xff3366"]]'
local $aArray=X($sTring)

But it's easy in python.Of course, this problem is not difficult now, it can be solved by calling json related functions.

Edited by Letraindusoir
Link to comment
Share on other sites

  • Moderators

Letraindusoir,

I do not see the connection between the 2 questions, but the second can be done easily with a RegEx:

#include <Array.au3>

$sString = '[["0x990033", "0xcc6699", "0xff6699", "0xff3366"]]'

$aArray=_ToArray($sString)

_ArrayDisplay($aArray, "", Default, 8)

Func _ToArray($sText)

    Return StringRegExp($sText, '(?U)"(.*)"', 3) ; Array of matches

EndFunc

There is no error-checking in that snippet - so results on a badly formatted string are unlikely to be correct.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Letraindusoir,

And the only way I can think of answering the first question is to append the variable name to its content like this:

$vVariable = "VarName|12345679*9"

_Expand($vVariable)

Func _Expand($vVar)

    $aContent = StringSplit($vVar, "|")

    ConsoleWrite($aContent[1] & " = [" & Execute($aContent[2]) & "]" & @CRLF)

EndFunc

You will need a wrapper function to reassign the variable content within the script, but that is pretty trivial.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

35 minutes ago, Melba23 said:

Letraindusoir,

I do not see the connection between the 2 questions, but the second can be done easily with a RegEx:

#include <Array.au3>

$sString = '[["0x990033", "0xcc6699", "0xff6699", "0xff3366"]]'

$aArray=_ToArray($sString)

_ArrayDisplay($aArray, "", Default, 8)

Func _ToArray($sText)

    Return StringRegExp($sText, '(?U)"(.*)"', 3) ; Array of matches

EndFunc

There is no error-checking in that snippet - so results on a badly formatted string are unlikely to be correct.

M23

More thanks,Melba23!

I mean, are there any built-in modules related to OOP in autoit? Built-in functions such as eval, for example, quickly solve problems so that don't have to achieve the desired results through various forms of indirect methods (stringsplit,stringregexp and so on).

I specifically stressed that :some special form of string, if not a string, happens to be an array assignment expression.

$aColor = [["0x990033", "0xcc6699", "0xff6699", "0xff3366"]]
$bColor = [["0x990033", "0xcc6699"],["0xff6699", "0xff3366"]]

However, this second problem is just an additional small problem, your method is very good,we can write a general function to solve by regular. So we don't have to spend any more time on it. Thanks again!

Edited by Letraindusoir
Link to comment
Share on other sites

9 minutes ago, Melba23 said:

Letraindusoir,

And the only way I can think of answering the first question is to append the variable name to its content like this:

$vVariable = "VarName|12345679*9"

_Expand($vVariable)

Func _Expand($vVar)

    $aContent = StringSplit($vVar, "|")

    ConsoleWrite($aContent[1] & " = [" & Execute($aContent[2]) & "]" & @CRLF)

EndFunc

You will need a wrapper function to reassign the variable content within the script, but that is pretty trivial.

M23

Your function is to pre-process the variable before it can achieve the effect, it is also not convenient. So the problem is, how do keep the variable-name in double-quotation-marks in its original shape?

Link to comment
Share on other sites

AutoIt lacks a VarName function, similar to FuncName.

You can dump the content of a variable but you don't have a way to recover its name:

Local $struct = DllStructCreate("char[3];handle[3];uint[35];byte[128];wchar[190000]; double[3];int64[3];char[3];float;double;byte;byte;short;ushort;int;uint;char")
    DllStructSetData($struct, 1, 'sos')
    DllStructSetData($struct, 2, Ptr(123456789))
    DllStructSetData($struct, 3, 8, 1)
    DllStructSetData($struct, 3, 0x87654321, 2)
    DllStructSetData($struct, 3, 256, 5)
    DllStructSetData($struct, 4, Binary('sos'))
    DllStructSetData($struct, 5, 'gno' & @CRLF & 'j''i' & @TAB & 'o')
    DllStructSetData($struct, 6, 3.1415926, 2)
    DllStructSetData($struct, 7, 17, 1)
    DllStructSetData($struct, 7, -1, 2)
    DllStructSetData($struct, 8, 'end')
    DllStructSetData($struct, 9, 2.7182818284590452353602874713527)
    DllStructSetData($struct, 10, 2.7182818284590452353602874713527)
    DllStructSetData($struct, 11, 107)
    DllStructSetData($struct, 12, -108)
    DllStructSetData($struct, 13, 109)
    DllStructSetData($struct, 14, 110)
    DllStructSetData($struct, 15, 111)
    DllStructSetData($struct, 16, 112)

    Local $f = _VarDump

    Local $c[2][0]
    Local $e = [[Null, Default], [__DumpStr, MsgBox]]
    Local Enum $p = 33333333333333
    Opt("WinTitleMatchMode", 2)
    Local $a[4][4] = [ _
        [$c, $e, ObjCreate("shell.application"), WinGetHandle("t.au3")], _
        ['zzz', 1/3, True, 0x123456], _
        [$struct, 93, Null, $p], _
        [$f, Mod, _ArrayDisplay] _
    ]

    _ConsoleWrite('Test example of moderate complexity' & @LF & $f($a) & @LF)

produces this output:

Test example of moderate complexity
Array[4][4]
      [0][0] => Array[2][0]        (array is empty)
      [0][1] => Array[2][2]
            [0][0] => Keyword            Null
            [0][1] => Keyword            Default
            [1][0] => UserFunction       __DUMPSTR
            [1][1] => Function           MSGBOX
      [0][2] => Object
                Name:             IShellDispatch6
                Description:      Updated IShellDispatch
                ProgID:           Shell.Application.1
                Associated file:  C:\Windows\SysWOW64\shell32.dll
                Owner/marshaller: C:\Program Files (x86)\AutoIt3\autoit3.exe
                CLSID:            {13709620-C279-11CE-A49E-444553540000}
                InterfaceID:      {34936BA1-67AD-4C41-99B8-8C12DFF1E974}
      [0][3] => HWnd               
      [1][0] => String (3)         'zzz'
      [1][1] => Double             0.333333333333333
      [1][2] => Boolean            True
      [1][3] => Int32              1193046
      [2][0] => Struct             (380376) @:03929FA0 (structure alignment is unknown)
            char[3]         'sos'
            ptr[3]
                            0x075BCD15
                            0x00000000
                            0x00000000
            uint[35]
                            8
                            2271560481
                            0
                            0
                            256
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            ... there are 15 more uint in this array
            byte[128]       0x736F7300000000000000000000000000 ... 00000000000000000000000000000000
            wchar[190000]   'gno<0x0D><0x0A>j'i<0x09>o'
            double[3]
                            0.0
                            3.1415926
                            0.0
            int64[3]
                            17
                            -1
                            0
            char[3]         'end'
            float           2.71828174591064
            double          2.71828182845905
            byte            107
            byte            148
            short           109
            ushort          110
            int             111
            uint            112
            char            ''
      [2][1] => Int32              93
      [2][2] => Keyword            Null
      [2][3] => Int64              33333333333333
      [3][0] => UserFunction       _VARDUMP
      [3][1] => Function           MOD
      [3][2] => UserFunction       _ARRAYDISPLAY
      [3][3] => String (0)         ''

Ask for the functions not provided, in needed.  But as you can see no vairable name is available.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

7 hours ago, jchd said:

 

7 hours ago, jchd said:

AutoIt lacks a VarName function, similar to FuncName.

You can dump the content of a variable but you don't have a way to recover its name:

Local $struct = DllStructCreate("char[3];handle[3];uint[35];byte[128];wchar[190000]; double[3];int64[3];char[3];float;double;byte;byte;short;ushort;int;uint;char")
    DllStructSetData($struct, 1, 'sos')
    DllStructSetData($struct, 2, Ptr(123456789))
    DllStructSetData($struct, 3, 8, 1)
    DllStructSetData($struct, 3, 0x87654321, 2)
    DllStructSetData($struct, 3, 256, 5)
    DllStructSetData($struct, 4, Binary('sos'))
    DllStructSetData($struct, 5, 'gno' & @CRLF & 'j''i' & @TAB & 'o')
    DllStructSetData($struct, 6, 3.1415926, 2)
    DllStructSetData($struct, 7, 17, 1)
    DllStructSetData($struct, 7, -1, 2)
    DllStructSetData($struct, 8, 'end')
    DllStructSetData($struct, 9, 2.7182818284590452353602874713527)
    DllStructSetData($struct, 10, 2.7182818284590452353602874713527)
    DllStructSetData($struct, 11, 107)
    DllStructSetData($struct, 12, -108)
    DllStructSetData($struct, 13, 109)
    DllStructSetData($struct, 14, 110)
    DllStructSetData($struct, 15, 111)
    DllStructSetData($struct, 16, 112)

    Local $f = _VarDump

    Local $c[2][0]
    Local $e = [[Null, Default], [__DumpStr, MsgBox]] 

 

Undefined function: _VarDump,__DumpStr

Link to comment
Share on other sites

No need to quote what I posted.  I also said the code would need extra functions.
My purpose was to examplify thatwe can go a long way to dissect what a variable contains, contrary to what name we use to manipulate it.

Anyway here's the current version I use.

Spoiler
#AutoIt3Wrapper_Version=B       ; beta 3.3.15.0 or greater is mandatory for Map datatype support

#include-once

#include <AutoItConstants.au3>
#include <String.au3>
#include <Math.au3>

Local Const $_TAB = '      '
Local $_DumpStr, $_DumpBin

; user-callable function, so that noone messes with __VarDump indentation
; $vVar is the variable to be dumped.
; $iLimit is the max number of entries of an array dimension, map or DllStruct array element to be displayed in full
; $bFullStr allows dumping strings in full
; $bFullBin allows dumping binary data in full
Func _VarDump(Const ByRef $vVar, $iLimit = 20, $bFullStr = 0, $bFullBin = 0)
    If $iLimit < 3 Then $iLimit = 0
    $_DumpStr = ($bFullStr ? __DumpFullStr : __DumpStr)
    $_DumpBin = ($bFullBin ? __DumpFullBin : __DumpBin)
    $sStr = $vVar
    Return (__VarDump($sStr, $iLimit))
EndFunc   ;==>_VarDump


Func __VarDump(ByRef $vVar, $iLimit, $sIndent = '', $sMore = '')
    Local $ret, $len, $ptr, $tmp

    Switch VarGetType($vVar)

        Case "String"
            If StringRegExp($vVar, '(?x)' & _
                '(?(DEFINE) (?<element> (?&ws) (?&value) (?&ws) ) )' & _
                '(?(DEFINE) (?<value> (?&ws) (?: (?&object) | (?&array) | (?&string) | (?&number) | true | false | null ) (?&ws) ) )' & _
                '(?(DEFINE) (?<object> \{ (?: (?&ws) | (?&member) (?: , (?&member) )* ) \} ) )' & _
                '(?(DEFINE) (?<member> (?&ws) (?&string) (?&ws) : (?&element) ) )' & _
                '(?(DEFINE) (?<array> \[ (?: (?&ws) | (?&value) (?: , (?&value) )* ) \] ) )' & _
                '(?(DEFINE) (?<string> " (?: \\ (?: ["\\/bnrt] | u [[:xdigit:]]{4} ) | [^[:cntrl:]\\"] )* " ) )' & _
                '(?(DEFINE) (?<number> [-+]? \d+ (?: \.\d+ )? (?: [Ee] [-+]? \d+ )? ) )' & _
                '(?(DEFINE) (?<ws> [\x09\x0A\x0D\x20]* ) )' & _
                '\A (?&object) \z') Then
                $tmp = $vVar
                Return __DumpJSON($tmp, $sIndent)
            Else
                Return StringFormat("%-19s", "String (" & StringLen($vVar) & ")") & $_DumpStr($vVar)
            EndIf

        Case "Double"
            Return 'Double             ' & $vVar & (IsInt($vVar) ? '.0' : '')

        Case "Int32", "Int64"
            Return VarGetType($vVar) & '              ' & $vVar

        Case "Array"
            Local $iDimensions = UBound($vVar, 0)
            Local $iCells = 1
            $ret = 'Array'
            $iDimensions -= 1
            For $i = 0 To $iDimensions
                $ret &= '[' & UBound($vVar, $i + 1) & ']'
                $iCells *= UBound($vVar, $i + 1)
            Next
            $sMore = _StringRepeat(' ', StringLen($ret) - 1)
            If $iCells = 0 Then
                Return $ret & $_TAB & '  (array is empty)'
            Else
                Return $ret & @CRLF & __VarDumpArray($vVar, $iLimit, $sIndent, $sMore)
            EndIf

        Case "Binary"
            $len = BinaryLen($vVar)
            $ret = 'Binary (' & BinaryLen($vVar) & ')             '
            Return ($ret & $_DumpBin($vVar))

        Case "Bool"
            Return 'Boolean            ' & $vVar

        Case "Keyword"
            Return ('Keyword            ' & ($vVar = Null ? 'Null' : ($vVar = Default ? 'Default' : 'Other keyword')))

        Case "Ptr"
            Return (IsHWnd($vVar) ? 'HWnd               ' : 'Pointer            ' & $vVar)

        Case "Object"
            Return __DumpObj($vVar, $iLimit, $sIndent & $_TAB, $sMore)

        Case "Function", "UserFunction"
            Return StringFormat('%-19s', VarGetType($vVar)) & FuncName($vVar)

        Case "DllStruct"
            $len = DllStructGetSize($vVar)
            $ptr = DllStructGetPtr($vVar)
            $ret = 'Struct             (' & $len & ') @:' & Hex($ptr) & ' (structure alignment is unknown)' & @CRLF
            Local $nbElem = 1, $idx, $incr, $data, $type, $indent = $sIndent & $_TAB, $oldvalue, $readvalue, $elem
            While 1
                $data = DllStructGetData($vVar, $nbElem)
                If @error = 2 Then ExitLoop
                $type = VarGetType($data)
                $idx = 1
                $incr = 0
                ; determine max index of element
                While 1
                    DllStructGetData($vVar, $nbElem, 2 * $idx)
                    If @error = 3 Then ExitLoop
                    $incr = $idx
                    $idx *= 2
                WEnd
                ; index is in [$idx, (2 * $idx) - 1]
                $idx += $incr
                Do
                    DllStructGetData($vVar, $nbElem, $idx)
                    If @error = 3 Then
                        ; approach is asymetric (upper bound is too big)
                        $idx -= ($incr = 1) ? 1 : $incr / 2
                    Else
                        $idx += Int($incr / 2)
                    EndIf
                    $incr = Int($incr / 2)
                Until $incr = 0
                Switch $type
                    Case "Int32", "Int64"
                        $ret &= $indent
                        $data = DllStructGetData($vVar, $nbElem, 1)
                        DllStructSetData($vVar, $nbElem, 0x7777666655554433, 1)
                        $readvalue = DllStructGetData($vVar, $nbElem, 1)
                        Switch $readvalue
                            Case 0x7777666655554433
                                $elem = "int64"
                                ; alias: uint64
                                ; alias: int_ptr(x64), long_ptr(x64), lresult(x64), lparam(x64)
                                ; alias: uint_ptr(x64), ulong_ptr(x64), dword_ptr(x64), wparam(x64)
                            Case 0x55554433
                                DllStructSetData($vVar, $nbElem, 0x88887777, 1)
                                $readvalue = DllStructGetData($vVar, $nbElem, 1)
                                $elem = ($readvalue > 0 ? "uint" : "int")
                                ; int aliases: long, bool, int_ptr(x86), long_ptr(x86), lresult(x86), lparam(x86);
                                ; uint aliases: ulong, dword, uint_ptr(x86), ulong_ptr(x86), dword_ptr(x86), wparam(x86)
                            Case 0x4433
                                DllStructSetData($vVar, $nbElem, 0x8888, 1)
                                $readvalue = DllStructGetData($vVar, $nbElem, 1)
                                $elem = ($readvalue > 0 ? "ushort" : "short")
                                ; ushort alias: word
                            Case 0x33
                                $elem = "byte"
                                ; alias: ubyte
                        EndSwitch
                        DllStructSetData($vVar, $nbElem, $data, 1)
                        If $idx = 1 Then
                            $ret &= StringFormat('%-' & 9 + StringLen($len) & 's ', $elem) & $data & @CRLF
                        Else
                            $ret &= $elem & "[" & $idx & "]" & @CRLF
                            For $i = 1 To $idx
                                If $iLimit And $idx > $iLimit And $i > $iLimit Then
                                    $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's ', '') & '... there are ' & $idx - $iLimit & ' more ' & $elem & ' in this array' & @CRLF
                                    ExitLoop
                                Else
                                    $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's ', '') & DllStructGetData($vVar, $nbElem, $i) & @CRLF
                                EndIf
                            Next
                        EndIf
                    Case "String"
                        $oldvalue = DllStructGetData($vVar, $nbElem, 1)
                        DllStructSetData($vVar, $nbElem, ChrW(0x2573), 1)
                        $readvalue = DllStructGetData($vVar, $nbElem, 1)
                        DllStructSetData($vVar, $nbElem, $oldvalue, 1)
                        $elem = ($readvalue = ChrW(0x2573) ? "wchar" : "char")
                        If $idx > 1 Then $elem &= "[" & $idx & "]"
                        $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's ', $elem) & $_DumpStr($data) & @CRLF
                    Case "Binary"
                        Local $blen = BinaryLen($data)
                        $elem = "byte"
                        If $idx > 1 Then $elem &= "[" & $idx & "]"
                        $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's ', $elem) & $_DumpBin($data) & @CRLF
                    Case "Ptr"
                        $ret &= $indent
                        $elem = "ptr"
                        ; alias: hwnd, handle
                        If $idx = 1 Then
                            $ret &= StringFormat('%-' & 9 + StringLen($len) & 's ', $elem) & $data & @CRLF
                        Else
                            $ret &= $elem & "[" & $idx & "]" & @CRLF
                            For $i = 1 To $idx
                                $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's ', '') & DllStructGetData($vVar, $nbElem, $i) & @CRLF
                            Next
                        EndIf
                    Case "Double"
                        $ret &= $indent
                        $oldvalue = DllStructGetData($vVar, $nbElem, 1)
                        DllStructSetData($vVar, $nbElem, 10 ^ - 15, 1)
                        $readvalue = DllStructGetData($vVar, $nbElem, 1)
                        DllStructSetData($vVar, $nbElem, $oldvalue, 1)
                        $elem = ($readvalue = 10 ^ - 15 ? "double" : "float")
                        If $idx = 1 Then
                            $ret &= StringFormat('%-' & 9 + StringLen($len) & 's ', $elem) & $data & (IsInt($data) ? '.0' : '') & @CRLF
                        Else
                            $ret &= $elem & "[" & $idx & "]" & @CRLF
                            For $i = 1 To $idx
                                If $iLimit And $idx > $iLimit And $i > $iLimit Then
                                    $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's ', '') & '... there are ' & $idx - $iLimit & ' more ' & $elem & ' in this array' & @CRLF
                                    ExitLoop
                                Else
                                    $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's %s', '', DllStructGetData($vVar, $nbElem, $i)) & (IsInt(DllStructGetData($vVar, $nbElem, $i)) ? '.0' : '') & @CRLF
                                EndIf
                            Next
                        EndIf
                EndSwitch
                $nbElem += 1
            WEnd
            Return StringTrimRight($ret, 2)

        Case "Map"
            Local $iCells = UBound($vVar)
            $ret = 'Map[' & $iCells & ']'
            If $iCells = 0 Then
                Return $ret & $_TAB & '  (map is empty)'
            Else
                Return $ret & @CRLF & __VarDumpMap($vVar, $iLimit, $sIndent, '    ')
            EndIf

        Case Else
            Return StringFormat('%-19s', VarGetType($vVar)) & $vVar

    EndSwitch
EndFunc   ;==>__VarDump


Func __VarDumpArray(Const ByRef $aArray, $iLimit, $sIndent = $_TAB, $sMore = '')
    Local $sDump, $sArrayFetch, $sArrayRead, $iDone = 0, $iElements = 1
    Local $iDimensions = UBound($aArray, 0)
    Local $aUBounds[$iDimensions]
    Local $aIndices[$iDimensions]
    $iDimensions -= 1
    For $i = 0 To $iDimensions
        $aUBounds[$i] = UBound($aArray, $i + 1) - 1
        $iElements *= $aUBounds[$i] + 1
        $aIndices[$i] = 0
    Next
    $sIndent &= $_TAB
    While $iDone < ($iLimit ? _Min($iLimit, $iElements) : $iElements)
        $sArrayFetch = ''
        For $i = 0 To $iDimensions
            $sArrayFetch &= '[' & $aIndices[$i] & ']'
        Next
        $sArrayRead = Execute('$aArray' & $sArrayFetch)
        $sDump &= $sIndent & $sArrayFetch & ' => ' & __VarDump($sArrayRead, $iLimit, $sIndent, $sMore) & @CRLF
        $iDone += 1
        If $iLimit And $iDone = $iLimit Then
            $sDump &= $sIndent & '... there are ' & $iElements - $iDone & ' more elements in this array' & @CRLF
            ExitLoop
        EndIf

        For $i = $iDimensions To 0 Step -1
            $aIndices[$i] += 1
            If $aIndices[$i] > $aUBounds[$i] Then
                $aIndices[$i] = 0
            Else
                ExitLoop
            EndIf
        Next
    WEnd
    Return (StringTrimRight($sDump, 2))
EndFunc   ;==>__VarDumpArray


Func __VarDumpMap(ByRef $mMap, $iLimit, $sIndent = $_TAB, $sMore = '')
    Local $i = 0, $sDump
    $sIndent &= $_TAB
    For $key In MapKeys($mMap)
        $sDump &= $sIndent & StringFormat('%-22s => ', _
                "[" & (IsString($key) ? __DumpStr($key) : $key) & "]")
        $sDump &= __VarDump($mMap[$key], $iLimit, $sIndent, $sMore) & @CRLF
        If $iLimit And $i = $iLimit - 1 Then
            $sDump &= $sIndent & '... there are ' & UBound($mMap) - $i - 1 & ' more elements in this map' & @CRLF
            ExitLoop
        EndIf
        $i += 1
    Next
    Return (StringTrimRight($sDump, 2))
EndFunc   ;==>__VarDumpMap


Func __DumpObj(Const ByRef $vVar, $iLimit, $sIndent = $_TAB, $sMore = '')
    $ret = ObjName($vVar, $OBJ_NAME)
    If $ret = "Dictionary" Then
        With $vVar
            $tmp = 'Scripting.Dictionary'
            For $key In .keys()
                $tmp &= @LF & $sIndent & '    ' & StringFormat("%-32s    %s", __VarDump($key, $iLimit, $sIndent), __VarDump(.item($key), $iLimit, $sIndent))
            Next
        EndWith
    Else
        $tmp = 'Object' & @LF & $sIndent & '    Name:             ' & $ret
        $ret = ObjName($vVar, $OBJ_STRING)
        If Not @error Then $tmp &= @LF & $sIndent & '    Description:      ' & $ret
        $ret = ObjName($vVar, $OBJ_PROGID)
        If Not @error Then $tmp &= @LF & $sIndent & '    ProgID:           ' & $ret
        $ret = ObjName($vVar, $OBJ_FILE)
        If Not @error Then $tmp &= @LF & $sIndent & '    Associated file:  ' & $ret
        $ret = ObjName($vVar, $OBJ_MODULE)
        If Not @error Then $tmp &= @LF & $sIndent & '    Owner/marshaller: ' & $ret
        $ret = ObjName($vVar, $OBJ_CLSID)
        If Not @error Then $tmp &= @LF & $sIndent & '    CLSID:            ' & $ret
        $ret = ObjName($vVar, $OBJ_IID)
        If Not @error Then $tmp &= @LF & $sIndent & '    InterfaceID:      ' & $ret
    EndIf
    Return $tmp
EndFunc   ;==>__DumpObj


Func __DumpStr(ByRef $vVar)
    Local $len = StringLen($vVar)
    Local $var = Execute("'" & StringRegExpReplace(StringReplace($vVar, "'", "''"), "([\p{Cc}])", "<0x' & Hex(AscW('$1'), 2) & '>") & "'")
    Return "'" & (($len <= 64) ? $var : StringMid($vVar, 1, 32) & ' ... ' & StringTrimLeft(StringMid($var, $len - 31, 32), 2)) & "'"
EndFunc   ;==>__DumpStr


Func __DumpBin(ByRef $vVar)
    Local $len = BinaryLen($vVar)
    Return (($len <= 32) ? $vVar : BinaryMid($vVar, 1, 16) & ' ... ' & StringTrimLeft(BinaryMid($vVar, $len - 15, 16), 2))
EndFunc   ;==>__DumpBin


Func __DumpFullStr(ByRef $vVar)
    $vVar = Execute("'" & StringRegExpReplace(StringReplace($vVar, "'", "''"), "([\p{Cc}])", "<0x' & Hex(AscW('$1'), 2) & '>") & "'")
    Return "'" & $vVar & "'"
EndFunc   ;==>__DumpFullStr


Func __DumpFullBin(ByRef $vVar)
    Return $vVar
EndFunc   ;==>__DumpFullBin


Func __DumpJSON(ByRef $vVar, $sIndent)
    Local $jstr = 'JSON_object'
    $sIndent &= $_TAB
    Local $v = $vVar
    Do
$cw($v)
        $v = StringRegExpReplace($v, '^(\s*\{\s*)', '')
        $jstr &=  @CRLF & $sIndent & StringFormat('%-16s', '"' & __DumpJsonString($v) & '"') & ' --> ' & __DumpJsonValue($v, $sIndent)
    Until StringRegExp($v, '^\s*\}\s*')
;~  $v = StringRegExpReplace($v, '^(\s*\}\s*)', '')
    Return $jstr
EndFunc   ;==>__DumpJSON


Func __DumpJsonString(ByRef $sStr)
    Local $aPair = StringRegExp($sStr, '(?x) \s* " (.*?) (?<! \\) " \s* (.*) \s*', 1)
    $sStr = $aPair[1]
    $aPair[0] = StringReplace($aPair[0], "'", "''")
    $aPair[0] = StringReplace($aPair[0], '\"', '"')
    $aPair[0] = StringReplace($aPair[0], '\/', '/')
    $aPair[0] = StringReplace($aPair[0], '\b', '<0x08>')
    $aPair[0] = StringReplace($aPair[0], '\f', '<0x0C>')
    $aPair[0] = StringReplace($aPair[0], '\n', '<0x0A>')
    $aPair[0] = StringReplace($aPair[0], '\r', '<0x0D>')
    $aPair[0] = StringReplace($aPair[0], '\t', '<0x09>')
    $aPair[0] = StringReplace($aPair[0], '\\', '\')     ; must be last replace
    Return Execute("'" & StringRegExpReplace($aPair[0], '\\u(....)', "' & ChrW('0x' & '$1') & '") & "'")
EndFunc   ;==>__DumpJsonString


Func __DumpJsonValue(ByRef $sStr, $sIndent)
    Local $jstr, $aPair
    Select
        Case StringLeft($sStr, 1) = ':'
            $sStr = StringRegExpReplace($sStr, ':\s*', '')
            $jstr &= __DumpJsonValue($sStr, $sIndent)   ; & '*a' & @CRLF
        Case StringLeft($sStr, 1) = '"'
            $jstr &= "'" & __DumpJsonString($sStr) & "'"
        Case StringRegExp($sStr, '^[-+]?\d+')
            $aPair = StringRegExp($sStr, '(?x) ^ ( [-+]? \d+ (?: \.\d+ )? (?: [Ee] [-+]? \d+ )? ) (.*)', 1)
            $sStr = $aPair[1]
            $jstr &= Number($aPair[0])  ; & '*c' & @CRLF
        Case StringLeft($sStr, 1) = 't'
            $sStr = StringRegExpReplace($sStr, '^\w*\s*', '')
            $jstr &= 'JSON_true'    ; & '*d' & @CRLF
        Case StringLeft($sStr, 1) = 'f'
            $sStr = StringRegExpReplace($sStr, '^\w*\s*', '')
            $jstr &= 'JSON_false'   ; & '*e' & @CRLF
        Case StringLeft($sStr, 1) = 'n'
            $sStr = StringRegExpReplace($sStr, '^\w*\s*', '')
            $jstr &= 'JSON_null'    ; & '*f' & @CRLF
        Case StringLeft($sStr, 1) = '['
            $jstr &= 'JSON_array'
            $sIndent &= $_TAB
            Do
                $sStr = StringRegExpReplace($sStr, '^[\[,]\s*', '')
                $jstr &=  @CRLF & $sIndent & __DumpJsonValue($sStr, $sIndent)
            Until StringRegExp($sStr, '^\s*\]\s*')
            $sStr = StringRegExpReplace($sStr, '^(\s*\]\s*)', '')
        Case StringLeft($sStr, 1) = '{'
            $jstr &= __DumpJSON($sStr, $sIndent)
    EndSelect
    Return $jstr
EndFunc   ;==>__DumpJsonValue

 

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

31 minutes ago, jchd said:

No need to quote what I posted.  I also said the code would need extra functions.
My purpose was to examplify thatwe can go a long way to dissect what a variable contains, contrary to what name we use to manipulate it.

Anyway here's the current version I use.

  Reveal hidden contents
#AutoIt3Wrapper_Version=B       ; beta 3.3.15.0 or greater is mandatory for Map datatype support

#include-once

#include <AutoItConstants.au3>
#include <String.au3>
#include <Math.au3>

Local Const $_TAB = '      '
Local $_DumpStr, $_DumpBin

; user-callable function, so that noone messes with __VarDump indentation
; $vVar is the variable to be dumped.
; $iLimit is the max number of entries of an array dimension, map or DllStruct array element to be displayed in full
; $bFullStr allows dumping strings in full
; $bFullBin allows dumping binary data in full
Func _VarDump(Const ByRef $vVar, $iLimit = 20, $bFullStr = 0, $bFullBin = 0)
    If $iLimit < 3 Then $iLimit = 0
    $_DumpStr = ($bFullStr ? __DumpFullStr : __DumpStr)
    $_DumpBin = ($bFullBin ? __DumpFullBin : __DumpBin)
    $sStr = $vVar
    Return (__VarDump($sStr, $iLimit))
EndFunc   ;==>_VarDump


Func __VarDump(ByRef $vVar, $iLimit, $sIndent = '', $sMore = '')
    Local $ret, $len, $ptr, $tmp

    Switch VarGetType($vVar)

        Case "String"
            If StringRegExp($vVar, '(?x)' & _
                '(?(DEFINE) (?<element> (?&ws) (?&value) (?&ws) ) )' & _
                '(?(DEFINE) (?<value> (?&ws) (?: (?&object) | (?&array) | (?&string) | (?&number) | true | false | null ) (?&ws) ) )' & _
                '(?(DEFINE) (?<object> \{ (?: (?&ws) | (?&member) (?: , (?&member) )* ) \} ) )' & _
                '(?(DEFINE) (?<member> (?&ws) (?&string) (?&ws) : (?&element) ) )' & _
                '(?(DEFINE) (?<array> \[ (?: (?&ws) | (?&value) (?: , (?&value) )* ) \] ) )' & _
                '(?(DEFINE) (?<string> " (?: \\ (?: ["\\/bnrt] | u [[:xdigit:]]{4} ) | [^[:cntrl:]\\"] )* " ) )' & _
                '(?(DEFINE) (?<number> [-+]? \d+ (?: \.\d+ )? (?: [Ee] [-+]? \d+ )? ) )' & _
                '(?(DEFINE) (?<ws> [\x09\x0A\x0D\x20]* ) )' & _
                '\A (?&object) \z') Then
                $tmp = $vVar
                Return __DumpJSON($tmp, $sIndent)
            Else
                Return StringFormat("%-19s", "String (" & StringLen($vVar) & ")") & $_DumpStr($vVar)
            EndIf

        Case "Double"
            Return 'Double             ' & $vVar & (IsInt($vVar) ? '.0' : '')

        Case "Int32", "Int64"
            Return VarGetType($vVar) & '              ' & $vVar

        Case "Array"
            Local $iDimensions = UBound($vVar, 0)
            Local $iCells = 1
            $ret = 'Array'
            $iDimensions -= 1
            For $i = 0 To $iDimensions
                $ret &= '[' & UBound($vVar, $i + 1) & ']'
                $iCells *= UBound($vVar, $i + 1)
            Next
            $sMore = _StringRepeat(' ', StringLen($ret) - 1)
            If $iCells = 0 Then
                Return $ret & $_TAB & '  (array is empty)'
            Else
                Return $ret & @CRLF & __VarDumpArray($vVar, $iLimit, $sIndent, $sMore)
            EndIf

        Case "Binary"
            $len = BinaryLen($vVar)
            $ret = 'Binary (' & BinaryLen($vVar) & ')             '
            Return ($ret & $_DumpBin($vVar))

        Case "Bool"
            Return 'Boolean            ' & $vVar

        Case "Keyword"
            Return ('Keyword            ' & ($vVar = Null ? 'Null' : ($vVar = Default ? 'Default' : 'Other keyword')))

        Case "Ptr"
            Return (IsHWnd($vVar) ? 'HWnd               ' : 'Pointer            ' & $vVar)

        Case "Object"
            Return __DumpObj($vVar, $iLimit, $sIndent & $_TAB, $sMore)

        Case "Function", "UserFunction"
            Return StringFormat('%-19s', VarGetType($vVar)) & FuncName($vVar)

        Case "DllStruct"
            $len = DllStructGetSize($vVar)
            $ptr = DllStructGetPtr($vVar)
            $ret = 'Struct             (' & $len & ') @:' & Hex($ptr) & ' (structure alignment is unknown)' & @CRLF
            Local $nbElem = 1, $idx, $incr, $data, $type, $indent = $sIndent & $_TAB, $oldvalue, $readvalue, $elem
            While 1
                $data = DllStructGetData($vVar, $nbElem)
                If @error = 2 Then ExitLoop
                $type = VarGetType($data)
                $idx = 1
                $incr = 0
                ; determine max index of element
                While 1
                    DllStructGetData($vVar, $nbElem, 2 * $idx)
                    If @error = 3 Then ExitLoop
                    $incr = $idx
                    $idx *= 2
                WEnd
                ; index is in [$idx, (2 * $idx) - 1]
                $idx += $incr
                Do
                    DllStructGetData($vVar, $nbElem, $idx)
                    If @error = 3 Then
                        ; approach is asymetric (upper bound is too big)
                        $idx -= ($incr = 1) ? 1 : $incr / 2
                    Else
                        $idx += Int($incr / 2)
                    EndIf
                    $incr = Int($incr / 2)
                Until $incr = 0
                Switch $type
                    Case "Int32", "Int64"
                        $ret &= $indent
                        $data = DllStructGetData($vVar, $nbElem, 1)
                        DllStructSetData($vVar, $nbElem, 0x7777666655554433, 1)
                        $readvalue = DllStructGetData($vVar, $nbElem, 1)
                        Switch $readvalue
                            Case 0x7777666655554433
                                $elem = "int64"
                                ; alias: uint64
                                ; alias: int_ptr(x64), long_ptr(x64), lresult(x64), lparam(x64)
                                ; alias: uint_ptr(x64), ulong_ptr(x64), dword_ptr(x64), wparam(x64)
                            Case 0x55554433
                                DllStructSetData($vVar, $nbElem, 0x88887777, 1)
                                $readvalue = DllStructGetData($vVar, $nbElem, 1)
                                $elem = ($readvalue > 0 ? "uint" : "int")
                                ; int aliases: long, bool, int_ptr(x86), long_ptr(x86), lresult(x86), lparam(x86);
                                ; uint aliases: ulong, dword, uint_ptr(x86), ulong_ptr(x86), dword_ptr(x86), wparam(x86)
                            Case 0x4433
                                DllStructSetData($vVar, $nbElem, 0x8888, 1)
                                $readvalue = DllStructGetData($vVar, $nbElem, 1)
                                $elem = ($readvalue > 0 ? "ushort" : "short")
                                ; ushort alias: word
                            Case 0x33
                                $elem = "byte"
                                ; alias: ubyte
                        EndSwitch
                        DllStructSetData($vVar, $nbElem, $data, 1)
                        If $idx = 1 Then
                            $ret &= StringFormat('%-' & 9 + StringLen($len) & 's ', $elem) & $data & @CRLF
                        Else
                            $ret &= $elem & "[" & $idx & "]" & @CRLF
                            For $i = 1 To $idx
                                If $iLimit And $idx > $iLimit And $i > $iLimit Then
                                    $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's ', '') & '... there are ' & $idx - $iLimit & ' more ' & $elem & ' in this array' & @CRLF
                                    ExitLoop
                                Else
                                    $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's ', '') & DllStructGetData($vVar, $nbElem, $i) & @CRLF
                                EndIf
                            Next
                        EndIf
                    Case "String"
                        $oldvalue = DllStructGetData($vVar, $nbElem, 1)
                        DllStructSetData($vVar, $nbElem, ChrW(0x2573), 1)
                        $readvalue = DllStructGetData($vVar, $nbElem, 1)
                        DllStructSetData($vVar, $nbElem, $oldvalue, 1)
                        $elem = ($readvalue = ChrW(0x2573) ? "wchar" : "char")
                        If $idx > 1 Then $elem &= "[" & $idx & "]"
                        $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's ', $elem) & $_DumpStr($data) & @CRLF
                    Case "Binary"
                        Local $blen = BinaryLen($data)
                        $elem = "byte"
                        If $idx > 1 Then $elem &= "[" & $idx & "]"
                        $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's ', $elem) & $_DumpBin($data) & @CRLF
                    Case "Ptr"
                        $ret &= $indent
                        $elem = "ptr"
                        ; alias: hwnd, handle
                        If $idx = 1 Then
                            $ret &= StringFormat('%-' & 9 + StringLen($len) & 's ', $elem) & $data & @CRLF
                        Else
                            $ret &= $elem & "[" & $idx & "]" & @CRLF
                            For $i = 1 To $idx
                                $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's ', '') & DllStructGetData($vVar, $nbElem, $i) & @CRLF
                            Next
                        EndIf
                    Case "Double"
                        $ret &= $indent
                        $oldvalue = DllStructGetData($vVar, $nbElem, 1)
                        DllStructSetData($vVar, $nbElem, 10 ^ - 15, 1)
                        $readvalue = DllStructGetData($vVar, $nbElem, 1)
                        DllStructSetData($vVar, $nbElem, $oldvalue, 1)
                        $elem = ($readvalue = 10 ^ - 15 ? "double" : "float")
                        If $idx = 1 Then
                            $ret &= StringFormat('%-' & 9 + StringLen($len) & 's ', $elem) & $data & (IsInt($data) ? '.0' : '') & @CRLF
                        Else
                            $ret &= $elem & "[" & $idx & "]" & @CRLF
                            For $i = 1 To $idx
                                If $iLimit And $idx > $iLimit And $i > $iLimit Then
                                    $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's ', '') & '... there are ' & $idx - $iLimit & ' more ' & $elem & ' in this array' & @CRLF
                                    ExitLoop
                                Else
                                    $ret &= $indent & StringFormat('%-' & 9 + StringLen($len) & 's %s', '', DllStructGetData($vVar, $nbElem, $i)) & (IsInt(DllStructGetData($vVar, $nbElem, $i)) ? '.0' : '') & @CRLF
                                EndIf
                            Next
                        EndIf
                EndSwitch
                $nbElem += 1
            WEnd
            Return StringTrimRight($ret, 2)

        Case "Map"
            Local $iCells = UBound($vVar)
            $ret = 'Map[' & $iCells & ']'
            If $iCells = 0 Then
                Return $ret & $_TAB & '  (map is empty)'
            Else
                Return $ret & @CRLF & __VarDumpMap($vVar, $iLimit, $sIndent, '    ')
            EndIf

        Case Else
            Return StringFormat('%-19s', VarGetType($vVar)) & $vVar

    EndSwitch
EndFunc   ;==>__VarDump


Func __VarDumpArray(Const ByRef $aArray, $iLimit, $sIndent = $_TAB, $sMore = '')
    Local $sDump, $sArrayFetch, $sArrayRead, $iDone = 0, $iElements = 1
    Local $iDimensions = UBound($aArray, 0)
    Local $aUBounds[$iDimensions]
    Local $aIndices[$iDimensions]
    $iDimensions -= 1
    For $i = 0 To $iDimensions
        $aUBounds[$i] = UBound($aArray, $i + 1) - 1
        $iElements *= $aUBounds[$i] + 1
        $aIndices[$i] = 0
    Next
    $sIndent &= $_TAB
    While $iDone < ($iLimit ? _Min($iLimit, $iElements) : $iElements)
        $sArrayFetch = ''
        For $i = 0 To $iDimensions
            $sArrayFetch &= '[' & $aIndices[$i] & ']'
        Next
        $sArrayRead = Execute('$aArray' & $sArrayFetch)
        $sDump &= $sIndent & $sArrayFetch & ' => ' & __VarDump($sArrayRead, $iLimit, $sIndent, $sMore) & @CRLF
        $iDone += 1
        If $iLimit And $iDone = $iLimit Then
            $sDump &= $sIndent & '... there are ' & $iElements - $iDone & ' more elements in this array' & @CRLF
            ExitLoop
        EndIf

        For $i = $iDimensions To 0 Step -1
            $aIndices[$i] += 1
            If $aIndices[$i] > $aUBounds[$i] Then
                $aIndices[$i] = 0
            Else
                ExitLoop
            EndIf
        Next
    WEnd
    Return (StringTrimRight($sDump, 2))
EndFunc   ;==>__VarDumpArray


Func __VarDumpMap(ByRef $mMap, $iLimit, $sIndent = $_TAB, $sMore = '')
    Local $i = 0, $sDump
    $sIndent &= $_TAB
    For $key In MapKeys($mMap)
        $sDump &= $sIndent & StringFormat('%-22s => ', _
                "[" & (IsString($key) ? __DumpStr($key) : $key) & "]")
        $sDump &= __VarDump($mMap[$key], $iLimit, $sIndent, $sMore) & @CRLF
        If $iLimit And $i = $iLimit - 1 Then
            $sDump &= $sIndent & '... there are ' & UBound($mMap) - $i - 1 & ' more elements in this map' & @CRLF
            ExitLoop
        EndIf
        $i += 1
    Next
    Return (StringTrimRight($sDump, 2))
EndFunc   ;==>__VarDumpMap


Func __DumpObj(Const ByRef $vVar, $iLimit, $sIndent = $_TAB, $sMore = '')
    $ret = ObjName($vVar, $OBJ_NAME)
    If $ret = "Dictionary" Then
        With $vVar
            $tmp = 'Scripting.Dictionary'
            For $key In .keys()
                $tmp &= @LF & $sIndent & '    ' & StringFormat("%-32s    %s", __VarDump($key, $iLimit, $sIndent), __VarDump(.item($key), $iLimit, $sIndent))
            Next
        EndWith
    Else
        $tmp = 'Object' & @LF & $sIndent & '    Name:             ' & $ret
        $ret = ObjName($vVar, $OBJ_STRING)
        If Not @error Then $tmp &= @LF & $sIndent & '    Description:      ' & $ret
        $ret = ObjName($vVar, $OBJ_PROGID)
        If Not @error Then $tmp &= @LF & $sIndent & '    ProgID:           ' & $ret
        $ret = ObjName($vVar, $OBJ_FILE)
        If Not @error Then $tmp &= @LF & $sIndent & '    Associated file:  ' & $ret
        $ret = ObjName($vVar, $OBJ_MODULE)
        If Not @error Then $tmp &= @LF & $sIndent & '    Owner/marshaller: ' & $ret
        $ret = ObjName($vVar, $OBJ_CLSID)
        If Not @error Then $tmp &= @LF & $sIndent & '    CLSID:            ' & $ret
        $ret = ObjName($vVar, $OBJ_IID)
        If Not @error Then $tmp &= @LF & $sIndent & '    InterfaceID:      ' & $ret
    EndIf
    Return $tmp
EndFunc   ;==>__DumpObj


Func __DumpStr(ByRef $vVar)
    Local $len = StringLen($vVar)
    Local $var = Execute("'" & StringRegExpReplace(StringReplace($vVar, "'", "''"), "([\p{Cc}])", "<0x' & Hex(AscW('$1'), 2) & '>") & "'")
    Return "'" & (($len <= 64) ? $var : StringMid($vVar, 1, 32) & ' ... ' & StringTrimLeft(StringMid($var, $len - 31, 32), 2)) & "'"
EndFunc   ;==>__DumpStr


Func __DumpBin(ByRef $vVar)
    Local $len = BinaryLen($vVar)
    Return (($len <= 32) ? $vVar : BinaryMid($vVar, 1, 16) & ' ... ' & StringTrimLeft(BinaryMid($vVar, $len - 15, 16), 2))
EndFunc   ;==>__DumpBin


Func __DumpFullStr(ByRef $vVar)
    $vVar = Execute("'" & StringRegExpReplace(StringReplace($vVar, "'", "''"), "([\p{Cc}])", "<0x' & Hex(AscW('$1'), 2) & '>") & "'")
    Return "'" & $vVar & "'"
EndFunc   ;==>__DumpFullStr


Func __DumpFullBin(ByRef $vVar)
    Return $vVar
EndFunc   ;==>__DumpFullBin


Func __DumpJSON(ByRef $vVar, $sIndent)
    Local $jstr = 'JSON_object'
    $sIndent &= $_TAB
    Local $v = $vVar
    Do
$cw($v)
        $v = StringRegExpReplace($v, '^(\s*\{\s*)', '')
        $jstr &=  @CRLF & $sIndent & StringFormat('%-16s', '"' & __DumpJsonString($v) & '"') & ' --> ' & __DumpJsonValue($v, $sIndent)
    Until StringRegExp($v, '^\s*\}\s*')
;~  $v = StringRegExpReplace($v, '^(\s*\}\s*)', '')
    Return $jstr
EndFunc   ;==>__DumpJSON


Func __DumpJsonString(ByRef $sStr)
    Local $aPair = StringRegExp($sStr, '(?x) \s* " (.*?) (?<! \\) " \s* (.*) \s*', 1)
    $sStr = $aPair[1]
    $aPair[0] = StringReplace($aPair[0], "'", "''")
    $aPair[0] = StringReplace($aPair[0], '\"', '"')
    $aPair[0] = StringReplace($aPair[0], '\/', '/')
    $aPair[0] = StringReplace($aPair[0], '\b', '<0x08>')
    $aPair[0] = StringReplace($aPair[0], '\f', '<0x0C>')
    $aPair[0] = StringReplace($aPair[0], '\n', '<0x0A>')
    $aPair[0] = StringReplace($aPair[0], '\r', '<0x0D>')
    $aPair[0] = StringReplace($aPair[0], '\t', '<0x09>')
    $aPair[0] = StringReplace($aPair[0], '\\', '\')     ; must be last replace
    Return Execute("'" & StringRegExpReplace($aPair[0], '\\u(....)', "' & ChrW('0x' & '$1') & '") & "'")
EndFunc   ;==>__DumpJsonString


Func __DumpJsonValue(ByRef $sStr, $sIndent)
    Local $jstr, $aPair
    Select
        Case StringLeft($sStr, 1) = ':'
            $sStr = StringRegExpReplace($sStr, ':\s*', '')
            $jstr &= __DumpJsonValue($sStr, $sIndent)   ; & '*a' & @CRLF
        Case StringLeft($sStr, 1) = '"'
            $jstr &= "'" & __DumpJsonString($sStr) & "'"
        Case StringRegExp($sStr, '^[-+]?\d+')
            $aPair = StringRegExp($sStr, '(?x) ^ ( [-+]? \d+ (?: \.\d+ )? (?: [Ee] [-+]? \d+ )? ) (.*)', 1)
            $sStr = $aPair[1]
            $jstr &= Number($aPair[0])  ; & '*c' & @CRLF
        Case StringLeft($sStr, 1) = 't'
            $sStr = StringRegExpReplace($sStr, '^\w*\s*', '')
            $jstr &= 'JSON_true'    ; & '*d' & @CRLF
        Case StringLeft($sStr, 1) = 'f'
            $sStr = StringRegExpReplace($sStr, '^\w*\s*', '')
            $jstr &= 'JSON_false'   ; & '*e' & @CRLF
        Case StringLeft($sStr, 1) = 'n'
            $sStr = StringRegExpReplace($sStr, '^\w*\s*', '')
            $jstr &= 'JSON_null'    ; & '*f' & @CRLF
        Case StringLeft($sStr, 1) = '['
            $jstr &= 'JSON_array'
            $sIndent &= $_TAB
            Do
                $sStr = StringRegExpReplace($sStr, '^[\[,]\s*', '')
                $jstr &=  @CRLF & $sIndent & __DumpJsonValue($sStr, $sIndent)
            Until StringRegExp($sStr, '^\s*\]\s*')
            $sStr = StringRegExpReplace($sStr, '^(\s*\]\s*)', '')
        Case StringLeft($sStr, 1) = '{'
            $jstr &= __DumpJSON($sStr, $sIndent)
    EndSelect
    Return $jstr
EndFunc   ;==>__DumpJsonValue

 

 

Thanks! Yes, as you said, If only there were extra functions.....

Link to comment
Share on other sites

What is missing?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

You could pass the line number of your script along with your variable to the function like this:

Local $myVar = 8675309

debugVariable(@ScriptLineNumber, $myVar)

Func debugVariable($line, $value)

    Local $lineContents = FileReadLine(@ScriptFullPath, $line)
    Local $varName = "$" & StringSplit($lineContents, "$)")[2]
    ConsoleWrite($varName & ": " & $value & @CRLF)

EndFunc

... but it will only work when you haven't compiled the script. If you needed, you could FileInstall your source code and read from there with a compiled script.

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Yes you can!  But then how hard is it to use that instead?

debugVariable($myVar, "$myVar")

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • 1 month later...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...