A potential problem with your code is not scoping the variable in the function 
- it's very possible that outside your function you have another variable named 
result that could be conflicting with your function.

<cffunction name="myfunction" access="remote" returntype="struct">
       <cfargument name="form_data" type="struct">

<!---  The variable to be returned by the function is "result"  --->
<cfset var result = StructNew() />
<cfset var person = "" />
<cfset result['dept_name'] = "some dept"
<cfset result['dept_num'] = "some dept number"
Try putting that in there and see if it helps.



________________________________
From: [email protected] [mailto:[email protected]] On Behalf Of Clarke Bishop
Sent: Thursday, September 09, 2010 11:24 AM
To: [email protected]
Subject: RE: [ACFUG Discuss] newbie question: storing an array variable into a 
variable whose data type is not specified

I think <cfset foo['sauce'] = []/> started working with CF8, so this could 
still be a problem with an earlier version of ColdFusion.

Also, Chris, just so you know, you can put multiple lines inside a <cfscript> 
block. It usually looks more like:
<cfscript>
   Line 1 of code;
   Line 2 of code;
   Line 3 of code
...


</cfscript>

Easier to read in my opinion!

   Clarke

From: [email protected] [mailto:[email protected]] On Behalf Of Steve Ross
Sent: Thursday, September 09, 2010 10:03 AM
To: [email protected]
Subject: Re: [ACFUG Discuss] newbie question: storing an array variable into a 
variable whose data type is not specified

actually that should work fine...

because this works:

<cfset foo['sauce'] = []/>
<cfdump var="#foo#">

On Thu, Sep 9, 2010 at 9:56 AM, 
<[email protected]<mailto:[email protected]>> 
wrote:
I think you have to first declare

<cfset result = StructNew()>

before attempting to do this
                <cfset result['people_info'] = peoplearray <!--- Can this be 
done? --->

               <cfset result['statMsg'] = 'Information successfully collected.'>
               <cfset result['status'] = true>



Jay Jayaraman
Central Billing Services
Financial Management and Planning
(404) 498-8453 (W)
(404) 273-7131 (C)



From:        Chris H <[email protected]<mailto:[email protected]>>
To:        [email protected]<mailto:[email protected]>
Date:        09/09/2010 09:51 AM
Subject:        [ACFUG Discuss] newbie question: storing an array variable into 
a variable whose data type is not specified
Sent by:        [email protected]<mailto:[email protected]>
________________________________



Hi All,

I am a newbie to Coldfusion. My development background is mainly in C/C++ so 
please excuse me if my below question is naive.

I have a function as below

<cffunction name="myfunction" access="remote" returntype="any">
       <cfargument name="form_data" type="struct">

<!---  The variable to be returned by the function is "result"  --->

<cfset result['dept_name'] = "some dept"
<cfset result['dept_num'] = "some dept number"

<!---  I run a query where I want to find some information about people having
name "John" and there can be N number of people with the name of John --->


<cfquery dbtype="query" name="printPeople">
   SELECT *
   FROM people
   WHERE peopleName = "John"
</cfquery>

<cfset peoplearray=ArrayNew(1)>

     <cfset myCounter = 0 />
        <cfloop query="printPeople">

          <cfset myCounter = myCounter + 1 />


         <cfscript>
                 ArrayAppend(peoplearray, #printPeople.empID#);
         </cfscript>

         <cfscript>
                 ArrayAppend(peoplearray, #printPeople.departmentname#);
         </cfscript>


         <cfscript>
                 ArrayAppend(peoplearray, #printPeople.departmentID#);
         </cfscript>


         <cfscript>
                 ArrayAppend(peoplearray, #printPeople.empTitle#);
         </cfscript>

         </cfloop>



               <cfset result['people_info'] = peoplearray <!--- Can this be 
done? --->

               <cfset result['statMsg'] = 'Information successfully collected.'>
               <cfset result['status'] = true>

    <cfreturn result>

</cffunction>


The part <cfset result['people_info'] = peoplearray
attempts to store an array variable into a variable whose data type is not 
specified.

Can this be done?

If not, what should I do? Should I define the datatype of "result" variable as 
a structure, change the return type
in function signature as a structure from any as a structure variable
can hold string, integer and array variables?

Any suggestions would be appreciated.


-------------------------------------------------------------
To unsubscribe from this list, manage your profile @
http://www.acfug.org?fa=login.edituserform

For more info, see http://www.acfug.org/mailinglists
Archive @ http://www.mail-archive.com/discussion%40acfug.org/
List hosted by FusionLink<http://www.fusionlink.com/>
-------------------------------------------------------------


-------------------------------------------------------------
To unsubscribe from this list, manage your profile @
http://www.acfug.org?fa=login.edituserform

For more info, see http://www.acfug.org/mailinglists
Archive @ http://www.mail-archive.com/discussion%40acfug.org/
List hosted by FusionLink<http://www.fusionlink.com>
-------------------------------------------------------------



--
Steve Ross
web application & interface developer
http://blog.stevensross.com
[mobile] (912) 344-8113
[ AIM / Yahoo! : zeriumsteven ] [googleTalk : nowhiding ]

-------------------------------------------------------------
To unsubscribe from this list, manage your profile @
http://www.acfug.org?fa=login.edituserform

For more info, see http://www.acfug.org/mailinglists
Archive @ http://www.mail-archive.com/discussion%40acfug.org/
List hosted by FusionLink<http://www.fusionlink.com>
-------------------------------------------------------------



-------------------------------------------------------------

To unsubscribe from this list, manage your profile @ 

http://www.acfug.org?fa=login.edituserform



For more info, see http://www.acfug.org/mailinglists

Archive @ http://www.mail-archive.com/discussion%40acfug.org/

List hosted by http://www.fusionlink.com

-------------------------------------------------------------


Reply via email to