RE: array - structure question
Others have sent in suggestions, but I'd like to show another way of doing it as well... with UDFs! I have an article coming out for CFDJ that discusses this concept, but the idea is simple. You can use a UDF to quickly create structures and, if you know what you are doing, safely append to the local scope. Watch: Original: // DEPARTMENT 1 item.department = 'Department 1; item.name = 'Bill Jones; item.email = '[EMAIL PROTECTED]; additem = arrayAppend(request.contact, item); // DEPARTMENT 2 item.department = 'Department 2; item.name = 'Joe Jones; item.email = '[EMAIL PROTECTED]; With UDFs: request.contact = arrayNew(); addContact(Department 1,Bill Jones,[EMAIL PROTECTED]); addContact(Department 2,Jpe Jones,[EMAIL PROTECTED]); etc... function addContact(dpt,name,email) { var d = structNew(); d.dpt = dpt; d.name = name; d.email = email; arrayAppend(request.contact,d); } === Raymond Camden, Principal Spectra Compliance Engineer for Macromedia Email: [EMAIL PROTECTED] Yahoo IM : morpheus My ally is the Force, and a powerful ally it is. - Yoda -Original Message- From: Owens, Howard [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 10, 2002 7:41 PM To: CF-Talk Subject: array - structure question On my Application.cfm page, I want to use an array to populate a feedback form with contacts, and the response page with the corresponding e-mail addresses in the to attribute. This seemed more practical than storing the info in a database, for an amount of data this limited, but still give some flexibility for making changes down the road. So here's a snip from within my CFScript: // department mail addresses // e-mail addresses and contact information dropped into an array of structs to facilitate retrieval and updating request.contact = arrayNew(1); item = structNew(); // DEPARTMENT 1 item.department = 'Department 1; item.name = 'Bill Jones; item.email = '[EMAIL PROTECTED]; additem = arrayAppend(request.contact, item); // DEPARTMENT 2 item.department = 'Department 2; item.name = 'Joe Jones; item.email = '[EMAIL PROTECTED]; additem = arrayAppend(request.contact, item); and so on. The problem is, the last entry keeps overwriting the structures at each array position. In other words, request.contact[1] contains the data for array position 10, and position 2 contains the data for 10 ... and so on. Should position 1 of the array remember what it had initially and not get over written by the time the 2 position is created, and so on? How can I get each position in the array to have structures with discrete and unique information? H. Howard Owens Internet Operations Coordinator www.insidevc.com [EMAIL PROTECTED] AIM: GoCatGo1956 __ Get Your Own Dedicated Windows 2000 Server PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER Instant Activation · $99/Month · Free Setup http://www.pennyhost.com/redirect.cfm?adcode=coldfusionb FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: array - structure question
Raymond, you're the UDF King, aren't you :-) H. Howard Owens Internet Operations Coordinator www.insidevc.com [EMAIL PROTECTED] AIM: GoCatGo1956 -Original Message- From: Raymond Camden [SMTP:[EMAIL PROTECTED]] Sent: Friday, January 11, 2002 5:29 AM To: CF-Talk Subject: RE: array - structure question Others have sent in suggestions, but I'd like to show another way of doing it as well... with UDFs! I have an article coming out for CFDJ that discusses this concept, but the idea is simple. You can use a UDF to quickly create structures and, if you know what you are doing, safely append to the local scope. Watch: Original: // DEPARTMENT 1 item.department = 'Department 1; item.name = 'Bill Jones; item.email = '[EMAIL PROTECTED]; additem = arrayAppend(request.contact, item); // DEPARTMENT 2 item.department = 'Department 2; item.name = 'Joe Jones; item.email = '[EMAIL PROTECTED]; With UDFs: request.contact = arrayNew(); addContact(Department 1,Bill Jones,[EMAIL PROTECTED]); addContact(Department 2,Jpe Jones,[EMAIL PROTECTED]); etc... function addContact(dpt,name,email) { var d = structNew(); d.dpt = dpt; d.name = name; d.email = email; arrayAppend(request.contact,d); } Raymond Camden, Principal Spectra Compliance Engineer for Macromedia Email: [EMAIL PROTECTED] Yahoo IM : morpheus My ally is the Force, and a powerful ally it is. - Yoda -Original Message- From: Owens, Howard [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 10, 2002 7:41 PM To: CF-Talk Subject: array - structure question On my Application.cfm page, I want to use an array to populate a feedback form with contacts, and the response page with the corresponding e-mail addresses in the to attribute. This seemed more practical than storing the info in a database, for an amount of data this limited, but still give some flexibility for making changes down the road. So here's a snip from within my CFScript: // department mail addresses // e-mail addresses and contact information dropped into an array of structs to facilitate retrieval and updating request.contact = arrayNew(1); item = structNew(); // DEPARTMENT 1 item.department = 'Department 1; item.name = 'Bill Jones; item.email = '[EMAIL PROTECTED]; additem = arrayAppend(request.contact, item); // DEPARTMENT 2 item.department = 'Department 2; item.name = 'Joe Jones; item.email = '[EMAIL PROTECTED]; additem = arrayAppend(request.contact, item); and so on. The problem is, the last entry keeps overwriting the structures at each array position. In other words, request.contact[1] contains the data for array position 10, and position 2 contains the data for 10 ... and so on. Should position 1 of the array remember what it had initially and not get over written by the time the 2 position is created, and so on? How can I get each position in the array to have structures with discrete and unique information? H. Howard Owens Internet Operations Coordinator www.insidevc.com [EMAIL PROTECTED] AIM: GoCatGo1956 __ Dedicated Windows 2000 Server PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER Instant Activation · $99/Month · Free Setup http://www.pennyhost.com/redirect.cfm?adcode=coldfusiona FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: array - structure question
Structs are like Pointers/Linked-Lists and reference-based data-structures in other programming languages. If you don't know what I'm talking abooot, thats okay. Just remember this simple example: cfset x=StructNew() cfset y=x y is now x and x is now y for all intents and purposes. any modifications to y are made to x and visa versa. you have 2 options. option #1: Use StructCopy to copy Item to that array element option #2: Set Item=StructNew after assigning the value. Example: // department mail addresses // e-mail addresses and contact information dropped into an array of structs to facilitate retrieval and updating request.contact = arrayNew(1); // DEPARTMENT 1 item = structNew(); item.department = 'Department 1; item.name = 'Bill Jones; item.email = '[EMAIL PROTECTED]; additem = arrayAppend(request.contact, item); // DEPARTMENT 2 item=StructNew(); item.department = 'Department 2; item.name = 'Joe Jones; item.email = '[EMAIL PROTECTED]; additem = arrayAppend(request.contact, item); ::brendan avery 2.0 ::310.779.2211 ::[EMAIL PROTECTED] ::santa monica, california -Original Message- From: Owens, Howard [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 10, 2002 16:41 To: CF-Talk Subject: array - structure question On my Application.cfm page, I want to use an array to populate a feedback form with contacts, and the response page with the corresponding e-mail addresses in the to attribute. This seemed more practical than storing the info in a database, for an amount of data this limited, but still give some flexibility for making changes down the road. So here's a snip from within my CFScript: // department mail addresses // e-mail addresses and contact information dropped into an array of structs to facilitate retrieval and updating request.contact = arrayNew(1); item = structNew(); // DEPARTMENT 1 item.department = 'Department 1; item.name = 'Bill Jones; item.email = '[EMAIL PROTECTED]; additem = arrayAppend(request.contact, item); // DEPARTMENT 2 item.department = 'Department 2; item.name = 'Joe Jones; item.email = '[EMAIL PROTECTED]; additem = arrayAppend(request.contact, item); and so on. The problem is, the last entry keeps overwriting the structures at each array position. In other words, request.contact[1] contains the data for array position 10, and position 2 contains the data for 10 ... and so on. Should position 1 of the array remember what it had initially and not get over written by the time the 2 position is created, and so on? How can I get each position in the array to have structures with discrete and unique information? H. Howard Owens Internet Operations Coordinator www.insidevc.com [EMAIL PROTECTED] AIM: GoCatGo1956 __ Dedicated Windows 2000 Server PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER Instant Activation · $99/Month · Free Setup http://www.pennyhost.com/redirect.cfm?adcode=coldfusiona FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
Re: array - structure question
this may be looking a little awkard but it works... try item1 = structNew(); item1.department = 'Department 1; item1.name = 'Bill Jones; item1.email = '[EMAIL PROTECTED]; additem = arrayAppend(request.contact, item1); item2 = StructNew(); item2.department = 'Department 2; item2.name = 'Joe Jones; item2.email = '[EMAIL PROTECTED]; additem = arrayAppend(request.contact, item2); cheerio Birgit Thursday, January 10, 2002, 7:40:47 PM, you wrote: OH On my Application.cfm page, I want to use an array to populate a feedback OH form with contacts, and the response page with the corresponding e-mail OH addresses in the to attribute. OH This seemed more practical than storing the info in a database, for an OH amount of data this limited, but still give some flexibility for making OH changes down the road. OH So here's a snip from within my CFScript: OH // department mail addresses OH // e-mail addresses and contact information dropped into an array of structs OH to facilitate retrieval and updating OH request.contact = arrayNew(1); OH item = structNew(); OH // DEPARTMENT 1 OH item.department = 'Department 1; OH item.name = 'Bill Jones; OH item.email = '[EMAIL PROTECTED]; OH additem = arrayAppend(request.contact, item); OH // DEPARTMENT 2 OH item.department = 'Department 2; OH item.name = 'Joe Jones; OH item.email = '[EMAIL PROTECTED]; OH additem = arrayAppend(request.contact, item); OH and so on. OH The problem is, the last entry keeps overwriting the structures at each OH array position. In other words, request.contact[1] contains the data for OH array position 10, and position 2 contains the data for 10 ... and so on. OH Should position 1 of the array remember what it had initially and not get OH over written by the time the 2 position is created, and so on? OH How can I get each position in the array to have structures with discrete OH and unique information? OH H. OH Howard Owens OH Internet Operations Coordinator OH www.insidevc.com OH [EMAIL PROTECTED] OH AIM: GoCatGo1956 OH __ Dedicated Windows 2000 Server PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER Instant Activation · $99/Month · Free Setup http://www.pennyhost.com/redirect.cfm?adcode=coldfusiona FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists