Save multiple separate values for pasting later in the script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WeThotUWasAToad
Posts: 312
Joined: 19 Nov 2013, 08:44

Save multiple separate values for pasting later in the script

20 Jul 2020, 14:15

Hello,

When running a script, is there a way to have ahk save multiple separate values then paste those same values later when the script calls for them?

For example, suppose you have a website which stores membership records and each record includes four fields:
  • First Name
  • Last Name
  • DOB
  • Phone Number
And suppose you have a spreadsheet in which the first four columns contain the corresponding information for several hundred members.

Is there a way, using ahk, to do essentially what is shown in the following script (assuming you have already selected the first cell [Col A, First Name] in Excel for a given member) and, in Chrome, you have the cursor placed in the first field (ie First Name)?

Code: Select all

F1::
SetTitleMatchMode, 2
Loop, 10
{
WinActivate, Excel

Send ^c			; copy Col A value and save as m1
Send {Tab}
Send ^c			; copy Col B value and save as m2
Send {Tab}
Send ^c			; copy Col C value and save as m3
Send {Tab}
Send ^c			; copy Col D value and save as m4
Send {Tab}

Send {Down}
Send {Home}		; ready for next row

WinActivate, Chrome

Send [saved value m1]
Send {Tab}
Send [saved value m2]
Send {Tab}
Send [saved value m3]
Send {Tab}
Send [saved value m4]
Send {Tab}

Send {Enter}		; saves info and opens new record form
}

Return
I realize this can be done one cell/field at-a-time by using Send ^c & Send ^v and bouncing back and forth between Excel and Chrome. However, it would be much easier and take less time if the four values in Excel for a given row could be saved one after another and then, after activating Chrome, entered into the corresponding four fields (ie one bounce is better than four).

Thanks
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT

"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
braunbaer
Posts: 483
Joined: 22 Feb 2016, 10:49

Re: Save multiple separate values for pasting later in the script

20 Jul 2020, 15:32

I would export the excel file into a csv file that you can easily read in your ahk script using loop read.

In every loop step, you scan the content of one csv-line and input the field contents into the web page.
WeThotUWasAToad
Posts: 312
Joined: 19 Nov 2013, 08:44

Re: Save multiple separate values for pasting later in the script

20 Jul 2020, 17:06

Thanks for the great information braunbaer. I love getting solutions which cause me to learn an AHK function I've never used before.

I found an example in the docs which combines Loop, read, . . . with Loop, parse, . . . to get one value at a time:

Code: Select all

F1::
Loop, read, C:\Database Export.txt
{
    Loop, parse, A_LoopReadLine, %A_Tab%
    {
        MsgBox, Field number %A_Index% is %A_LoopField%.
    }
}
Return
However, is there any way to specify a particular line and value or do you just get the next one in the queue?

In other words, suppose you have a loop to run 50 records (rows) and something goes wrong causing the looped script to have to be stopped.

Is there a way to pick up where you left off or do you have to delete the rows already entered, resave the file, and begin again?

Also, can you tell me the difference the percent signs make when using them with built-in variables?

For example, I've used A_Index many times in the past in looped scripts. However, what change occurs when you instead use %A_Index%?

Thanks
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT

"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
braunbaer
Posts: 483
Joined: 22 Feb 2016, 10:49

Re: Save multiple separate values for pasting later in the script

21 Jul 2020, 16:00

Is there a way to pick up where you left off or do you have to delete the rows already entered, resave the file, and begin again?
There are different ways to handle this problem. For example, at the start of the script, you can ask for the number of records to skip

Code: Select all

F1::
InputBox, skiplines , Skip, Lines to skip:,,,,,,,,0
Loop, read, C:\Database Export.txt
{
    if (A_Index>skiplines)
    Loop, parse, A_LoopReadLine, %A_Tab%
    {
        MsgBox, Field number %A_Index% is %A_LoopField%.
    }
}
Return
Also, can you tell me the difference the percent signs make when using them with built-in variables?
As a general rule, you need to enclose a variablre name in percent signs in all commands while percent signs must not be used when the variable is part of an expression. For example
loop %count%
but
x:=count

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ntepa and 110 guests