somedude12 Posted December 24, 2014 Posted December 24, 2014 (edited) 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 December 24, 2014 by somedude12
Bowmore Posted December 26, 2014 Posted December 26, 2014 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
Luigi Posted December 26, 2014 Posted December 26, 2014 (edited) 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 December 26, 2014 by Detefon somedude12 1 Visit my repository
somedude12 Posted December 27, 2014 Author Posted December 27, 2014 (edited) You are right Detefon, thank you brother. Sometimes dictionaries can get really messy by it's syntax, but I cannot leave AutoIt. Edited December 27, 2014 by somedude12
Mat Posted December 29, 2014 Posted December 29, 2014 For completeness, this was also asked on SO, here. somedude12 1 AutoIt Project Listing
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now