GregLanders
Programmer
I am trying to set up an array with 3 dimensions and then test it by outputing it with 3 nested loops. Here is my code:
<!--- Initializing an array with 3 dimensions --->
<cfset menuitems = ArrayNew(3)>
<!--- Defining the elements of the array --->
<cfset menuitems[1] = "Fruit,/fruit/index.html">
<cfset menuitems[1][1] = "Apples,/fruit/apples.html">
<cfset menuitems[1][1][1] = "Green,/fruit/green_apples.html">
<cfset menuitems[1][1][2] = "Red,/fruit/red_apples.html">
<cfset menuitems[1][2] = "Oranges,/fruit/oranges.html">
<cfset menuitems[1][2][1] = "Little Oranges,/fruit/little_oranges.html">
<cfset menuitems[1][2][2] = "Big Oranges,/fruit/big_oranges.html">
<cfset menuitems[1][2][3] = "Round Oranges,/fruit/round_oranges.html">
<cfset menuitems[1][2][4] = "Navel Oranges,/fruit/navel_oranges.html">
<cfset menuitems[1][2][5] = "Seedless Oranges,/fruit/seedless_oranges.html">
<cfset menuitems[1][3] = "Bannanas,/fruit/bannanas.html">
<cfset menuitems[1][4] = "Exotic Fruits,/fruit/exotic_fruits.html">
<cfset menuitems[1][4][1] = "Kiwi,/fruit/kiwi.html">
<cfset menuitems[1][4][2] = "Pineapple,/fruit/pineapple.html">
<cfset menuitems[1][4][3] = "Mango,/fruit/mango.html">
<cfset menuitems[2] = "Vegetables,/vegetables/index.html">
<cfset menuitems[2][1] = "Corn,/vegetables/corn.html">
<cfset menuitems[2][1][1] = "Popcorn,/vegetables/popcorn.html">
<cfset menuitems[2][1][2] = "Yellow Corn,/vegetables/yella_corn.html">
<cfset menuitems[2][2] = "Carrots,/vegetables/carrots.html">
<cfset menuitems[2][3] = "Peas,/vegetables/peas.html">
<!--- Testing the array with a set of nested loops --->
<cfloop index = "loop1" from="1" to = "#ArrayLen(menuitems)#">
<cfoutput>
[#loop1#][#loop2#][#loop3#]</b>: #menuitems[loop1]#<br>
</cfoutput>
<cfloop index = "loop2" from="1" to = "#ArrayLen(menuitems[loop1])#">
<cfoutput>
[#loop1#][#loop2#][#loop3#]</b>: #menuitems[loop1][loop2]#<br>
</cfoutput>
<cfloop index = "loop3" from="1" to = "#ArrayLen(menuitems[loop1][loop2])#">
<cfoutput>
[#loop1#][#loop2#][#loop3#]</b>: #menuitems[loop1][loop2][loop3]#<br>
</cfoutput>
</cfloop>
</cfloop>
</cfloop>
Here is the error that am getting:
<HR><H3>Error Occurred While Processing Request</H3><P> <TABLE BORDER><TR><TD><H4>Error Diagnostic Information</H4><P><P>An error occurred while evaluating the expression:
<P><PRE> menuitems[1] = "Fruit,/fruit/index.html"
</PRE></P></P>Error near line 12, column 16.<HR><P>Cannot set element of indexed object<P><p>The element at position 1 of the object cannot be set. May be the object is read-only. The object has elements in positions 1 through 0.<P>The error is in dimension 1 of object "menuitems".<P> <p>The error occurred while processing an element with a general identifier of (CFSET), occupying document position (12:1) to (12:48).</p><P><P>Date/Time: 07/15/01 11:04:32<BR>Browser: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; MSOCD)<BR>Remote Address: 24.249.61.22<P></TD></TR></TABLE><P><HR>
<!--- Initializing an array with 3 dimensions --->
<cfset menuitems = ArrayNew(3)>
<!--- Defining the elements of the array --->
<cfset menuitems[1] = "Fruit,/fruit/index.html">
<cfset menuitems[1][1] = "Apples,/fruit/apples.html">
<cfset menuitems[1][1][1] = "Green,/fruit/green_apples.html">
<cfset menuitems[1][1][2] = "Red,/fruit/red_apples.html">
<cfset menuitems[1][2] = "Oranges,/fruit/oranges.html">
<cfset menuitems[1][2][1] = "Little Oranges,/fruit/little_oranges.html">
<cfset menuitems[1][2][2] = "Big Oranges,/fruit/big_oranges.html">
<cfset menuitems[1][2][3] = "Round Oranges,/fruit/round_oranges.html">
<cfset menuitems[1][2][4] = "Navel Oranges,/fruit/navel_oranges.html">
<cfset menuitems[1][2][5] = "Seedless Oranges,/fruit/seedless_oranges.html">
<cfset menuitems[1][3] = "Bannanas,/fruit/bannanas.html">
<cfset menuitems[1][4] = "Exotic Fruits,/fruit/exotic_fruits.html">
<cfset menuitems[1][4][1] = "Kiwi,/fruit/kiwi.html">
<cfset menuitems[1][4][2] = "Pineapple,/fruit/pineapple.html">
<cfset menuitems[1][4][3] = "Mango,/fruit/mango.html">
<cfset menuitems[2] = "Vegetables,/vegetables/index.html">
<cfset menuitems[2][1] = "Corn,/vegetables/corn.html">
<cfset menuitems[2][1][1] = "Popcorn,/vegetables/popcorn.html">
<cfset menuitems[2][1][2] = "Yellow Corn,/vegetables/yella_corn.html">
<cfset menuitems[2][2] = "Carrots,/vegetables/carrots.html">
<cfset menuitems[2][3] = "Peas,/vegetables/peas.html">
<!--- Testing the array with a set of nested loops --->
<cfloop index = "loop1" from="1" to = "#ArrayLen(menuitems)#">
<cfoutput>
[#loop1#][#loop2#][#loop3#]</b>: #menuitems[loop1]#<br>
</cfoutput>
<cfloop index = "loop2" from="1" to = "#ArrayLen(menuitems[loop1])#">
<cfoutput>
[#loop1#][#loop2#][#loop3#]</b>: #menuitems[loop1][loop2]#<br>
</cfoutput>
<cfloop index = "loop3" from="1" to = "#ArrayLen(menuitems[loop1][loop2])#">
<cfoutput>
[#loop1#][#loop2#][#loop3#]</b>: #menuitems[loop1][loop2][loop3]#<br>
</cfoutput>
</cfloop>
</cfloop>
</cfloop>
Here is the error that am getting:
<HR><H3>Error Occurred While Processing Request</H3><P> <TABLE BORDER><TR><TD><H4>Error Diagnostic Information</H4><P><P>An error occurred while evaluating the expression:
<P><PRE> menuitems[1] = "Fruit,/fruit/index.html"
</PRE></P></P>Error near line 12, column 16.<HR><P>Cannot set element of indexed object<P><p>The element at position 1 of the object cannot be set. May be the object is read-only. The object has elements in positions 1 through 0.<P>The error is in dimension 1 of object "menuitems".<P> <p>The error occurred while processing an element with a general identifier of (CFSET), occupying document position (12:1) to (12:48).</p><P><P>Date/Time: 07/15/01 11:04:32<BR>Browser: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; MSOCD)<BR>Remote Address: 24.249.61.22<P></TD></TR></TABLE><P><HR>