Basicamente, os comandos, como run, %something%
, são diferentes das funções, como myFunction(something)
. Aqui está outro exemplo baseado na resposta de qwertzguy
#t::
; get variable from message box
inputbox myVar, What is your variable?
; myVar DOES NOT have percents when passed to function
myNewVar := TestFunction(myVar)
; myNewVar DOES have percents when passed to command
MsgBox %myNewVar%
return
TestFunction(arg)
{
; command DOES have percents
MsgBox Launching: %arg%
if (arg = "calc")
{
; commands use traditional variable method
; traditional method example: Var = The color is %FoundColor%
; variables are evaluated inside quotes
run, "%A_WinDir%\system32\calc.exe"
}
else if (arg = "word")
{
; functions need to use expression version since percents are not evaluated
; expression method example: Var := "The color is " . FoundColor
; variables are not evaluated inside quotes
EnvGet, ProgramFilesVar, ProgramFiles(x86)
OfficeVersionVar := "15"
RunFunction(ProgramFilesVar . "\Microsoft Office\Office" . OfficeVersionVar . "\WINWORD.EXE")
}
return "You typed: " . arg
}
RunFunction(arg)
{
run, %arg%
}