![Smile :)](./images/smilies/icon_e_smile.gif)
http://imgur.com/5Cz1sOh
Code: Select all
class ObjectWithCounter
{
count()
{
return NumGet(&this + 4*A_PtrSize)
}
}
MyObject:=new ObjectWithCounter()
MyObject.push("a")
MyObject.push("b")
msgbox, % MyObject.count()
I too have had this incident come about time and time again. But today I was reading through this and if I interpret it correctly, it would do what we want, no?tidbit wrote:ran into this need for .key a couple times lately:
Due to the Objects auto-ABC sort, I need to turn 1D arrays into 2D arrays.
Each sub-array only consists of 1 array/object.
Usage: I have a treeview and a listbox. I can add items from the treeview to the listbox, when added to the LB, add to an object aswell. Something like: {TV_ID : TV_TEXT}. But since I want it in the order of which it's added to the LB (incase I need to rebuild the LB, if I delete an item), I need to make it a 2D Array, to avoid auto-sorting.
Code: Select all
arr:=[{"437742":"first"},{"122516":"second"},{"472125":"third"}] ; instead of this for every part I go through the array (this gets messier when other {}'s are needed for the for-loops): for key, arr2 in arr for key, val in arr2 msgBox, %key% = %val% ; it'd simply be: for key, arr2 in arr msgBox, % arr2.key(1) " = " arr2.value(1) ; or if I only need the 3rd item from the list msgbox % arr[3].key(1 " = " arr[3].value(1))
+1 here too!⠀⠀⠀⠀ItemCount := Object.Count() / ObjCount(Object)
Counts the number of items in an array/object.
Users browsing this forum: No registered users and 30 guests