Hi!
The script MyScript.ahk contains a function like this:
MyFunction(file, path:="", icon:="")
which can be called i.e. like this:
MyFunction("Text.txt", , "Icon.ico")
i.e. the second parameter can be left empty.
The script itself accepts parameters which will be used as parameters for MyFunction. It should be run from another script like this:
P1 := "Text.txt" , P2 := "C:\Test" , P3 := "Icon.ico"
Run, AHK.exe MyScript.ahk %P1% %P2% %P3%
But how to run MyScript with an empty second parameter P2?
How to pass an "empty parameter"?
-
- Posts: 493
- Joined: 24 Aug 2016, 03:34
How to pass an "empty parameter"?
Last edited by newbieforever on 30 Apr 2019, 14:46, edited 1 time in total.
Re: How to pass an "empty parameter"?
How about passing special character for parameter 2, like 0 (zero) and use If to handle it?
Code: Select all
p1 = %1%
p2 = %2%
p3 = %3%
MyFunction(p1, p2, p3)
Return
MyFunction(file, path:="", icon:="")
{
If (path = 0)
{
MsgBox, Blank path
path :=
}
Else MsgBox, Path is exist
}
-
- Posts: 493
- Joined: 24 Aug 2016, 03:34
Re: How to pass an "empty parameter"?
Thank you, Ridwan! I was afraid that would be the only solution. To pass an "empty parameter" is impossible, right?
Re: How to pass an "empty parameter"?
I think it's possible. I see it from some command line program like ImageMagick or FFmpeg which accept optional parameter.newbieforever wrote: ↑30 Apr 2019, 14:45Thank you, Ridwan! I was afraid that would be the only solution. To pass an "empty parameter" is impossible, right?
But some trick will needed.
Re: How to pass an "empty parameter"?
As an example:
Runner.ahk:
Script.ahk:
Store both scripts in the same folder and run Runner.ahk.
Runner.ahk:
Code: Select all
#NoEnv
File := "File"
Path := "Path"
Icon := "Icon"
Script := A_ScriptDir . "\Script.ahk"
RunWait, %A_AhkPath% "%Script%" /File="%File%" /Icon="%icon%"
ExitApp
Code: Select all
#NoEnv
; Read script parameters
Vars := {File: "", Icon: "", Path: ""}
For Each, Param In A_Args {
Part := StrSplit(LTrim(Param, "/"), "=", , 2)
If Vars.HasKey(Part[1])
Vars[Part[1]] := Part[2]
}
MsgBox, 0, Passed Variables, % "File: " . Vars["File"] . "`n"
. "Icon: " . Vars["Icon"] . "`n"
. "Path: " . Vars["Path"]
ExitApp
Store both scripts in the same folder and run Runner.ahk.
-
- Posts: 493
- Joined: 24 Aug 2016, 03:34
Re: How to pass an "empty parameter"?
Thank you, just me.