I feel like i just cant figure out the right words to search for this.
But basically i want to figure out how to select a big chunk of my script and call it like a shortcut name so the rest of the script can just refer to that section?
Let me know if i need to clarify anymore
Condense a part of a script to be referred to later as a shortcut?
Re: Condense a part of a script to be referred to later as a shortcut?
Are you referring to a Label?
Or Function?
Code: Select all
#SingleInstance, Force
NumCount := 0
Loop, 10 {
GoSub, Label1
NumCount++
}
Label1:
MsgBox, % NumCount
return
Code: Select all
#SingleInstance, Force
NumCount := 0
Loop, 10 {
Function1(5)
}
Function1(Num) {
Global NumCount
NumCount := NumCount + Num
MsgBox, % NumCount
}
Re: Condense a part of a script to be referred to later as a shortcut?
I mean something like the below, needing to be written out once in a script, but i could target this section again later on without having to copy it lower creating a ridiculously long script. Its a lot longer but basically how the same step is at the top and bottom of what ive posted, is there a way to call the first chunk something and just use that name in place of the same chunk again at the bottom?
F10::
Loop,
{
Suspend
;Copy ID from Excel
WinActivate, Script Data.xlsx - Excel
Sleep 1000
Send, {Down}
Sleep 500
Clipboard := ""
Send, ^c
ClipWait
if (Clipboard = "`r`n")
break
Sleep 2000
WinActivate, Google Chrome
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Status
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, {Up 2}
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Search by:
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, ^v
Sleep 3000
Send, {Tab 4}
Sleep 2000
Send, {Enter}
Sleep 3000
Send, ^f
Sleep 1500
SendRaw, Manage
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Enter}
Sleep 5000
;Copy Number from Excel
WinActivate, Script Data.xlsx - Excel
Sleep 1000
Send, {Right}
Clipboard := ""
send, ^c
ClipWait
if (Clipboard = "`r`n")
break
Sleep 1000
F10::
Loop,
{
Suspend
;Copy ID from Excel
WinActivate, Script Data.xlsx - Excel
Sleep 1000
Send, {Down}
Sleep 500
Clipboard := ""
Send, ^c
ClipWait
if (Clipboard = "`r`n")
break
Sleep 2000
WinActivate, Google Chrome
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Status
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, {Up 2}
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Search by:
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, ^v
Sleep 3000
Send, {Tab 4}
Sleep 2000
Send, {Enter}
Sleep 3000
Send, ^f
Sleep 1500
SendRaw, Manage
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Enter}
Sleep 5000
;Copy Number from Excel
WinActivate, Script Data.xlsx - Excel
Sleep 1000
Send, {Right}
Clipboard := ""
send, ^c
ClipWait
if (Clipboard = "`r`n")
break
Sleep 1000
Re: Condense a part of a script to be referred to later as a shortcut?
Code: Select all
#SingleInstance, Force
F10::
Loop {
Suspend
GoSub, Chunk1
Sleep 2000
WinActivate, Google Chrome
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Status
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, {Up 2}
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Search by:
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, ^v
Sleep 3000
Send, {Tab 4}
Sleep 2000
Send, {Enter}
Sleep 3000
Send, ^f
Sleep 1500
SendRaw, Manage
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Enter}
Sleep 5000
GoSub, Chunk1
Sleep 1000
}
return
Chunk1:
;Copy ID from Excel
WinActivate, Script Data.xlsx - Excel
Sleep 1000
Send, {Down}
Sleep 500
Clipboard := ""
Send, ^c
ClipWait
if (Clipboard = "`r`n")
break
return
Re: Condense a part of a script to be referred to later as a shortcut?
I think you are just trying to make a simple function https://autohotkey.com/docs/Functions.htm. Try this:
or you can take the whole chunk to a function like this:
Also, I would highly recommend using COM to automate Excel as opposed to sending keystrokes, it is much faster and more reliable and can run in the background invisibly if needed. I started out trying to automate excel in the way you are doing (and I think a lot of people do) and it was very unreliable and required a lot Sleep and Send commands that aren't very reliable. PM me and I'd be happy to give you more info on automating Excel via COM. You can also do this to automate web scraping, there are tons of tutorials on it, but I'm not that experienced with it yet so you'll have to put in the work yourself
Code: Select all
F10::
Loop,
{
Suspend
CopyIDfromExcel()
WinActivate, Google Chrome
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Status
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, {Up 2}
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Search by:
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, ^v
Sleep 3000
Send, {Tab 4}
Sleep 2000
Send, {Enter}
Sleep 3000
Send, ^f
Sleep 1500
SendRaw, Manage
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Enter}
Sleep 5000
CopyIDfromExcel()
}
; Function (I usually put my custom functions at the bottom of my scripts):
CopyIDfromExcel() {
WinActivate, Script Data.xlsx - Excel
Sleep 1000
Send, {Right}
Clipboard := ""
send, ^c
ClipWait
if (Clipboard = "`r`n")
break
Sleep 1000
}
Code: Select all
F10::
Loop,
{
Suspend
CopyIDEntireProcess()
}
; Function
CopyIDEntireProcess() {
WinActivate, Script Data.xlsx - Excel
Sleep 1000
Send, {Down}
Sleep 500
Clipboard := ""
Send, ^c
ClipWait
if (Clipboard = "`r`n")
break
Sleep 2000
WinActivate, Google Chrome
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Status
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, {Up 2}
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Search by:
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, ^v
Sleep 3000
Send, {Tab 4}
Sleep 2000
Send, {Enter}
Sleep 3000
Send, ^f
Sleep 1500
SendRaw, Manage
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Enter}
Sleep 5000
WinActivate, Script Data.xlsx - Excel
Sleep 1000
Send, {Right}
Clipboard := ""
send, ^c
ClipWait
if (Clipboard = "`r`n")
break
Sleep 1000
}
-TL
Who is online
Users browsing this forum: No registered users and 286 guests