AutoHotkey Community

It is currently May 27th, 2012, 1:29 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: September 10th, 2010, 9:53 pm 
Offline

Joined: August 2nd, 2009, 6:40 am
Posts: 215
Character: ALT+ (NumPad) 01, used as the leading/ending char in ArgCheckDefault and Default.
Code:
+#a::
TEST_Function("", "FOO")
TEST_FUNCTION("FOO", "", "BAR", "")
TEST_FUNCTION()
return

ArgCheckDefault( byRef blankParam, var1="ArgCheckDefault", var2="ArgCheckDefault", var3="ArgCheckDefault", var4="ArgCheckDefault", var5="ArgCheckDefault" )
{
   blankParam := 0, defaultCount := 0, numParams := 0
   Loop, 5
   {
      numParams++
      tmpV := var%A_Index%
      if( tmpV == "" && ++blankParam )
         continue
      if( tmpV == "DEFAULT" && ++defaultCount )
         continue
      if( tmpV == "ArgCheckDefault" && --numParams )
         break
   }
   
return ( numParams - defaultCount )
}


TEST_Function(aVar="DEFAULT", bVar="DEFAULT", cVar="DEFAULT", dVar="DEFAULT")
{
   A_ParamCount := ArgCheckDefault( blankParam, aVar, bVar, cVar, dVar )
   MsgBox,,, % "User Provided: " A_ParamCount " args to " A_ThisFunc ", of which " blankParam " were blank (`"`")",3

   aVar := ( aVar == "" || aVar == "DEFAULT" ) ? "SomeValue" : aVar
   ; etc.
return
}


Of course, personally I wouldn't use that, nor have I come across an instance where I need to know how many args were actually passed to a function.
I do something like this:
Code:
TC_CD( src="", trg="", newTab="", srcTrg="", keepSelect="", wID="", wControl="", allowMin="" )
{   ;;
   ;; Defaults: SameTab, LeftRight
   ;;
   Global @TC@_AllowMin   ; Global default for Allow cmds to be sent to TC while Minimized.
   Global @TC@_CDSelect   ; Global TC_CD() default: Keep "CD" Selected Files.
   Global @TC@_CDNewTab   ; Global TC_CD() default: Open "CD" in a new Tab.
   Global @TC@_CDSrcTrg   ; Global TC_CD() default: Use Active Panel as "Source", instead of
   ;;                  ;                    Absolute Left/Right positioning.
   ;;
   ;;   NOTE:   All Global _defaults_ can be overridden by simply
   ;;         providing the variable in the Function parameters.
   ;;
   onErrorExit( !src && !trg, A_ThisFunc, "No Path Parameters." )

   QueryID( wID, "ahk_class TTOTAL_CMD" )
   allowMin   := ( allowMin   == "" ? ( @TC@_AllowMin ? 1 : 0 ) : allowMin   )
   keepSelect   := ( keepSelect == "" ? ( @TC@_CDSelect ? 1 : 0 ) : keepSelect )
   newTab      := ( newTab      == "" ? ( @TC@_CDNewTab ? 1 : 0 ) : newTab )
   srcTrg      := ( srcTrg      == "" ? ( @TC@_CDSrcTrg ? 1 : 0 ) : srcTrg )


Report this post
Top
 Profile  
Reply with quote  
 Post subject: WHY
PostPosted: February 24th, 2011, 6:30 am 
When would you ever need to know that?
Isn't that why params are "default"?
Why distinguish between the default value being passed explicitly and the param being omitted?

Assuming I'm overlooking omething, try a function like this:

[code]msgbox % func("pass params all in, 1, comma separated string")


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 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