Page 1 of 1

While loop not looping

Posted: 06 Nov 2018, 02:39
by Scriefers
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
}

Re: While loop not looping

Posted: 06 Nov 2018, 07:09
by Scr1pter
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

Re: While loop not looping  Topic is solved

Posted: 06 Nov 2018, 10:26
by TLM
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

Re: While loop not looping

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