|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
functions
Author: Ben Doom
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164875
Yes. Yes I did.
:-)
--Ben
Raymond Camden wrote:
----- Excess quoted text cut - see Original Post for more -----
Author: daniel kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164867
Thanks everyone for helping out. I have it pretty well now.
----- Excess quoted text cut - see Original Post for more -----
Author: Charlie Griefer
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164853
http://www.houseoffusion.com/docs/cfscript.htm
http://tutorial84.easycfm.com/
----- Excess quoted text cut - see Original Post for more -----
Author: Ian Skinner
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164850
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.
Author: Ben Doom
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164848
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 -----
Author: daniel kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164849
>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;
>}
Author: Ben Doom
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164847
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 -----
Author: daniel kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164842
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)
Author: Raymond Camden
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164843
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;
}
Author: daniel kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164840
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
Author: Bryan Stevenson
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164839
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)
>
Author: daniel kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164838
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 -----
Author: daniel kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164837
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 -----
Author: Ben Doom
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164834
> 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
Author: Ben Doom
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164835
> 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
Author: daniel kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164832
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 -----
Author: daniel kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164831
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 -----
Author: daniel kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164830
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;
>}
Author: Bryan Stevenson
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164817
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
Author: Dain Anderson
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164815
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 -----
Author: Pascal Peters
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164813
function myFunction(some_passed_var){
var pv = some_passed_var;
pv = pv+10;
return pv;
}
----- Excess quoted text cut - see Original Post for more -----
Author: Daniel Kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32850#164812
<
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
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||