AutoHotkey Community

It is currently May 26th, 2012, 12:16 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: September 12th, 2008, 7:27 pm 
Offline

Joined: September 9th, 2008, 9:11 am
Posts: 5
Location: Czech rep.
1) For more complex functions it would be very helpful to have optional parameters in the middle of the parameter list, not only in the end.

2) For calling functions with optional parameters it will be very helpful to have possibility to use blank parameters. This is especially confusing, because the build in AHK functions have this possibility! When I met with this blank parameter error, I thought that it is my error and a few hours I searched on the internet and in another scripts, finally I have found 2 forum topics, where another people ask about it:
http://www.autohotkey.com/forum/topic32489.html
http://www.autohotkey.com/forum/viewtopic.php?t=18517&start=0&postdays=0&postorder=asc&highlight=optional+parameters+function
There enigmatiqk did not understand the answer, that it isn't possible to have blank parameter, because he didn't believe it :shock:
Neither did I.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 12th, 2008, 8:36 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
Try this way:
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
}

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2008, 1:28 am 
Offline

Joined: January 12th, 2008, 7:45 pm
Posts: 131
That's kickass, but I don't think it works if you have expressions in the parameters...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2008, 12:28 am 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
you could use transform, deref to parse out expressions, or concatenate the expressions along the way

Code:
function("8, " somevalue + 3 ", string")

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: jyloup and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group