Solved

Copy value from struct to struct??

Posted on 2004-09-01
5
178 Views
Last Modified: 2013-12-24
How do you copy one of the values in a structure to another structure..

I know about duplicate(), but wanted to ask if there is a way to just copy 1 value from the structure...

My first thought woudl be to copy it to local variable scope, and the move it into structure I want???

Please let me know if possible.

Thanks

WS
0
Comment
Question by:Westside2004
  • 3
5 Comments
 
LVL 21

Expert Comment

by:pinaldave
ID: 11959780
Hi Westside2004,

The following code shows how this function copies a structure that contains a string field, a number field, and a two-dimensional array at the top level:

<cfoutput>
   <cfset assignedCopy = StructNew()>
  <cfset assignedCopy.string = #struct.string#>
   <cfset assignedCopy.number = #struct.number#>
   <cfset assignedCopy.array = ArrayNew(2)>
   <cfset assignedCopy.array[1][1] = #struct.array[1][1]#>
   <cfset assignedCopy.array[1][2] = #sruct.array[1][2]#>
</cfoutput>

The following code shows how StructCopy copies a nested structure:

<cfoutput>
  <cfset assignedCopy.nestedStruct = struct.nestedStruct>
</cfoutput>

To copy a structure entirely by value, use Duplicate.

Regards,
---Pinal
0
 
LVL 1

Author Comment

by:Westside2004
ID: 11959897
I just need to copy one value from within the structure ideally..

The structure holds a bunch of other info, but I just want one specific key/value pair...

Can that be done?

Thanks

WS
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 11959915
Hello Westside2004!

You may browse this site for you reference on using arrays and structures :

http://livedocs.macromedia.com/coldfusion/6/Developing_ColdFusion_MX_Applications_with_CFML/arrayStruct7.htm


Regards!
eNTRANCE2002 :-)
0
 
LVL 21

Accepted Solution

by:
pinaldave earned 125 total points
ID: 11960112
Hi Westside2004,

i think so we can do it.
<CFSET structone.var = structtwo.var2>
I do not see any problem with that.

Regards,
---Pinal
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11960327
Smiles and good day,
---Pinal
0

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help Fix A 403 error 13 120
How to monitor the number of connections/threads being utilized on Tomcat 6.0 8 91
Help with a redirect in web.config file 8 65
Problem to copy file 14 51
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question