just move "ad = StructNew();" inside the for loop and problem solved.
The reason it's doing that is because you only declared structNew once.
When you declare structNew it causes the variable (ad) to point to a memory
address (let's use 0x1234 for this example).
You then add this memory address to the array 36 times so you have an array
where each item points to the exact same memory space. The last loop of the
for loop sets the values in that memory space to the last item in the file
and so it will appear that all the array items are the same (which they are)
and they all point to the last item from the file.
Put structNew inside the for loop and each iteration of the list will give
"ad" a new memory pointer and each array item will be unique.
+-----------------------------------------------+
Bryan Love
Database Analyst
Macromedia Certified Professional
Internet Application Developer
TeleCommunication Systems
[EMAIL PROTECTED]
+-----------------------------------------------+
"...'If there must be trouble, let it be in my day, that my child may have
peace'..."
- Thomas Paine, The American Crisis
"Let's Roll"
- Todd Beamer, Flight 93
-----Original Message-----
From: Owens, Howard [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 11, 2003 11:33 AM
To: CF-Talk
Subject: populate the damn array
OK, this probably something real stupid, but I'm not seeing it ...
This code takes a tabbed file and is supposed to parse it into an array of
structures.
The problem is, the array is populating with 36 elements of the same data.
Whatever the last item in the file is, that because the repeated element ...
which means that each array append is overwriting previous data, or
something like that ... below is the complete code ... can anyone see what
the error is? Probably something simple and stupid:
<cfscript>
Manifest=Replace(manifest, chr(09), ";", "ALL");
ListFileLen=ListLen(Manifest, "#chr(10)##chr(13)#");
container = ArrayNew(1);
ad = StructNew();
for (y=1; y LTE ListFileLen; y=y+1) {
ListFileText="#ListGetAt(Manifest, y,
"#chr(10)##chr(13)#")#";
ad.attribute_name="#ListGetAt(ListFileText, 2, ";")#";
ad.ad_id="#ListGetAt(ListFileText,
3, ";")#";
ad.display_text="Caption";
ad.attribute_cdata="#ListGetAt(ListFileText, 4, ";")#";
ad.startdate="#ListGetAt(ListFileText, 5, ";")#";
ad.stopdate="#ListGetAt(ListFileText, 5, ";")#";
containerAds = ArrayAppend(container, ad);
}
</cfscript>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Howard Owens
Internet Operations Coordinator
InsideVC.com/Ventura County Star
[EMAIL PROTECTED]
AIM: GoCatGo1956
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
This list and all House of Fusion resources hosted by CFHosting.com. The place for
dependable ColdFusion Hosting.
http://www.cfhosting.com
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4