to read multiple cfreturn

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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>...
    3. 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...
    4. 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....
    5. 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...
  3. #2

    Default 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

  4. #3

    Default Re: to read multiple cfreturn

    return what you need as an array or structure.
    PaulH Guest

  5. #4

    Default 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

  6. #5

    Default 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

  7. #6

    Default Re: to read multiple cfreturn

    Thank Paul,

    Its help me a lot.

    Thanks again

    Regards,
    Shaffiq
    capik79 Guest

  8. #7

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139