House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

functions

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
<
Daniel Kessler
05/28/04 10:58 A
function myFunction(some_passed_var){
Pascal Peters
05/28/04 11:03 A
You can use CFFUNCTION in MX:
Dain Anderson
05/28/04 11:04 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
http://www.houseoffusion.com/docs/cfscript.htm
Charlie Griefer
05/28/04 12:32 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
ok I see, thanks.
daniel kessler
05/28/04 12:17 P
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Daniel Kessler
05/28/2004 10:58 AM

< 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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
daniel kessler
05/28/2004 01:27 PM

Thanks everyone for helping out.  I have it pretty well now. ----- Excess quoted text cut - see Original Post for more -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Pascal Peters
05/28/2004 11:03 AM

function myFunction(some_passed_var){   var pv = some_passed_var;   pv = pv+10;   return pv; } ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
daniel kessler
05/28/2004 11:52 AM

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; >}

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Doom
05/28/2004 12:00 PM

> 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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
daniel kessler
05/28/2004 12:05 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
daniel kessler
05/28/2004 12:06 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Doom
05/28/2004 12:23 PM

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 -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dain Anderson
05/28/2004 11:04 AM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
daniel kessler
05/28/2004 11:54 AM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Doom
05/28/2004 12:00 PM

> 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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
daniel kessler
05/28/2004 12:08 PM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Doom
05/28/2004 12:25 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Raymond Camden
05/28/2004 12:17 PM

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; }

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
daniel kessler
05/28/2004 12:25 PM

>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; >}

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Doom
05/28/2004 01:55 PM

Yes.  Yes I did. :-) --Ben Raymond Camden wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bryan Stevenson
05/28/2004 11:05 AM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
daniel kessler
05/28/2004 11:57 AM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bryan Stevenson
05/28/2004 12:07 PM

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)   >

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
daniel kessler
05/28/2004 12:17 PM

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)

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ian Skinner
05/28/2004 12:26 PM

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.


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

March 14, 2010

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
   1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31