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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does exist something like a structurearray? 1

Status
Not open for further replies.

freiheit

Programmer
Oct 4, 2000
8
DE
Hi,

is it possible to define a structure and then define an array from this structure? Maybe someone remembers how a struct works in C or an object in C++, etc..

structure[1].keyname = anything
:
:
structure[n].keyname = anything else

Thanks.
Marcus [sig][/sig]
 
Yes, you may in a sense...
First define an array of dimension 1, then define a structure and populate it within a loop:

<cfset MyStruct=ArrayNew(1)>

<cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;LastNum&quot;>
<cfset MyStruct=StructNew()> - define the structure
<cfset MyStruct.key1=&quot;First Key&quot;>
<cfset MyStruct.key2=&quot;Second Key&quot;>
<cfset MyStruct.key3=&quot;Third Key&quot;> - define key contents
</cfloop>

Now refer to MyStruct[2].key2 or MyStruct[3].key1 as needed

A valuable resource is to obtain the custom tag (from Allaire Developer's Exchange) called cf_objectdump.

You can test your structure using this custom tag by including the line:

<cf_objectdump object=&quot;#MyStruct#>

and it will show the complete array of structures.
For further information contact me:
Rick Bierregaard
webmaster@rsd-tc.com
 
In reviewing the code, I realize I forgot to set up the array part... this is what it should be:

<cfset MyStruct=ArrayNew(1)>

<cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;LastNum&quot;>
<cfset MyStruct=StructNew()> - define the structure
<cfset MyStruct.key1=&quot;First Key&quot;>
<cfset MyStruct.key2=&quot;Second Key&quot;>
<cfset MyStruct.key3=&quot;Third Key&quot;> - define key contents
</cfloop>
 
When I submit I keep losing the [index] ([ i] generates italics!)

<cfset MyStruct=ArrayNew(1)>

<cfloop index=&quot;index&quot; from=&quot;1&quot; to=&quot;LastNum&quot;>
<cfset MyStruct[index]=StructNew()> - define the structure
<cfset MyStruct[index].key1=&quot;First Key&quot;>
<cfset MyStruct[index].key2=&quot;Second Key&quot;>
<cfset MyStruct[index].key3=&quot;Third Key&quot;> - define key contents
</cfloop>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top