AHK: Array _Loop

Get help with using AutoHotkey and its commands and hotkeys
inseption86
Posts: 72
Joined: 19 Apr 2018, 00:24

AHK: Array _Loop

07 Feb 2019, 08:30

Hi guys, please wait, how to simplify this code :

Code: Select all

Arr := Array("1", "5", "10","1", "5", "10","1", "5", "10", "1", "5", "10"..........................)
Arr1 := Array("0", "0", "0", "1", "1", "1","2", "2", "2","3", "3", "3"........................)

loop 100
{
ie.document.getElementsByClassName("Nnq7C weEfm")[Arr1[A_index]].getElementsByTagName("div")[Arr[A_index]].click()
}

So that in the end it turned out, such as:

Code: Select all

ie.document.getElementsByClassName("Nnq7C weEfm")[0].getElementsByTagName("div")[1].click()
ie.document.getElementsByClassName("Nnq7C weEfm")[0].getElementsByTagName("div")[5].click()
ie.document.getElementsByClassName("Nnq7C weEfm")[0].getElementsByTagName("div")[10].click()

ie.document.getElementsByClassName("Nnq7C weEfm")[1].getElementsByTagName("div")[1].click()
ie.document.getElementsByClassName("Nnq7C weEfm")[1].getElementsByTagName("div")[5].click()
ie.document.getElementsByClassName("Nnq7C weEfm")[1].getElementsByTagName("div")[10].click()

ie.document.getElementsByClassName("Nnq7C weEfm")[2].getElementsByTagName("div")[1].click()
ie.document.getElementsByClassName("Nnq7C weEfm")[2].getElementsByTagName("div")[5].click()
ie.document.getElementsByClassName("Nnq7C weEfm")[2].getElementsByTagName("div")[10].click()


ie.document.getElementsByClassName("Nnq7C weEfm")[3].getElementsByTagName("div")[1].click()
ie.document.getElementsByClassName("Nnq7C weEfm")[3].getElementsByTagName("div")[5].click()
ie.document.getElementsByClassName("Nnq7C weEfm")[3].getElementsByTagName("div")[10].click()

ie.document.getElementsByClassName("Nnq7C weEfm")[4].getElementsByTagName("div")[1].click()
ie.document.getElementsByClassName("Nnq7C weEfm")[4].getElementsByTagName("div")[5].click()
ie.document.getElementsByClassName("Nnq7C weEfm")[4].getElementsByTagName("div")[10].click()

ie.document.getElementsByClassName("Nnq7C weEfm")[5].getElementsByTagName("div")[1].click()
ie.document.getElementsByClassName("Nnq7C weEfm")[5].getElementsByTagName("div")[5].click()
ie.document.getElementsByClassName("Nnq7C weEfm")[5].getElementsByTagName("div")[10].click()

......
........

swagfag
Posts: 2926
Joined: 11 Jan 2017, 17:59

Re: AHK: Array _Loop

07 Feb 2019, 08:49

Code: Select all

loop 100
	clickElements(ie, (A_Index - 1), [1, 5, 10])

clickElements(ie, firstID, SecondIDs) {
	div := ie.document.getElementsByClassName("Nnq7C weEfm")[firstID].getElementsByTagName("div")

	for each, index in SecondIDs
		div[index].click()
}
User avatar
Scr1pter
Posts: 1069
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: AHK: Array _Loop

07 Feb 2019, 08:53

Hi,

I believe you could work it out without the Arrays, but I'm on the phone now, so I'll help you with arrays.

First, I would rename both arrays.

Code: Select all

Arr1 := ["1", "5", "10","1", "5", "10","1", "5", "10", "1", "5", "10"..........................]
Arr2 := ["0", "0", "0", "1", "1", "1","2", "2", "2","3", "3", "3"........................]
Then you can use helper variables inside of the loop.

Code: Select all

array1 := Arr1[A_Index]
array2 := Arr2[A_Index]
Then, just write it like this:

Code: Select all

ie.document.getElementsByClassName("Nnq7C weEfm")%array1%.getElementsByTagName("div")%array2%.click()
Check the syntaxes.
Not sure if you need at least one pair of [].

Edit
swagfag :x :lol:

Cheers!
Please use code tags when posting code!
Keyboard: Logitech G15 FE - Mice: Logitech G9 FE, G502 FE, G602 - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.29.00

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Odlanir, whitestar127 and 67 guests