Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assigning Structure to an Array

Status
Not open for further replies.

cfhelp

Programmer
Jan 11, 2006
11
US
Code:
<cfset KeyArray = ArrayNew(1)>
<cfset KeyStruct = StructNew()>

<cfloop INDEX="i" from="1" to="#Attributes.cq_value_Qry.RecordCount#">
<cfset KeyInnerArray = ArrayNew(1)>
<cfloop index="j" from="1" to="#r_cq_keycolumns.RecordCount#">
<cfset KeyInnerStruct = StructNew()>
<cfset KeyInnerStruct.Name = UCase(r_cq_keycolumns.keyname[j])>
<cfset FieldName = r_cq_keycolumns.fieldname[j]>
<cfset KeyInnerStruct.Value = Evaluate("Attributes.cq_value_Qry."&"#fieldname#" & "")>
<cfset Temp = ArrayAppend(KeyInnerArray,KeyInnerStruct)>
</cfloop>
<cfset KeyStruct.KeyCount = r_cq_keycolumns.RecordCount>
<cfset KeyStruct.Keys = KeyInnerArray>
<cfset Temp = ArrayAppend(KeyArray,KeyStruct)>
</cfloop>

The above code always returns the last value(structure) for KeyArray. When
i dump KeyArray it has the right value but when i dump the whole KeyArray array outside the loop
it has the last value of the structure. Could anyone see what i am doing wrong. Any help is appreciated.

Thanks
 
<cfset Temp = ArrayAppend(KeyArray,StructCopy(KeyStruct))>

Adding StructCopy worked. Thanks



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top