Get item from array Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Wigi
Posts: 140
Joined: 05 Jun 2017, 10:52
Contact:

Get item from array

17 Nov 2017, 15:00

Hello all,

I hope this is an easy question.

I am looping over an array:

Code: Select all

                StringSplit, ParamArray, sText, `n
                Loop, %ParamArray0%
                {
                }
Let's say the array contains 30 elements. I need to loop from 1 to 10,
and each time I need to store 3 variables:
- the value in the array at position x
- the value in the array at position x+10
- the value in the array at position x+20

So, there are 3 parts in the array: 1 to 10, 11 to 20, 21 to 30. They need to come by in groups of 3: 1, 11, 21, then 2, 12, 22, then 3, 13, 23, ...

How can I code this please ?
None of the syntaxes I tried seems to work.
I use A_index, but then referring to A_Index + 10, A_Index + 20 seems impossible.

Wim
User avatar
boiler
Posts: 17048
Joined: 21 Dec 2014, 02:44

Re: Get item from array

17 Nov 2017, 15:21

That's one reason array objects are better than pseudo arrays, which you can do by using StrSlit() instead of StringSplit. But you can still do it. Try using an intermediate variable:

Index10 := A_Index + 10
Index20 := A_Index + 20

Then you can refer to ParamArray%Index10% and ParamArray%Index20%.
Wigi
Posts: 140
Joined: 05 Jun 2017, 10:52
Contact:

Re: Get item from array

17 Nov 2017, 15:24

Thanks, I will implement it and see if I can get it working.
Wigi
Posts: 140
Joined: 05 Jun 2017, 10:52
Contact:

Re: Get item from array

17 Nov 2017, 15:31

Strange but it seems to be here that I am having a difficulty.
This works:

Code: Select all

                    Index_type := A_Index + 10
                    Index_default := A_Index + 20
but this does not work:

Code: Select all

                    Index_type := A_Index + ( Nr_of_params * 1 ) + 1
                    Index_default := A_Index + ( Nr_of_params * 2 ) + 2
Do I need to do a conversion ? In the second case, I get numbers like 16.000000 instead of 16

That 10 and 20 in my example were simplifications, now I am working with an offset that depends on the number of items in the array.

Thank you.
User avatar
boiler
Posts: 17048
Joined: 21 Dec 2014, 02:44

Re: Get item from array  Topic is solved

17 Nov 2017, 18:13

Your variable Nr_of_params must be a floating point value. Try this:

Code: Select all

                    Index_type := A_Index + ( floor(Nr_of_params) * 1 ) + 1
                    Index_default := A_Index + ( floor(Nr_of_params) * 2 ) + 2
Wigi
Posts: 140
Joined: 05 Jun 2017, 10:52
Contact:

Re: Get item from array

17 Nov 2017, 19:33

Thanks. It’s well after midnight here, I will check it out tomorrow.
Wigi
Posts: 140
Joined: 05 Jun 2017, 10:52
Contact:

Re: Get item from array

18 Nov 2017, 04:29

It works with Floor ! Many thanks boiler.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, jollyjoe and 266 guests