Skip to main content
Participant
December 28, 2006
Answered

Structure variable undefined

  • December 28, 2006
  • 3 replies
  • 262 views
Hi All,

I have a problem in using structure and am not sure what I am missing here. I get the following error:
Variable STRSUMMARY is undefined : line 8. This is where NOT StructKeyExists(strSummary,theKey)) code starts.

The code is as below:

<script>
strSummary = StructNew();
</script>

<cfloop query="speclist">
<cfscript>
theKey = "#option#_#model#_#mfr#_#qty#";
if (NOT StructKeyExists(strSummary,theKey)){
strSummary[theKey] = StructNew();
strSummary[theKey].option = option;
strSummary[theKey].model = model;
strSummary[theKey].mfr = mfr;
strSummary[theKey].qty = qty;
strSummary[theKey].itemid = itemid;
}
ArrayAppend(strSummary[theKey].itemid,itemid);
</cfscript>
</cfloop>

Thanks
    This topic has been closed for replies.
    Correct answer Chandu1
    Thanks.. The problem is solved and the code is as below. we can have alpha / numeric as keys

    <cfscript>
    strSummary = StructNew();
    </cfscript>

    <cfloop query="speclist">
    <cfscript>
    theKey = "#option#_#model#_#mfr#_#qty#";
    if (NOT StructKeyExists(strSummary,theKey)){
    strSummary[theKey] = StructNew();
    strSummary[theKey].option = option;
    strSummary[theKey].model = model;
    strSummary[theKey].mfr = mfr;
    strSummary[theKey].qty = qty;
    strSummary[theKey].itemid = ArrayNew(1);
    }
    ArrayAppend(strSummary[theKey].itemid,itemid);
    </cfscript>
    </cfloop>

    3 replies

    Inspiring
    December 28, 2006
    I do not see the reason you would get the error you are reporting.

    But, is this really the best way to model your data. Looking at your
    key structure gave me a headache.

    theKey = "#option#_#model#_#mfr#_#qty#";

    I can not suggest options without understanding the requirements. But I
    really would hate to have to write something like that. Maybe because
    I've been fighting with something like this all week.
    Chandu1AuthorCorrect answer
    Participant
    December 28, 2006
    Thanks.. The problem is solved and the code is as below. we can have alpha / numeric as keys

    <cfscript>
    strSummary = StructNew();
    </cfscript>

    <cfloop query="speclist">
    <cfscript>
    theKey = "#option#_#model#_#mfr#_#qty#";
    if (NOT StructKeyExists(strSummary,theKey)){
    strSummary[theKey] = StructNew();
    strSummary[theKey].option = option;
    strSummary[theKey].model = model;
    strSummary[theKey].mfr = mfr;
    strSummary[theKey].qty = qty;
    strSummary[theKey].itemid = ArrayNew(1);
    }
    ArrayAppend(strSummary[theKey].itemid,itemid);
    </cfscript>
    </cfloop>
    Inspiring
    December 28, 2006
    Problem 1, you are mixing structures and arrays.
    Problem 2, shouldn't thekey be numeric?