Ask a Question related to Macromedia ColdFusion, Design and Development.
-
capik79 #1
to read multiple cfreturn
Hi All,
I'm just exploring the CF component function. I've face oe problem which is to
read more than1 cfreturn. Here the code and file name :
File name : currency.cfc
<!--- File name Currency.cfc --->
<!--- componet file to change currency --->
<cfcomponent name="currency_converter">
<cffunction name="curr_converter" access="remote" returntype="any">
<cfargument name="country">
<cfargument name="myr">
<cfquery name ="get_val" datasource="ScratchDB">
Select curr from currency
Where Currency_type = '#arguments.country#'
</cfquery>
<cfset curr_val = #arguments.myr#*#get_val.curr#>
<cfset country_curr =#get_val.curr#>
<cfreturn curr_val>
<cfreturn country_curr>
</cffunction>
</cfcomponent>
CF file : currency_converter.cfm
<cfoutput>
<cfset curr_req = #form.val#>
<cfset curr_country =#form.country#>
<cfinvoke component="currency" method="curr_converter"
returnVariable="final_val">
<cfinvokeargument name="country" value="#curr_country#">
<cfinvokeargument name="myr" value="#curr_req#">
</cfinvoke>
<cfinvoke component="currency" method="return_currency"
returnvariable="cntry_val">
</cfinvoke>
<br>
<br>Original Currency : #curr_country#
<br>Original Value : #curr_req#
<br>RM 1 = #cntry_val# <!--- this value wil return from cfc file, cfreturn
country_curr --->
<br>Malaysia Value : RM #final_val#
<br>
</cfoutput>
now my program only read <cfreturn curr_val>, not <cfreturn country_curr>.
So is it possible to return more than 1 data in one function?
thanks in advance
Shaffiq
CF Developers
capik79 Guest
-
Having trouble with cfreturn to a <mx:Text> field
I have done a return to populate a DataGrid, but I need to populate a text field. My code is as follows in my CFC where I first check a previous... -
tracing output of cfreturn var in flash
Im trying to pass data from a cf component to my flash file and trace it, but it keeps coming up undefined. Cold Fusion Script: <cfcomponent>... -
Action Script to read multiple datasets in XML doc forFlash Bar Chart
I am trying to compare groups of items using an XML source and need assistance in creating the Action Script to properly read multiple datasets... -
File system get auto change from read-write to read-oly
I have a very strange file system with OS Redhat 7.2 The file system is read-write, but some how it randomly changes to read-only at any time.... -
multiple threads read() problems
Hello, I have a multi-threaded echo server designed like so: - there's a main threads and some number of worker threads (threadpool) - main... -
capik79 #2
to read multiple cfreturn
Hi All,
I'm just exploring the CF component function. I've face oe problem which is to
read more than1 cfreturn. Here the code and file name :
File name : currency.cfc
<!--- File name Currency.cfc --->
<!--- componet file to change currency --->
<cfcomponent name="currency_converter">
<cffunction name="curr_converter" access="remote" returntype="any">
<cfargument name="country">
<cfargument name="myr">
<cfquery name ="get_val" datasource="ScratchDB">
Select curr from currency
Where Currency_type = '#arguments.country#'
</cfquery>
<cfset curr_val = #arguments.myr#*#get_val.curr#>
<cfset country_curr =#get_val.curr#>
<cfreturn curr_val>
<cfreturn country_curr>
</cffunction>
</cfcomponent>
CF file : currency_converter.cfm
<cfoutput>
<cfset curr_req = #form.val#>
<cfset curr_country =#form.country#>
<cfinvoke component="currency" method="curr_converter"
returnVariable="final_val">
<cfinvokeargument name="country" value="#curr_country#">
<cfinvokeargument name="myr" value="#curr_req#">
</cfinvoke>
<cfinvoke component="currency" method="return_currency"
returnvariable="cntry_val">
</cfinvoke>
<br>
<br>Original Currency : #curr_country#
<br>Original Value : #curr_req#
<br>RM 1 = #cntry_val# <!--- this value wil return from cfc file, cfreturn
country_curr --->
<br>Malaysia Value : RM #final_val#
<br>
</cfoutput>
now my program only read <cfreturn curr_val>, not <cfreturn country_curr>.
So is it possible to return more than 1 data in one function?
thanks in advance
Shaffiq
CF Developers
capik79 Guest
-
-
capik79 #4
Re: to read multiple cfreturn
Thx Paul,
Can you provide me an example for that.
Array in cffunction and how do I grab in cfinvoke.
Thanks
Shaffiq
capik79 Guest
-
PaulH #5
Re: to read multiple cfreturn
a structure might be a better choice.
<cfcomponent name="currency_converter">
<cffunction name="curr_converter" access="remote" returntype="struct">
<cfargument name="country" required="Yes" type="string">
<cfargument name="myr" required="Yes" type="numeric">
<cfset var thisCurrency=structNew()>
<cfset var curr_val=0>
<cfset var country_curr="">
<cfquery name ="get_val" datasource="ScratchDB">
SELECT curr
FROM currency
WHERE Currency_type = '#arguments.country#'
</cfquery>
<cfset thisCurrency.curr_val = arguments.myr*get_val.curr>
<cfset thisCurrency.country_curr =#get_val.curr#>
<cfreturn thisCurrency>
</cffunction>
</cfcomponent>
<cfinvoke component="currency" method="curr_converter"
returnVariable="final_val">
<cfinvokeargument name="country" value=curr_country>
<cfinvokeargument name="myr" value=curr_req>
</cfinvoke>
<cfoutput>
#final_val.curr_val#
<br>
#final_val.country_curr#
</cfoutput>
PaulH Guest
-
capik79 #6
Re: to read multiple cfreturn
Thank Paul,
Its help me a lot.
Thanks again
Regards,
Shaffiq
capik79 Guest
-
MikeDon #7
Re: to read multiple cfreturn
Try using a Stucture
Change
<cfreturn curr_val>
<cfreturn country_curr>
Change the return type on your <cffunction> to returntype="struct"
then do something like this
<cfscript>
returnObj = StructNew();
returnObj.curr_val = #curr_val#;
returnObj.country_curr = #country_curr#;
</cfscript>
and return the structure
<cfreturn returnObj>
Back in your currency_converter.cfm page you can output #final_val.curr_val#
and #final_val.country_curr#.
Mike
MikeDon Guest



Reply With Quote

