Creating Dynamic Structure

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Creating Dynamic Structure

    Hi,

    I want to create a dynamic structure of structures. I wrote the following code
    but I am getting errors with that.

    I have three entities department, plant and PCP. There are multiple plants for
    a PCP specific to a department. PCP-Department-Plant combination is unique.

    User selects multiple departments, corresponding PCPs on the form. Here is my
    code ....

    <cfset deptPlantPCP = StructNew()>

    <cfloop list="#form.department#" index="deptId">
    <cfset deptPlantPCP.#deptId# = StructNew()> (Getting error with '.' here)
    <cfloop list="#form.pcp#" index="pcpId">
    <!--- plants Query for plant_num based on PCP and Department --->
    <cfloop from="1" to="#plants.recordcount#" index="pCtr">
    <cfset deptPlantPCP.#deptId#.#plants.plant_num[pCtr]# = "#pcpId#">
    </cfloop>
    </cfloop>
    </cfloop>

    Thanks for your help.
    -vmrao.

    vayumahesh Guest

  2. Similar Questions and Discussions

    1. Class::Struct - want to access structure within structure
      I want to access a structure within a structure. Below is what I had in mind. Please help. #!/perl/bin/perl use Class::Struct; struct Step...
    2. Dynamic Structure Question?
      Hi, I wanted to know if possible. Can I have a dynamic structure name? some generic query <cfquery name="qryTest"...
    3. Creating new table with same structure as existing one
      I need to create "archive" table that will have the same structure as "production" one. When I run my program it have to create table named...
    4. Input form for creating hierarchy structure
      Hi I'm trying to create an input screen that allows users to create a hierarchical structure as the one below, but have no clue where to start or...
    5. #24993 [NEW]: Suggestion for DOM - creating XML documents with structure from a recordset
      From: kris_beyers at hotmail dot com Operating system: WindowsXP PHP version: 4.3.2 PHP Bug Type: DOM XML related Bug...
  3. #2

    Default Re: Creating Dynamic Structure

    Try using array notation

    <!--- not tested --->
    <cfset deptPlantPCP[deptId] = StructNew()>

    mxstu Guest

  4. #3

    Default Re: Creating Dynamic Structure

    Thanks, that worked.

    - vmrao
    vayumahesh Guest

  5. #4

    Default Re: Creating Dynamic Structure

    How to check if a particular element like deptPlantPCP[deptId][plantId] exists ?

    For example, the created structure is
    deptPlantPCP[2][25] = 111
    deptPlantPcp[1][10] = 118

    and I want to check if deptPlantPCP[3][22] exists ? If Yes, get the
    corresponding value.

    Thanks,
    vmrao

    vayumahesh Guest

  6. #5

    Default Re: Creating Dynamic Structure

    This should do it...


    <cfscript>
    deptPlantPCP = StructNew();
    deptPlantPcp[1] = StructNew();
    deptPlantPcp[2] = StructNew();

    deptPlantPCP[2][25] = 111;
    deptPlantPcp[1][10] = 118;

    if (StructKeyExists(deptPlantPCP, 3) and StructKeyExists(deptPlantPCP[3], 22))
    {
    writeoutput("yup");
    } else {
    writeoutput("nope");
    }
    </cfscript>

    BSterner Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139