How do you know:
[1] when to enclose a variable between two %'s?
[2] when a variable should/can be used directly in a command (vs as part of an expression defining a different variable)?
I use variables quite a bit but it seems like I'm commonly not sure exactly how to insert them into a script.
For example, I've currently got a long list of phrases in a Word document and I'm trying to create a script which will assign the correct hyperlink to each phrase from a list of (previously created) bookmarks. The goal is to create a Table of Contents of sorts with each phrase linked to a specific location in the document.
The list of phrases in the document and the list of bookmarks — as it appears in the Insert Hyperlink box (Ctrl+k) — are in a matched order. In other words, after correctly assigning a particular bookmark to it's corresponding phrase, the script simply needs to select the next phrase and apply the next bookmark, then select the next phrase and apply the next bookmark, and then continue that cycle/loop.
The first part (selecting each phrase in the list in sequence) is not a problem but the second part is where I'm struggling. When I go through the process manually (once the Insert Hyperlink box is opened), any bookmark in the list can be selected by some number of {PgDn} presses combined with some number of {Down} presses.
So I understand (I think) all the needed steps but knowing how to insert the variables correctly is what's eating my lunch.
For example, suppose you got to the previous (most recent bookmark to be assigned) by opening the Insert Hyperlink box then pressing {PgDn} three times followed by {Down} five times. If those two values are represented by the variables:
pgs:=3
prev:=5
then how should they be inserted — along with the built-in variable A_Index — to obtain the desired result?
Here is the script I've written so far:
Code: Select all
F1::
; sleeps
short:= 200
medium:=600
long:=1200
; other variables
pgs := 3 ; number of times to press {PgDn}
prev := 5 ; number of times to press {Down}
rowht := 29 ; height (in pixels) of each row in the document
Loop, 10
{
CoordMode, Mouse, Screen
MouseGetPos px,py ; captures beginning mouse position
Click
Sleep, short
Send {Shift Down}
Send {End} ; selects phrase
Send {Shift Up}
Sleep, short
Send ^k ; opens Insert Hyperlink box
Sleep, medium
Send {PgDn pgs}
Sleep, medium
Send {Down (prev+A_Index)} ; supposed to define the list position of the next bookmark
Sleep, medium
Send {Enter}
MouseMove %px%,%py%
Sleep, medium
MouseMove, 0, %rowht%,, R ; moves down exactly one row for the next loop
Sleep, medium
}
Return
Code: Select all
...
Send {PgDn pgs}
Sleep, medium
var:=prev+A_Index
Send {Down var} ; supposed to define the list position of the next bookmark
Sleep, medium
Send {Enter}
...
Sleep variables
- short:= 200
medium:=600
long:=1200
- Sleep, short
Sleep, medium
- MouseGetPos px,py
- MouseMove %px%,%py%
- pgs := 3
prev := 5
rowht := 29
- Send {PgDn pgs}
Send {Down (prev+A_Index)}
MouseMove, 0, %rowht%,, R
- var:=prev+A_Index
Send {Down var}