Sending %A_Index% values without hard-coding them into script Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
JKnight_xbt33
Posts: 88
Joined: 18 Sep 2019, 02:06

Sending %A_Index% values without hard-coding them into script

17 Jan 2020, 09:05

Dear all,
I made a script based on this thread: https://autohotkey.com/board/topic/80517-ahk-to-read-a-text-file-copy-first-linepaste-and-loop/

The idea is to read a txt file line by line, get the ID number in each line and create a pseudo array for each line.
After that if I open a blank document and hit the hotkey it will append each ID number to the end of c:\myfile\parent\

Code: Select all

#UseHook On
 
^!u::
setkeydelay , -1

Loop, Read, C:\Users\JK\Documents\AHK scripts\id.txt 

IDArr%A_Index% := A_LoopReadLine 

return


where I am stuck


To recall the id number in a blank document, I have to type the code below into the script and adjust depending on the line number in red:
send c:\myfile\parent\%IDArr1%
send c:\myfile\parent\%IDArr2%
e.t.c.

I dont want to have to do this for 100 lines.
Is there a way to loop automatically send
c:\myfile\parent\%IDArr1%,
c:\myfile\parent\%IDArr2%,
c:\myfile\parent\%IDArr3%,
e.t.c.

while also ignoring blank/empty lines?


Cheers for the help guys
JK
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: Sending %A_Index% values without hard-coding them into script

17 Jan 2020, 09:42

I dont understand, make it clear, what format you want to paste in the new document.

Code: Select all

Line1 content ...  and c:\myfile\parent\fileID + LineNumber
Line2 content ...  and c:\myfile\parent\fileID + LineNumber
Blank line ignored
Blank line ignored
Line3 content ...  and c:\myfile\parent\fileID + LineNumber
like this ?
aifritz
Posts: 237
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: Sending %A_Index% values without hard-coding them into script  Topic is solved

17 Jan 2020, 10:22

Here 3 approaches via pseudo array

Code: Select all

;slow version
While % IDArr%A_index%
 	send % "c:\myfile\parent\" IDArr%A_index% "`n"

Code: Select all

; faster version
ClipBoard := ""
While % IDArr%A_index%{
	ClipBoard .= "c:\myfile\parent\" IDArr%A_index% "`n"
	Send ^v
}

Code: Select all

;ultra fast version
ClipBoard := ""
While % IDArr%A_index%
	ClipBoard .= "c:\myfile\parent\" IDArr%A_index% "`n"
Send ^v
JKnight_xbt33
Posts: 88
Joined: 18 Sep 2019, 02:06

Re: Sending %A_Index% values without hard-coding them into script

20 Jan 2020, 06:34

Perfect and simple just what i needed!
:bravo:
Thanks

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Clemens375, Google [Bot] and 218 guests