Yes attributes can be optional
You'll want to only list the attributes that are required function
defintion. But when you call the function you can use the arguments
array to reference anything that you pass to the function.
<cfscript>
Function fnMyTest(req1,req2)
{
var optionlVar = arguments[3]
// the problem here is that I don't remember/know if you need
some scope for the argument array - CFDJ had an article on it back when
CF5 was coming out I can only assume forta.com has info on it too.
}
// use the function
fnMyTest(FORM.req1,FORM.req2,FORM.opt1); // will process it
</cfscript>
HTH,
t
**********************************************************************
Tyler M. Fitch
Certified Advanced ColdFusion 5 Developer
http://isitedesign.com
**********************************************************************
-----Original Message-----
From: Tyler Silcox [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 25, 2002 3:24 PM
To: CF-Talk
Subject: optional UDF parameters???
Is it possible to make a parameter optional in UDFs, just like some of
CF's built in functions? Here's what I got's:
<cfscript>
/* i might only want to pass the 1st parameter and i have no need to
pass the 2nd parameter everytime so i'd like to leave it off and not
code in an empty ("") everytime */
function myFunction(Parameter1,Parameter2){
someVariable="";
etc...
}
</cfscript>
If I leave the function like above and then only pass one argument:
#myFunction("Bah")# , I get the following error:
The number of arguments passed to a user-defined function cannot be less
than the number of parameters in its definition. This call to myFunction
passes 1 arguments, but 2 parameters are defined.
I know CF can do it, but can I?
Tyler Silcox
email | [EMAIL PROTECTED]
______________________________________________________________________
Why Share?
Dedicated Win 2000 Server � PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
Instant Activation � $99/Month � Free Setup
http://www.pennyhost.com/redirect.cfm?adcode=coldfusionc
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists