Jump to content

Create empty array inside Scripting.Dictionary object


Recommended Posts

Is there a way I can create an array inside a dictionary this way (without creating a variable first):

Local $myDictionary = ObjCreate("Scripting.Dictionary")
$myDictionary.Add("firstDictionary", ObjCreate("Scripting.Dictionary")) ;this is ok
$myDictionary.Add("firstarray", []) ;this is wrong

_ArrayAdd($myDictionary.Item("firstArray"), "first element in firstArray")
_ArrayAdd($myDictionary.Item("firstArray"), "second element in firstArray")

This caused a popup with "Error in expression"
Shouldn't this [] return an empty sized array?

And for some reason I cannot add elements when an array is inside a dictionary:

Local $newArray[1]
Local $myDictionary = ObjCreate("Scripting.Dictionary")
 
_ArrayAdd($newArray,101) ;this is ok
$myDictionary.Add("firstArray", $newArray)

;_ArrayAdd($myDictionary.Item("firstArray"), 102)  ; this is wrong
_ArrayAdd(($myDictionary.Item("firstArray")), 102)  ; this does not change the dictionary array
_ArrayDisplay(($myDictionary.Item("firstArray")))  ; this still shows 101
Edited by somedude12
Link to comment
Share on other sites

The scripting dictionary can only store strings, so the only way to store an array is to convert it to a string first.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Try this...

 

#include <Array.au3>

;~ Is there a way I can create an array inside a dictionary this way (without creating a variable first):
Global Const $SD = "Scripting.Dictionary"
Local $myDictionary = ObjCreate($SD)
;~ I agree, this way work!
$myDictionary.Add("firstDictionary", ObjCreate($SD)) ;this is ok
;~ you are write, this way does not work...
;~ $myDictionary.Add("firstarray", []) ;this is wrong

;~ If you put an array in SD, try this...

Local $arr[1] = ["item_1"]
$myDictionary.Add("array", $arr)
_ArrayDisplay(($myDictionary.Item("array"))) ; to display an array inside SD, put it between ()

Add_Obj_Array($myDictionary, "array", "item_2")

_ArrayDisplay(($myDictionary.Item("array")))
;_ArrayAdd( ($myDictionary.Item("array")), "teste_2")

Func Add_Obj_Array(ByRef $oo, $array, $element)
    Local $arr = $oo.Item($array)
    _ArrayAdd($arr, $element)
    $oo.Item($array) = $arr
EndFunc   ;==>Add_Obj_Array

obs: see this, I work with SD too, and for me, I can not see this code work without SD.

Edited by Detefon

Visit my repository

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

  • Recently Browsing   0 members

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