> When I run the code below, the keys are outputted in
> alphabetic order, not the order that they are in the structure
> (which is of course what I am after).
>
> Can someone point me in the right direction ... *please*?

You're not going to like the right direction, but here goes anyway.

There isn't really a meaningful "order" of items within an associative
array, which is what a Structure is. A useful analogy is a big bag of stuff.
You might put stuff in in one order and get it out in another order. CF, in
some versions, happens to loop through keys alphabetically. CF 4.5.1
retrieves keys in the original order in which they were entered, but you
can't guarantee that behavior across versions. If you want to order these
items, you'll have to impose that order manually. For example, you could add
a property which simply lists other properties in the order you desire, then
use that to determine how to output those other properties.

> And while we're at it ... is there a way I can output the name of the
> structure without using <CFSET stSwatch.name="#qGetDetails.name#"> or
> another <CFLOOP>?

There's no difference between Structures and other variables when it comes
to referencing the name of the variable. If the Structure isn't dynamically
named at run-time, just output the literal text that matches its name. If
the structure is dynamically named at run-time, you can simply refer to the
name of the variable you used to dynamically name the Structure in the first
place:

<html>

<head>
<title>Structure Fun!</title>
</head>

<body>

<cfscript>
// new name - generated at run-time
MyStructName = "stFoo" & RandRange(1,5);
// create structure with dynamic name
SetVariable(MyStructName, StructNew());
// create pointer to structure
MyStructPointer = Evaluate(MyStructName);
// populate structure keys
StructInsert(MyStructPointer, "Key1", "Value1");
StructInsert(MyStructPointer, "Key2", "Value2");
</cfscript>

<!--- output structure name, loop over keys & values --->
Structure name: <cfoutput>#MyStructName#</cfoutput><br>
<cfloop collection="#MyStructPointer#" item="ThisKey">
        <cfoutput>
        #ThisKey# = #MyStructPointer[ThisKey]#<br>
        </cfoutput>
</cfloop>

</body>
</html>

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444

------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to