Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFSCRIPT and Function Argument Default Value 1

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,

In CF MX using CFSCRIPT with a function, how can I set the default value of an argument?

In the script form you would use: <cfargument name="parameterName" type="dataType"
required="true/false" default="defaultValue">


Here is my test function:
Code:
function msg(message,title) {
   ...
   return writeOutput( "<br>" & title & "<br>" & message);
}



Thanks,

Michael42
 
There's an array called "Arguments" available to your functions...

The way it works is that you have to provide all parameters that you list in your function declaration

Code:
function ExampleHere(Provide,These)

Any that aren't in your function declaration are optional, and those are what you access by Arguments[]..

If your function call looks like ExampleHere(Val1,Val2) then you only provide required arguments... If your call looks like ExampleHere(Val,OtherVal,NewVal) then you've provided an optional argument (NewVal) which you would access by Arguments[3]..

Of course, optional arguments should be the last ones of course.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
webmigit,

Thanks!

With all the CF docs around I still had a problem clarifying how this worked for CFSCRIPT functions. :)

-Michael42
 
I'd read about it but I'd never needed an optional argument so its something I stored away for later but when you asked I couldn't find a tutorial that I thought explained it well enough (or even at all).

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top