Confused with For Loop and Object. Please help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Confused with For Loop and Object. Please help

07 Mar 2018, 11:50

Here is my example code:

I suppose to get value "E", but I got "45". Why? :?

Code: Select all

TestObject := Object()
Value :=0	

loop 10
 {
 	i := A_index
 		loop 10
 		{
 			j:=A_Index
 			Value ++
 			TestObject[i,j] := Value
 		}
 }
 
 for i, L in TestObject
 {
    NewV := ["A","B","C","D","E","F","G"]
    L := NewV
 }
 
 Msgbox % TestObject[5,5]
 ;I suppose to get value "E", but I got "45"
If I change the code to the follows, Result is "E".

Code: Select all

for i, L in TestObject
 {
   if (i=5)
     L[5] := "E"
 }
If I changed the code to:

Code: Select all

for i, L in TestObject
 {
   NewV := ["A","B","C","D","E","F","G"]
   L := NewV
   if (i=5)
   L[5] := "E"
 }
It shows "45" again.

I'm really confused. Please help!

Thank you in advance! :salute:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, doodles333, ulysim and 378 guests