Page 1 of 1

Loop with increments 1a, 1b, 1c, 2a, 2b, 2c, 3a etc

Posted: 30 Aug 2018, 21:51
by cnahk
Hello, I need to loop the following:

Code: Select all

#!F11::
CoordMode, Mouse, Window
MouseGetPos, StartX, StartY
IfwinExist, ahk_exe abc.exe
WinActivate, ahk_exe abc.exe
WinwaitActive, ahk_exe abc.exe
// loop
Click 2400, 1321
Send {down}
Click 3312, 1321
Send %NUMBER%
// loop
Where %NUMBER% must be the following number+letter each loop:

1a
1b
1c
2a
2b
2c
3a
3b
3c
etc until 500a 500b 500c

I have no idea how to accomplish this... is it possible?

Thanks in advance!

Re: Loop with increments 1a, 1b, 1c, 2a, 2b, 2c, 3a etc

Posted: 30 Aug 2018, 21:59
by Datapoint

Code: Select all

Loop, 500
{
    i := A_Index
    Loop, 3
    {
        ;Send % i . Chr(96 + A_Index)
        MsgBox % i . Chr(96 + A_Index)
    }
}

Re: Loop with increments 1a, 1b, 1c, 2a, 2b, 2c, 3a etc

Posted: 30 Aug 2018, 22:05
by Exaskryz
There's more than one way to solve this problem. Rather than any loop inside of a loop, here's an answer with a single loop.

In a loop, you have the variable A_Index. We will use this in conjunction with the Ceil() function (Ceil, rounds up) and the Mod() function (Modulus, calculates a remainder from division).

I am going to use the Ternary operator which is a way to say If/else.

The . in there is a concatenate operator. This is how we'll put a number with a letter.

You will see me using a Forced Expression by using a lone % at the start of the Send parameter.

Code: Select all

Loop, 15 ; make into 1500 if you want 1a-500c
{ ; optional when only a single command is in the Loop
Send % Ceil(A_Index/3) . (Mod(A_Index,3)=1 ? "a" : Mod(A_Index,3) = 2 ? "b" : "c")
}
return
The answer by Datapoint reminded me about the Chr() function and that may be used here in fact. It's just a little messy since Mod will loop, when the divisor is 3, between values 1, 2, 0, not 0, 1, 2.

Code: Select all

Loop, 15
    Send % Ceil(A_Index/3) . (Mod(A_Index,3)=0 ? "c" : Chr(96 + Mod(A_Index,3)))
return

Re: Loop with increments 1a, 1b, 1c, 2a, 2b, 2c, 3a etc

Posted: 30 Aug 2018, 22:10
by cnahk
You guys are awesome, thanks for that!

Is it possible to start the loop from a different number than 1, say 150a 150b 150c, etc etc until 500 ?

Re: Loop with increments 1a, 1b, 1c, 2a, 2b, 2c, 3a etc

Posted: 31 Aug 2018, 02:09
by swagfag
i := a_index + 149

Re: Loop with increments 1a, 1b, 1c, 2a, 2b, 2c, 3a etc

Posted: 31 Aug 2018, 11:13
by cnahk
Issue solved thanks to your very helpful replies. What a great community! Thank you very much :)