AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Blank parameter in function call usability example

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
DerRaphael



Joined: 23 Nov 2007
Posts: 604
Location: 127.0.0.1

PostPosted: Fri Sep 12, 2008 7:38 pm    Post subject: Blank parameter in function call usability example Reply with quote

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
View user's profile Send private message
Chronos



Joined: 12 Sep 2008
Posts: 8

PostPosted: Sat Sep 13, 2008 2:02 am    Post subject: Reply with quote

Thank You for sharing this script. Am I right, that it wont work with expressions?
_________________
Back to top
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Sat Sep 13, 2008 3:41 am    Post subject: Reply with quote

Not without a bit of un-quoting, i.e.:

Code:
MsgBox % Function( 6 * 9 ",8," Round(5*2.2/9))

_________________
PlayAHK! Try it out Very Happy
Back to top
View user's profile Send private message AIM Address
Guest






PostPosted: Sat Sep 13, 2008 5:02 am    Post subject: Re: Blank parameter in function call usability example Reply with quote

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. Smile
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
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group