Iterative loop not working Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Iterative loop not working

01 Feb 2020, 11:35

Hello all,
I had a working script which I wanted to adapt. It iteratively reads each line in a txt file and runs a send command for each line.

working script

Code: Select all

Loop, Read, C:\Users\JK\18-reports PDFs\id.txt 

IDArr%A_Index%:= RegExReplace(A_LoopReadLine, "\D") 
 
While % IDArr%A_index%

send % "FileCopy, C:\Users\JK\18-reports PDFs\" IDArr%A_index%  "`n"
what i want to do
I want to adapt this code to run another code for each line in the id.txt file.
After it finishes running the script it moves to the next line in id.txt file and reruns the script for that line.


attempted code which doesn't seem to be working

Code: Select all

SetKeyDelay, -1 
SetTitleMatchMode, 2

winTitle := "Custom Filter - Occurrence List - Q-Pulse"
winTitle2 := "LaunchPad <xxx,xxx>"

winClass := "ahk_class WindowsForms10.Window.8.app.0.2eed1ca_r9_ad1"
editControl := "WindowsForms10.EDIT.app.0.2eed1ca_r9_ad"

hWnd1 := WinExist(winTitle) ; Get Custom Filter window hWnd
hWnd2 := WinExist(winTitle2) ; Get LaunchPad window hWnd

ptrS := A_PtrSize ? "Ptr" : "UInt"


Loop, Read, C:\Users\JK\18-reports PDFs\id.txt 

IDArr%A_Index%:= RegExReplace(A_LoopReadLine, "\D") 
 
While % IDArr%A_index%

WinMinimizeAll

Sleep, 800

ControlClick, % editControl "11", % "ahk_id " hWnd1
    Sleep, 100
    Send, ^{end}
    Sleep, 100
    Send, ^+{home}
    Sleep, 100
	
    Sleep, 100
    Send % "comp-"IDArr%A_index%
    Send {Enter}
    Sleep, 3000
Send % "comp-"IDArr%A_index% doesnt seem to be working. it just sends comp-IDArr0 rather than sending for example comp-2122
Tcharr
Posts: 41
Joined: 25 Jan 2020, 15:38

Re: Iterative loop not working

01 Feb 2020, 15:22

Have you tried

Code: Select all

Send % "comp-" . IDArr%A_index%
User avatar
boiler
Posts: 16949
Joined: 21 Dec 2014, 02:44

Re: Iterative loop not working  Topic is solved

01 Feb 2020, 17:04

You need { } around the block of code following your While % IDArr%A_index% statement. What you currently have is only looping on the line immediately following the While command (WinMinimizeAll). I think you mean:

Code: Select all

While % IDArr%A_index%
{
    WinMinimizeAll

    Sleep, 800

    ControlClick, % editControl "11", % "ahk_id " hWnd1
        Sleep, 100
        Send, ^{end}
        Sleep, 100
        Send, ^+{home}
        Sleep, 100
	
        Sleep, 100
        Send % "comp-" IDArr%A_index%
        Send {Enter}
        Sleep, 3000
}
Doesn't seem like you need WinMinimizeAll inside the loop, by the way. Not even sure why you are minimizing everything.
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Re: Iterative loop not working

02 Feb 2020, 07:09

Thanks @boiler I knew it had to be something simple.

Also thanks @Tcharr I used your suggestion and it sends perfectly now.

:dance:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: slowwd and 204 guests