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

Get help with using AutoHotkey and its commands and hotkeys
TheNomadicAspie
Posts: 111
Joined: 07 Jan 2020, 15:39

Script is supposed to loop but won't

21 Nov 2020, 06:01

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
		}
	}
}
Last edited by TheNomadicAspie on 21 Nov 2020, 06:17, edited 1 time in total.
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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

21 Nov 2020, 06:17

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.
TheNomadicAspie
Posts: 111
Joined: 07 Jan 2020, 15:39

Re: Script is supposed to loop but won't

21 Nov 2020, 10:38

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!
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

Re: Script is supposed to loop but won't

21 Nov 2020, 10:44

@TheNomadicAspie

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

And you are welcome :D
TheNomadicAspie
Posts: 111
Joined: 07 Jan 2020, 15:39

Re: Script is supposed to loop but won't

24 Nov 2020, 04:01

Didn't realize that was even possible to do. Thanks, marked it solved!

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], grossermanitu, mikeyww, Peaceful, songdg and 49 guests