Page 1 of 1

Script is supposed to loop but won't

Posted: 21 Nov 2020, 06:01
by TheNomadicAspie
I've run into a problem with my code that I've been unable to solve, would appreciate any advice.

The script is supposed to go to a website and perform a sequence several times as defined by RetrieveNum, then after completing that many repetitions it waits as defined by waitNum, then performs several batches of those sequences as defined by batchNum. The script gets to "MsgBox Increasing batch" and then never loops. I assumed it was an issue with the while sequence, but if so I can't figure out what it is.

Sorry that this is my third question in the last week or two. I've been getting really into learning AHK but sometimes I get stuck and figured asking would be better than spending another day or two staring at the code when I could be spending that time trying to understand what I did wrong.

Code: Select all

RepProfilesFromEntryToSpreadsheet()
{
InputBox, entryVal, entry to rep, What entry?
InputBox, repNum, Number of reps, How many entries for each batch?
InputBox, waitMin, How long to wait, How many minutes should we wait between batches?
InputBox, batchNum, How many batches, How many batches?
waitNum := waitMin*60000
batchCount = 0
currentNum = 0
websiteTagUrl = https www.website.com /  Broken Link for safety
sleep %shortSleep%
CheckCorrectProfile(correctProfile)
currentNum = 1
countTemp = 0
Send ^t
sleep %mediumSleep%
Send ^l
sleep %shortSleep%
Send %websiteTagUrl%
sleep %shortSleep%
Send %entryVal%
sleep %shortSleep%
Send {enter}
sleep %longSleep%
while (currentNum < repNum && batchCount < batchNum)
	{
	MsgBox Starting sequence
Send ^f
sleep %shortSleep%
Send rep
sleep %shortSleep%
Send {tab}
sleep %shortSleep%
Send {tab}
sleep %shortSleep%
Send {tab}
sleep %shortSleep%
Send {enter}
while (countTemp < currentNum)
		{
Send {tab}
sleep %shortSleep%
countTemp++
		}
countTemp = 0
Send {enter}
if (currentNum == 1)
		{
countTempGoal = 3
		}
else
		{
countTempGoal = 4
		}
while (countTemp < countTempGoal)
		{
Send {tab}
sleep %shortSleep%
countTemp++
		}
countTemp = 0
RightClickAndCopyUrl()
sleep %shortSleep%
sleep %shortSleep%
currentUserRaw = %clipboard%
sleep %shortSleep%
StringTrimLeft, currentUserTemp, currentUserRaw, 26
StringTrimRight, currentUser, currentUserTemp, 1
sleep %shortSleep%
Send {tab}
sleep %shortSleep%
Send {enter}
sleep %shortSleep%
Send {escape}
sleep %shortSleep%
Send {Shift Down}{Ctrl Down}{tab}{Ctrl Up}{Shift Up}
sleep %shortSleep%
Send %currentUser%
sleep %shortSleep%
Send {tab}
sleep %shortSleep%
Send reped
sleep %shortSleep%
Send {enter}
sleep %shortSleep%
Send {Ctrl Down}{tab}{Ctrl Up}
sleep %mediumSleep%	
MsgBox currentNum is %currentNum% repNum is %repNum% batchCount is %batchCount% batchNum is %batchNum%
	if (currentNum == repNum)
		{
MsgBox Increasing batch
batchCount++
currentNum = 0
sleep %waitNum%
if (batchCount == batchNum)
			{
			MsgBox Finishing
Send ^w
MsgBox Completed successfully.
return
			}
		}
	else
		{	
		MsgBox Increasing current num
		currentNum++
		return
		}
	}
}

Re: Script is supposed to loop but won't  Topic is solved

Posted: 21 Nov 2020, 06:17
by TheArkive
To check the conditions that are terminating the while loop, add this at the end of your script:

Code: Select all

Msgbox Ending Results`r`n`r`nwhile (%currentNum% < %repNum% && %batchCount% < %batchNum%)
Hopefully this will show you what is going on.

Clearly one of those while conditions is not being met. This may be a problem with the script, or the natural result of what the script does in response to what the site is doing.

Re: Script is supposed to loop but won't

Posted: 21 Nov 2020, 10:38
by TheNomadicAspie
Thank you! I was able to figure out that several starting variables needed to be 1 instead of 0, and that I was increasing currentNum in the wrong part of the script. That tip will definitely help me figure things out on my own in the future. Much appreciated!

Re: Script is supposed to loop but won't

Posted: 21 Nov 2020, 10:44
by TheArkive
@TheNomadicAspie

Please don't forget to mark this as solved (once it is solved that is).

And you are welcome :D

Re: Script is supposed to loop but won't

Posted: 24 Nov 2020, 04:01
by TheNomadicAspie
Didn't realize that was even possible to do. Thanks, marked it solved!