Please make me understand why the behavior of these two arrays is different as shown in these two examples?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

Please make me understand why the behavior of these two arrays is different as shown in these two examples?

14 Mar 2019, 13:39

FIRST EXAMPLE-

I have these values in range a1:a10 -

14_03_19 @11_34_52.PNG
14_03_19 @11_34_52.PNG (4.7 KiB) Viewed 1353 times
Now please look at these codes-

Code: Select all

Xl := ComObjActive("Excel.Application")
	A := {}
	for key, value in Xl.Range("a1:a11")
		MsgBox % key ; shows empty msgbox
In the above codes you can see that i convert the values of range a1:a10 into an array and then i try to show the key which, i think, should be the index number of each value, in msgbox then it shows an empty msgbox.



Now, when i try to show only the value which should be value of each cell like- 500, 600, 900, 100 so on till 900, by following codes then it shows 9 in each msgbox-

Code: Select all

Xl := ComObjActive("Excel.Application")
	A := {}
	for key, value in Xl.Range("a1:a11")
		MsgBox % value ; shows 9 in each msgbox, very strange!!!!
I don't understand why it is happening?


SECOND EXAMPLE-

Code: Select all

arr:= {jone:"smith",sam:"donn",frank:"caine"}
for key,value in arr
	MsgBox % key ; shows jonw, sam and frank
In above codes, it is showing the key of each pair which is - jone, sam and frank


Now when i run following codes-

Code: Select all

arr:= {jone:"smith",sam:"donn",frank:"caine"}
for key,value in arr
	MsgBox % value ; shows smith donn and caine

Then, it shows the value of each pair which is smith, donn and caine.


I am not understanding why each key and value is shown individually in second example, while it is not showing individual key and value of cell in first example?

Please help and guide me..

THANKS A LOT..
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
User avatar
sinkfaze
Posts: 614
Joined: 01 Oct 2013, 08:01

Re: Please make me understand why the behavior of these two arrays is different as shown in these two examples?

14 Mar 2019, 14:45

You're not dealing with the same types of objects.

One is an AHK object, the other is an Excel object, they work with for-loops differently.

Code: Select all

Xl := ComObjActive("Excel.Application")
for c in Xl.Range("a1:a11")
	MsgBox % c.Value
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

Re: Please make me understand why the behavior of these two arrays is different as shown in these two examples?

15 Mar 2019, 00:21

sinkfaze wrote:
14 Mar 2019, 14:45
You're not dealing with the same types of objects.

One is an AHK object, the other is an Excel object, they work with for-loops differently.

Code: Select all

Xl := ComObjActive("Excel.Application")
for c in Xl.Range("a1:a11")
	MsgBox % c.Value
Thanks dear sinkfaze for your kind reply...

sir, my biggest confusion is that, why the following codes are showing 9 in each msgbox????-

Code: Select all

Xl := ComObjActive("Excel.Application")
	A := {}
	for key, value in Xl.Range("a1:a10")
		MsgBox % value ; shows 9 in each msgbox, very strange!!!!
I think either it should show and empty msgbox or the value of current cell. But, it is not showing both. It does not make any sense showing 9 in each msgbox. Please guide and solve my quarry. Thanks a lot dear sinkfaze....
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Please make me understand why the behavior of these two arrays is different as shown in these two examples?

15 Mar 2019, 00:39

When you have reply comments.
You'd better take a look at it, even with skimming.
and
You'd better say a brief word, "thanks".

I have commented 3 links
the first one has the clear reason for your asking

...For COM objects, Key contains the value returned by IEnumVARIANT::Next() and Value contains a number which represents its variant type... See ComObjType for a list of type codes.

the second has proper values clearly "9"

Code: Select all

VT_DISPATCH  = 9   ; COM object
I feel like wasted my time
Last edited by IMEime on 15 Mar 2019, 01:26, edited 1 time in total.
hd0202
Posts: 148
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: Please make me understand why the behavior of these two arrays is different as shown in these two examples?

15 Mar 2019, 01:26

@IMEime
you could have shown him the reason for his asking (not only pointing him to 3 pages)
Key contains the value returned by IEnumVARIANT::Next() and Value contains a number which represents its variant type
and that this is always 9 = COM object

then he had a chance to understand and say "thanks"

Hubert
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Please make me understand why the behavior of these two arrays is different as shown in these two examples?

15 Mar 2019, 01:36

and
If you do Not understand it, You do Not represent any kind of appreciation ?
If you say so, that looks very convenient attitude.

The understanding depends on him/her Not me, I have showed the ultimate answer to the question.
hd0202
Posts: 148
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: Please make me understand why the behavior of these two arrays is different as shown in these two examples?

15 Mar 2019, 01:42

@IMEime
sorry, but another two snotty answer

you have edited your other answer (I think) after reading my explanation

Hubert
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Please make me understand why the behavior of these two arrays is different as shown in these two examples?

15 Mar 2019, 01:53

What is the your point ?

There is no YOUR explanations
I can see only the explanations which already showed in HELP document.

.... you have made me to wasted my time again.
just me
Posts: 6669
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Please make me understand why the behavior of these two arrays is different as shown in these two examples?

15 Mar 2019, 03:51

IMEime wrote:
15 Mar 2019, 01:53
.... you have made me to wasted my time again.
You're definitely right. And you shouldn't do it any more.
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

Re: Please make me understand why the behavior of these two arrays is different as shown in these two examples?

15 Mar 2019, 10:14

IMEime wrote:
15 Mar 2019, 04:18
Right

I'm done
No more to say, as in SQLite

Regards
Thanks a lot dear IMEime.

I am quite beginner so it is quite difficult to understand programming related stuff for me, that's why i asked it again. Anyway thanks you so much...
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
User avatar
sinkfaze
Posts: 614
Joined: 01 Oct 2013, 08:01

Re: Please make me understand why the behavior of these two arrays is different as shown in these two examples?

15 Mar 2019, 10:24

IMEime has given the specifics, I refrained from doing so because, in this case, it's a lot like going to the doctor and complaining that it hurts when you stab yourself with a knife. It doesn't really matter why it hurts at that point, stop stabbing yourself.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], georgedx, kookuei and 228 guests