Quantcast
Channel: AutoHotkey Community
Viewing all articles
Browse latest Browse all 579

Ask for Help (v2) • Re: Issue with Building an Array Using a Loop

$
0
0
A valid array index needs to be less than or equal to the array length. Ier := [] creates an array with a length of 0.
In the first iteration of the loop, it tries to set Ier[1] := []. 1 is an invalid index because it's greater than Ier.length.
You can set the length after creating Ier:

CODE:

#Requires Autohotkey v2.0
#SingleInstance Force


Ier := []
Ier.Length := 8
Aer := ["a", "b", "c", "d", "e", "f","g","h"]
Loop 8
{

Ier[A_index] := []
Ier[A_Index].Push(Aer[A_index])
}

MsgBox Ier[2][1]


Or push an array instead:

CODE:

#Requires Autohotkey v2.0
#SingleInstance Force


Ier := []
Aer := ["a", "b", "c", "d", "e", "f","g","h"]
Loop 8
{

Ier.Push([])
Ier[A_Index].Push(Aer[A_index])
}

MsgBox Ier[2][1]

Statistics: Posted by ntepa — Today, 17:55



Viewing all articles
Browse latest Browse all 579

Trending Articles