I have been on the list for years but am a bit of a shy lurker. I wonder if anyone can help with the following.

The CF docs say:
"StructFindKey - Searches recursively through a substructure of nested arrays, structures, and other elements, for structures whose values match the search key in the value parameter."

This sounds great, but when I tried it with a two dimensional array of structures I couldn't get it to work as I thought it should from the top level. Am I misunderstanding something? Does anyone know if it is possible to use StructFindKey in a two dimensional array? Looks like I can't, but I wish....

Thanks if someone can cast some light on this.
Sue McNab

Test code follows:
<cfscript>
aErrors = Arraynew(1);

//Create arrays and structures
aTwoDimArrayOfStructs = ArrayNew(2);
for(i=1; i lte 5; i=i+1){
ArrayAppend(aTwoDimArrayOfStructs,ArrayNew(1));
iDim1=ArrayLen(aTwoDimArrayOfStructs);
for(j=1; j lte 3; j=j+1){
  ArrayAppend(aTwoDimArrayOfStructs[iDim1],StructNew());
  iDim2=ArrayLen(aTwoDimArrayOfStructs[iDim1]);
  StructInsert(aTwoDimArrayOfStructs[iDim1][iDim2],"struct content ("&j&")",iDim1&"."&iDim2);
}
}
try{
aTestSTFK = StructFindKey(aTwoDimArrayOfStructs,"struct content (2)","all");
}
catch(Any excpt) {
excptMessage = excpt.Message & "<br /><br />";
ArrayAppend(aErrors,excptMessage);
}
try{
aTestSTFK_d1 = StructFindKey(aTwoDimArrayOfStructs[1],"struct content (2)","all");
}
catch(Any excpt) {
excptMessage = excpt.Message & "<br /><br />";
ArrayAppend(aErrors,excptMessage);
}
try{
aTestSTFK_d2  = StructFindKey(aTwoDimArrayOfStructs[1][2],"struct content (2)","all");
}
catch(Any excpt) {
excptMessage = excpt.Message & "<br /><br />";
ArrayAppend(aErrors,excptMessage);
}  
</cfscript>
<strong>Errors caught:</strong>
<cfif ArrayIsEmpty(aErrors)><cfdump label="aErrors" var="#aErrors#"><cfelse>None</cfif><br />
<br /><strong>StructFindKey Results Top:</strong>
<cfif isDefined("aTestSTFK")><cfdump label="aTestSTFK" var="#aTestSTFK#"><cfelse>aTestSTFK Failed</cfif><br />
<br /><strong>StructFindKey Results L1:</strong>
<cfif isDefined("aTestSTFK_d1")><cfdump label="aTestSTFK_d1" var="#aTestSTFK_d1#"><cfelse>aTestSTFK_d1 Failed</cfif><br />
<br /><strong>StructFindKey Results L2:</strong>
<cfif isDefined("aTestSTFK_d2")><cfdump label="aTestSTFK_d2" var="#aTestSTFK_d2#"><cfelse>aTestSTFK_d2 Failed</cfif><br />
<br /><strong>Output of 2D array of structures:</strong>
<cfif isDefined("aTwoDimArrayOfStructs")><cfdump label="aTwoDimArrayOfStructs" var="#aTwoDimArrayOfStructs#"><cfelse>Failed to populate arrays</cfif><br />
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to