|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
functions
<Daniel Kessler 05/28/04 10:58 A Thanks everyone for helping out. I have it pretty well now.daniel kessler 05/28/04 01:27 P function myFunction(some_passed_var){Pascal Peters 05/28/04 11:03 A pascal, that just looks like ECMA (JS, AS), can you elaborate?daniel kessler 05/28/04 11:52 A > pascal, that just looks like ECMA (JS, AS), can you elaborate?Ben Doom 05/28/04 12:00 P huh. so I don't have to surround it with cfscript? How is this different from CFFunction?daniel kessler 05/28/04 12:05 P huh. so I don't have to surround it with cfscript? How is this different from CFFunction, other than by structure.daniel kessler 05/28/04 12:06 P You surround the function declaration (in the script version) withBen Doom 05/28/04 12:23 P You can use CFFUNCTION in MX:Dain Anderson 05/28/04 11:04 A though it's kinda wordy, it seems to be what I want.daniel kessler 05/28/04 11:54 A > Also, why did you val the pv?Ben Doom 05/28/04 12:00 P ah locals, nice.daniel kessler 05/28/04 12:08 P There's a mediocre chapter on script in the Designing Applicaitons bookBen Doom 05/28/04 12:25 P http://www.houseoffusion.com/docs/cfscript.htmCharlie Griefer 05/28/04 12:32 P Um... no. Val() is a CF function. I think you mean var. And it must be atRaymond Camden 05/28/04 12:17 P >Um... no. Val() is a CF function. I think you mean var. And it must be atdaniel kessler 05/28/04 12:25 P Yes. Yes I did.Ben Doom 05/28/04 01:55 P Your Options:Bryan Stevenson 05/28/04 11:05 A which one would be the one Dain displayed?daniel kessler 05/28/04 11:57 A Dain's example was a function and could either be in a CFC or a UDFBryan Stevenson 05/28/04 12:07 P ok I see, thanks.daniel kessler 05/28/04 12:17 P < I have a set of code in CF that I use four times in a script. It could easily be a function with an in/out but I've yet to see functions in CF, mostly scripts. I don't want to do anything special by making it external or making it nice enough to give to others. I just want a callable/reusable function: function myFunction(some_passed_var){ <cfset pv = some_passed_var> <cfset pv = pv+10> return pv } Is there something similar in CF? > -- Daniel Kessler Department of Public and Community Health University of Maryland Suite 2387 Valley Drive College Park, MD 20742-2611 301-405-2545 Phone www.phi.umd.edu Thanks everyone for helping out. I have it pretty well now. ----- Excess quoted text cut - see Original Post for more ----- function myFunction(some_passed_var){ var pv = some_passed_var; pv = pv+10; return pv; } ----- Excess quoted text cut - see Original Post for more ----- pascal, that just looks like ECMA (JS, AS), can you elaborate? do I just put that at the top and call it from cfset? do I precede it with anything? >function myFunction(some_passed_var){ > var pv = some_passed_var; > pv = pv+10; > return pv; >} > pascal, that just looks like ECMA (JS, AS), can you elaborate? > do I just put that at the top and call it from cfset? > do I precede it with anything? It's very much like an ECMA language. The biggest difference (off the top of my head) is that you use CF comparison operators instead of ECMA ones. That is you use "is" or "eq" instead of "==" and so forth. You can call it from a CFSET if you want the results to be put in a variable: <cfset value = function_name(arguments)> If you just want them displayed, you can do something like <cfoutput> #function_name(arguments)# </cfoutput> --Ben Doom huh. so I don't have to surround it with cfscript? How is this different from CFFunction? ----- Excess quoted text cut - see Original Post for more ----- huh. so I don't have to surround it with cfscript? How is this different from CFFunction, other than by structure. ----- Excess quoted text cut - see Original Post for more ----- You surround the function declaration (in the script version) with cfscript tags. The call doesn't have to be in a cfscript block. There are small differences in loops in the script version vs the tag version, but (afaik) that's all. --Ben Doom daniel kessler wrote: ----- Excess quoted text cut - see Original Post for more ----- You can use CFFUNCTION in MX: <CFFUNCTION NAME="myFunction" RETURNTYPE="numeric"> <CFARGUMENT NAME="some_passed_var" TYPE="numeric"> <CFSET pv = Arguments.some_passed_var> <CFSET pv = Val(pv + 10)> <CFRETURN pv> </CFFUNCTION> -Dain Daniel Kessler wrote: ----- Excess quoted text cut - see Original Post for more ----- though it's kinda wordy, it seems to be what I want. so in cfset, I do: <cfset myVar = myFunction(passy_varry)> ? Also, why did you val the pv? thanks for replyin. ----- Excess quoted text cut - see Original Post for more ----- > Also, why did you val the pv? If you use "val" to declare a variable, it is local to the function. this is a good idea, since otherwise you might accidentally overwrite something in the variable scope. --Ben Doom ah locals, nice. That's a boon. Sure would've been nice to have a course in all this instead of ad-hoc and relying on my historical knowledge ("who's buried in grant's tomb" and the like :). >If you use "val" to declare a variable, it is local to the function. >this is a good idea, since otherwise you might accidentally overwrite >something in the variable scope. > >--Ben Doom There's a mediocre chapter on script in the Designing Applicaitons book and section in the livedocs. I vaguely recall Michael Dinowitz putting up a tutorial on it for CF5, but vague memories are often wrong. :-) I also seem to recall tutorials on CFLIB.org, and there are plenty of samples to learn from on there. --Ben Doom daniel kessler wrote: ----- Excess quoted text cut - see Original Post for more ----- http://www.houseoffusion.com/docs/cfscript.htm http://tutorial84.easycfm.com/ ----- Excess quoted text cut - see Original Post for more ----- Um... no. Val() is a CF function. I think you mean var. And it must be at the beginning of a UDF. Ie function foo(x,y) { var z = 1; z = x*y+9; return z; } >Um... no. Val() is a CF function. I think you mean var. And it must be at >the beginning of a UDF. Ie thanks. yeah it complains about that and missing semi-colons. I guess I'm kinda used to flash and being lazy on all that. This is pretty cool and it makes me very happy that I can use functions. > >function foo(x,y) { > var z = 1; > z = x*y+9; > return z; >} Yes. Yes I did. :-) --Ben Raymond Camden wrote: ----- Excess quoted text cut - see Original Post for more ----- Your Options: -make a custom tag -make a UDF (user defined function) - see www.cflib.org for info -if on CF MX make a function in a CFC (ColdFusion Component) -go dead simple and make the script an included file and include it whereever you need it (set your "in" var(s) before including the file and the "out" gets set in the included file) HTH Cheers Bryan Stevenson B.Comm. VP & Director of E-Commerce Development Electric Edge Systems Group Inc. t. 250.920.8830 e. bryan@electricedgesystems.com --------------------------------------------------------- Macromedia Associate Partner www.macromedia.com --------------------------------------------------------- Vancouver Island ColdFusion Users Group Founder & Director www.cfug-vancouverisland.com < I have a set of code in CF that I use four times in a script. It could easily be a function with an in/out but I've yet to see functions in CF, mostly scripts. I don't want to do anything special by making it external or making it nice enough to give to others. I just want a callable/reusable function: function myFunction(some_passed_var){ <cfset pv = some_passed_var> <cfset pv = pv+10> return pv } Is there something similar in CF? > -- Daniel Kessler Department of Public and Community Health University of Maryland Suite 2387 Valley Drive College Park, MD 20742-2611 301-405-2545 Phone www.phi.umd.edu which one would be the one Dain displayed? I'm hoping to not make a component since it's really just specific to this page. I'm just used to fuctioning duplicate programming. ----- Excess quoted text cut - see Original Post for more ----- Dain's example was a function and could either be in a CFC or a UDF Bryan Stevenson B.Comm. VP & Director of E-Commerce Development Electric Edge Systems Group Inc. t. 250.920.8830 e. bryan@electricedgesystems.com --------------------------------------------------------- Macromedia Associate Partner www.macromedia.com --------------------------------------------------------- Vancouver Island ColdFusion Users Group Founder & Director www.cfug-vancouverisland.com which one would be the one Dain displayed? I'm hoping to not make a component since it's really just specific to this page. I'm just used to fuctioning duplicate programming. > Your Options: > -make a custom tag > -make a UDF (user defined function) - see www.cflib.org for info > -if on CF MX make a function in a CFC (ColdFusion Component) > -go dead simple and make the script an included file and include it > whereever you need it (set your "in" var(s) before including the file > and the "out" gets set in the included file) > ok I see, thanks. ----- Excess quoted text cut - see Original Post for more ----- > To: CF-Talk > Sent: Friday, May 28, 2004 8:57 AM > Subject: Re: functions > > > which one would be the one Dain displayed? > I'm hoping to not make a component since it's really just specific to > this page. I'm just used to fuctioning duplicate programming. > > > Your Options: > > -make a custom tag > > -make a UDF (user defined function) - see www.cflib.org for info > > -if on CF MX make a function in a CFC (ColdFusion Component) > > -go dead simple and make the script an included file and include it > > > whereever you need it (set your "in" var(s) before including the > file > > and the "out" gets set in the included file) Yes, the val() used in the function is there because CF is type less. Thus your function could receive a string just has happily has an integer or a float as a parameter. The val() function prevents the math from blowing up if it receives a string instead of a numeric value. It would cause all non-numeric values to become 0. Confidentiality Notice: This message including any attachments is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender and delete any copies of this message.
|
March 14, 2010
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||