While loop not looping Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Scriefers
Posts: 3
Joined: 13 Mar 2017, 21:46

While loop not looping

06 Nov 2018, 02:39

I wrote a piece of code to help name a ton of picture boxes in visual studio, but I can't seem to get the while loop to work properly.
It exits the code after the first run through of the while loop and I can't figure out why.
Can anybody help?

Code: Select all

a=1
b=39
c=158
x=0

F12::
while (a < 153)
{
if (a=14) or (a=27) or (a=39) or (a=52) or (a=65) or (a=78) or (a=91) or (a=104) or (a=117) or (a=130) or (a=143) 
{
c=c+13
}
b=b+33
Click %b%, %c%
Sleep 1000
x=1
while (x < 21)
{
Click 1584, 758
Sleep 100
x=x+1
}
Click 1436, 733
Sleep 1000
Send B%a%B1
Sleep 1000
a=a+1
}
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: While loop not looping

06 Nov 2018, 07:09

Add some tabs inside of your code to make it better readable.
Also, not clear why you set x to 1 within your loop.
Is that the whole script?

You can also add a MsgBox at the end to see all the values.
MsgBox, %a%, %b%, %c%, %x%
Or just:
MsgBox, % a, b, c, x
(But I never use that style)

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: While loop not looping  Topic is solved

06 Nov 2018, 10:26

Scr1pter wrote:
06 Nov 2018, 07:09
MsgBox, % a, b, c, x
(But I never use that style)
Your expression is incorrect.
In this case, it's better to not use expression mode as you'd be left with:
msgbox % "a, b, c, x", msgbox % "a, " "b, " "c, " "x"
or something else similarly horrid. Please only respond if you feel you can provide an answer next time.
Scriefers wrote:
06 Nov 2018, 02:39
It exits the code after the first run through of the while loop and I can't figure out why.
For staters, here's a few things to look at

Code: Select all

a=1
b=39
c=158
x=0

F12::

while (a < 153)
{
	if (a=14) or (a=27) or (a=39) or (a=52) or (a=65) or (a=78) or (a=91) or (a=104) or (a=117) or (a=130) or (a=143) 
	{
		c=c+13 ; CHANGE TO EXPRESSION: c += 13 ; or c := c+13
	}

	b=b+33 ; CHANGE TO EXPRESSION
	Click %b%, %c%
	Sleep 1000
	x=1 ; BECAUSE OF THIS

	while (x < 21) ; <<< X WILL ALWAYS BE LESS THAN 21!!!
	{
		Click 1584, 758
		Sleep 100
		x=x+1 ; CHANGE TO EXPRESSION
	}

	Click 1436, 733
	Sleep 1000
	Send B%a%B1
	Sleep 1000
	a=a+1 ; CHANGE TO EXPRESSION
}

Return ; add a return so your script is persistent
I suggest reading up on expressions
Scriefers
Posts: 3
Joined: 13 Mar 2017, 21:46

Re: While loop not looping

06 Nov 2018, 18:00

TLM wrote:
06 Nov 2018, 10:26
I suggest reading up on expressions
Thanks man, it works perfectly now.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RandomBoy and 242 guests