Sign in to follow this  
Followers 0
Luigi

Scripting.Dictionary: another way to set a value, is possible?

1 post in this topic

#1 ·  Posted (edited)

Greetings forum!

You know another way to do set a new value in nested Scripting.Dictionary?

I make this litle function called 'set', you pass the Scripting.Dictionary, the path and the value...

The function split the path, and set the new value.

I found this way, there are another?

Br, Detefon

#include <Array.au3>
Local $SD = "Scripting.Dictionary"
Local $oo = ObjCreate($SD)
$oo.Add("key", 0)
$oo.Add("array", ObjCreate($SD))
$oo.Item("array").Add("one", 1)
$oo.Item("array").Add("two", 2)

ConsoleWrite("before" & @LF)
ConsoleWrite("      key[ " & $oo.Item("key") & " ]" & @LF)
ConsoleWrite("array.one[ " & $oo.Item("array").Item("one") & " ]" & @LF)


set($oo, "key", 1)
set($oo, "array.one", 6)

Func set(ByRef $oo, $path, $value)
    Local $oTemp = $oo
    Local $aPath = StringSplit($path, ".")
    Local $sPath = '.Item("' & _ArrayToString($aPath, '").Item("', 1) & '")'
    Switch $aPath[0]
        Case 1
            With $oo
                .Item($aPath[1]) = $value
            EndWith
        Case 2
            With $oo
                .Item($aPath[1]).Item($aPath[2]) = $value
            EndWith
        Case 3
            With $oo
                .Item($aPath[1]).Item($aPath[2]).Item($aPath[3]) = $value
            EndWith
    EndSwitch
EndFunc   ;==>set

ConsoleWrite(@LF & "after" & @LF)
ConsoleWrite("      key[ " & $oo.Item("key") & " ]" & @LF)
ConsoleWrite("array.one[ " & $oo.Item("array").Item("one") & " ]" & @LF)
Edited by Detefon

Visit my repository

Share this post


Link to post
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
Sign in to follow this  
Followers 0