0
votes

My loop in my autohotkey script is only running through once. Can anyone tell me why? Thanks

Loop, 8 
{
  WinActivate, NDTr
  ControlClick, Button3 ;Select Batch, enter info, start collecting data
  WinWait, Batch Readings
  ControlClick, Edit1
  Send {BS}+{BS}+{BS}+{BS}+{BS}+{BS}
  Send 1
  ControlClick, Edit2
  Send {BS}+{BS}+{BS}+{BS}+{BS}+{BS}
  Send 15

  if A_Index = 4
  {
    Sleep, 20000
  }
  else if A_Index = 7
  {
    Sleep, 20000
  }
  else if A_Index = 1
  {
    Sleep, 3000
  }
  else 
  {
    Sleep, 15000
  }

  ControlClick, Button1
  Sleep, 15000
}
2
is it possible you're just not waiting long enough? those Sleep values seem kinda long... Alternatively, is your WinWait working correctly on the second run through the loop? Is another window stealing the focus, so that your other commands are sent to the wrong place?andrewdotnich

2 Answers

1
votes

WinWait looks like a likely culprit like anthv123 said. Double check your window's title and make sure it fits the TitleMatchMode that you're expecting.

Common debugging practices include adding different ToolTips in places along the problem code. For example tooltips above and below the WinWait line with texts "before" and "after" would tell you if it's pausing indefinitely at that part (if it never says "after").

Sleeping for 3-20 seconds isn't going to help your patience either.

1
votes

Try using this to diagnose the issue. If "Batch Readings" takes longer than 5 seconds, you get an error letting you know and the loop continues

WinWait, Batch Readings,,5
if (errorLevel = 1)
   Msgbox % "Batch Readings timed out"