School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,388 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,561 people online right now. Registration is fast and FREE... Join Now!




Using CFReturn

 

Using CFReturn

xheartonfire43x

3 Apr, 2009 - 05:27 AM
Post #1

D.I.C Regular
***

Joined: 22 Dec, 2008
Posts: 260



Thanked: 2 times
My Contributions
I am trying to call a returned variable from a function but I am new to usin CFC's so I don't know how to.

weekview.cfm
CODE

<!---Set the parameters for the current year, month, and time--->
<cfparam name="currentyear" default="#year(now())#">
<cfparam name="currentmonth" default="#month(now())#">
<cfparam name="currentday" default="#day(now())#">
<cfparam name="currenttime" default="#timeformat(now(),'HH:mm')#">
<cfset currentdate = dateformat(createdate(currentyear,currentmonth,currentday))>

<cfinvoke component="week" method="weekstartat">
    <cfinvokeargument name="date" value="#currentdate#">
</cfinvoke>

<table cellpadding="0" cellspacing="0" width="100%">
    <tr><th colspan="7"><cfoutput>#dateformat(createdate(currentyear,currentmonth,currentday),"mmmm d, yyyy")#</cfoutput></th></tr>
    <tr valign="top">
        <cfloop from="1" to="7" index="i">
                <th valign="top"><cfoutput>#dayofweekasstring(i)#</cfoutput></th>
        </cfloop>
    </tr>
    <tr>
        <cfloop from="1" to="7" index="i">
            <td height="50" align="center">All Day Appointments</td>
        </cfloop>
    </tr>
    <tr>
        <td><cfoutput>#weekstartat#</cfoutput></td>
    </tr>
</table>


week.cfc
CODE

<cfcomponent>
<!---WeekStartAt Function--->
<cffunction name="weekstartat" access="public" hint="Function to get the date of the first day of the week.  Pass any date in the argument.">
    <cfargument name="date" default="#now()#">
    
    <cfset weekday = dayofweek(date)>
    <cfset subtract = weekday - 1>
    
    <cfset weekstartat = dateadd("d",- subtract,date)>
        
    <cfdump var="#weekstartat#">
    <cfreturn weekstartat />
</cffunction>
</cfcomponent>

I am new to using CFC's so I am doing something wrong.

This post has been edited by xheartonfire43x: 3 Apr, 2009 - 06:46 AM

User is offlineProfile CardPM
+Quote Post


sansclue

RE: Using CFReturn

3 Apr, 2009 - 08:21 AM
Post #2

D.I.C Regular
***

Joined: 21 Nov, 2007
Posts: 316



Thanked: 28 times
My Contributions
Use the "returnVariable" attribute to capture the value.

CODE

<cfinvoke component="week" method="weekstartat" returnVariable="yourVariableName">
    <cfinvokeargument name="date" value="#currentdate#">
</cfinvoke>


It is also a good idea to get into the habit of VAR scoping all function local variables. Otherwise, you will run into threading problems if you store the component in a shared scope.

CODE

<cffunction name="weekstartat" access="public" hint="Function to get the date of the first day of the week.  Pass any date in the argument.">
    <cfargument name="date" default="#now()#">
    <!--- VAR scope variables. All VAR statements must be at the top of the function --->
    <cfset var weekday = dayofweek(date)>
    <cfset var subtract = weekday - 1>
    <cfset var weekstartat = dateadd("d",- subtract,date)>
      
    <cfreturn weekstartat />
</cffunction>
</cfcomponent>



User is offlineProfile CardPM
+Quote Post

xheartonfire43x

RE: Using CFReturn

5 Apr, 2009 - 05:11 PM
Post #3

D.I.C Regular
***

Joined: 22 Dec, 2008
Posts: 260



Thanked: 2 times
My Contributions
QUOTE(sansclue @ 3 Apr, 2009 - 08:21 AM) *

Use the "returnVariable" attribute to capture the value.

It is also a good idea to get into the habit of VAR scoping all function local variables. Otherwise, you will run into threading problems if you store the component in a shared scope.


Thanks. Like I said I am just starting with CFC's. I apprenticed under someone who works with ColdFusion 5 so I have been building on what I have learned from him really. Is there any good sites that you know of to learn building and using CFC's?
User is offlineProfile CardPM
+Quote Post

apendrag0n3

RE: Using CFReturn

4 May, 2009 - 10:16 AM
Post #4

New D.I.C Head
*

Joined: 3 May, 2009
Posts: 6



Thanked: 1 times
My Contributions
Go to: http://www.coldfusionjedi.com/index.cfm

and do a search on CFC

Lots of good info there

QUOTE(xheartonfire43x @ 5 Apr, 2009 - 05:11 PM) *

QUOTE(sansclue @ 3 Apr, 2009 - 08:21 AM) *

Use the "returnVariable" attribute to capture the value.

It is also a good idea to get into the habit of VAR scoping all function local variables. Otherwise, you will run into threading problems if you store the component in a shared scope.


Thanks. Like I said I am just starting with CFC's. I apprenticed under someone who works with ColdFusion 5 so I have been building on what I have learned from him really. Is there any good sites that you know of to learn building and using CFC's?


User is offlineProfile CardPM
+Quote Post

ComboAlex

RE: Using CFReturn

6 Aug, 2009 - 11:41 AM
Post #5

New D.I.C Head
*

Joined: 31 Jul, 2009
Posts: 25


My Contributions
I also have a small problem with the <cfreturn> tag. Here is my post. I would be very grateful if someone could help me.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 09:39PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month