 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
DerRaphael
Joined: 23 Nov 2007 Posts: 604 Location: 127.0.0.1
|
Posted: Fri Sep 12, 2008 7:38 pm Post subject: Blank parameter in function call usability example |
|
|
its not perfect, but something to work with if needed
| Code: |
msgbox % function(",8")
x := 10
msgbox % function("%x%,8")
function(Parameter="a=5,b=2,c=5") {
Static DefaultVarsValues := "a=5,b=2,c=5"
Loop,Parse,DefaultVarsValues,`,
If (RegExMatch(A_LoopField,"(?P<Name>[^=]+)=(?P<Value>.+)",Def)) {
TransForm, Value, Deref, %DefValue%
Var%A_Index% := DefName, %DefName% := Value
}
Loop,Parse,Parameter,`,
if ((VarName:=Var%A_Index%)&&(StrLen(A_LoopField)!=0)) {
TransForm, Value, Deref, %A_LoopField%
%VarName% := Value
}
return a+b+c
}
|
_________________
|
|
| Back to top |
|
 |
Chronos
Joined: 12 Sep 2008 Posts: 8
|
Posted: Sat Sep 13, 2008 2:02 am Post subject: |
|
|
Thank You for sharing this script. Am I right, that it wont work with expressions? _________________
 |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Sat Sep 13, 2008 3:41 am Post subject: |
|
|
Not without a bit of un-quoting, i.e.:
| Code: | | MsgBox % Function( 6 * 9 ",8," Round(5*2.2/9)) |
_________________ PlayAHK! Try it out  |
|
| Back to top |
|
 |
Guest
|
Posted: Sat Sep 13, 2008 5:02 am Post subject: Re: Blank parameter in function call usability example |
|
|
| DerRaphael wrote: | its not perfect, but something to work with if needed
| Code: |
msgbox % function(",8")
x := 10
msgbox % function("%x%,8")
function(Parameter="a=5,b=2,c=5") {
Static DefaultVarsValues := "a=5,b=2,c=5"
Loop,Parse,DefaultVarsValues,`,
If (RegExMatch(A_LoopField,"(?P<Name>[^=]+)=(?P<Value>.+)",Def)) {
TransForm, Value, Deref, %DefValue%
Var%A_Index% := DefName, %DefName% := Value
}
Loop,Parse,Parameter,`,
if ((VarName:=Var%A_Index%)&&(StrLen(A_LoopField)!=0)) {
TransForm, Value, Deref, %A_LoopField%
%VarName% := Value
}
return a+b+c
}
|
|
No sense in parsing the default value string for each call. Addition of one line will prevent parsing of that string after the first time.  | Code: | msgbox % function(",8")
x := 10
msgbox % function("%x%,8")
function(Parameter="a=5,b=2,c=5") {
Static DefaultVarsValues := "a=5,b=2,c=5"
if !DefName ; <------ added line
Loop,Parse,DefaultVarsValues,`,
If (RegExMatch(A_LoopField,"(?P<Name>[^=]+)=(?P<Value>.+)",Def)) {
TransForm, Value, Deref, %DefValue%
Var%A_Index% := DefName, %DefName% := Value
}
Loop,Parse,Parameter,`,
if ((VarName:=Var%A_Index%)&&(StrLen(A_LoopField)!=0)) {
TransForm, Value, Deref, %A_LoopField%
%VarName% := Value
}
return a+b+c
} |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|