Re: Problem deleting structure in an array

2010-01-12 Thread Leigh

> That's why I love this list it makes you less dumb.

Now that would make a good T-Shirt ;-)  

   "Join CF-Talk (It makes you less dumb)"


  

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329617
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Problem deleting structure in an array

2010-01-12 Thread jrmuniz

Hello:

For those of you following the tread Leigh had the correct solution.
When deleting using a loop, delete in reverse or descending order.
It makes so much sense, yet in never occurred to me. 

That's why I love this list it makes you less dumb.

Jaime



~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329616
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Problem deleting structure in an array

2010-01-12 Thread Leigh

Jaime,

No problem. I just wanted to make sure you saw the examples, as I think they 
give a good demonstration of both the issue and resolution.

-Leigh


  

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329615
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Problem deleting structure in an array

2010-01-12 Thread Qing Xia

Yep, Leigh's solution is much simpler.  [?]

On Tue, Jan 12, 2010 at 9:47 PM, jrmuniz  wrote:

>
> Leigh:  My apologies. When I read your post I stopped at the word "Yes" not
> realizing there was more.  What you are saying makes perfect sense. I'll
> give that a try.  Jaime
>
> See my previous response. You must remove the item in _descending_ order.
> That way the element you are trying to remove will always exist.
>
>
>
>
>
> 

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329614
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Problem deleting structure in an array

2010-01-12 Thread jrmuniz

Leigh:  My apologies. When I read your post I stopped at the word "Yes" not 
realizing there was more.  What you are saying makes perfect sense. I'll 
give that a try.  Jaime  

See my previous response. You must remove the item in _descending_ order. 
That way the element you are trying to remove will always exist.





~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329613
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Problem deleting structure in an array

2010-01-12 Thread Leigh

See my previous response. You must remove the item in _descending_ order. That 
way the element you are trying to remove will always exist.

-Leigh




  

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329612
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Problem deleting structure in an array

2010-01-12 Thread jrmuniz

Chad & Qing Xia:

Thanks for your responses. You are both correct. 
But I still can't figure out how to fix it.

Chad:
I used cfdump in the loop and what is happening is that the
session.shopping array  index is  decreasing  by 1 every time one
structure is deleted.
Which makes sense. When the index is off it can't find the others. 

Qing Xia:
This statement is correct.
"I bet the error happens only if item 3 is selected. If you do 1 and 2 
then
you'll get the original number 2 remaining in the array."
However, I don't understand how this would work:
"So maybe you can figure out which array index values are NOT selected for
deletion, clear out the original array and insert the un-deleted array 
elements back in there."

I have tried to compensate for that in the loop but nothing works so far.
It seems I  need to decrease the session.shopping [i]  by 1 every time it 
loops. 
Or maybe there is another way to accomplish this?

I tried the array resize function and did not work.

   

   
  
   
  
  
   

Thanks for any insights.

Jaime 


Chad Gray wrote:

My best guess is if you remove one item it changes the structure of the 
array and when it goes to remove the next one it cannot be found?

Use CFDump to display the array as you are looping over it to help debug.  
This way you can see the way the array is changing as you are removing 
items.



-Original Message-
From: jrmuniz [mailto:jrmu...@sfsailing.com]
Sent: Tuesday, January 12, 2010 4:16 PM
To: cf-talk
Subject: Problem deleting structure in an array

Hello:

Sorry, I forgot the subject in my last post.

I'm having an issue deleting a form structure that is in a shopping cart
array.
I'm sure it's something simple I'm doing wrong, but it's driving me crazy.

I have a checkbox to select which items to delete.
If only one item is selected there is no error and it works fine.
If more than one item is selected then the error is triggered.
Strangely, if I resubmit the form after the error it works OK.

If I select two items to delete the error is:
The error message is "  Element at position [3] doesn't exist in
array"

Here is the form code:


   
   
   
   
   
   
   
   
   
   
   
   
   
   



Here is the cfc code:


 

   


Any help is greatly appreciated.

Regards,
Jaime



~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329611
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Problem deleting structure in an array

2010-01-12 Thread Qing Xia

So maybe you can figure out which array index values are NOT selected for
deletion, clear out the original array and insert the un-deleted array
elements back in there.

On Tue, Jan 12, 2010 at 5:10 PM, Qing Xia  wrote:

> Nope, on 2nd thought, Chat was right. If your array index was messed up,
> then the error would have occurred sooner while rendering the form.
>
> I bet the error happens only if item 3 is selected. If you do 1 and 2 then
> you'll get the original number 2 remaining in the array.
>
> On Tue, Jan 12, 2010 at 4:51 PM, Qing Xia  wrote:
>
>> You are looping over the array sequentially from 1 but are you sure your
>> array key values are sequential from 1 as well?
>>
>> Your loop goes 1, 2, 3, which means it will expect to find
>> session.shoppingCart[1].itemid, session.shoppingCart[2].itemid and
>> session.shoppingCart[3].itemid.  But are you sure those are indeed the key
>> values in the session array? If your array key values go 1,3,4 then that
>> will definitely break things.
>>
>> On Tue, Jan 12, 2010 at 4:31 PM, Chad Gray  wrote:
>>
>>>
>>> My best guess is if you remove one item it changes the structure of the
>>> array and when it goes to remove the next one it cannot be found?
>>>
>>> Use CFDump to display the array as you are looping over it to help debug.
>>>  This way you can see the way the array is changing as you are removing
>>> items.
>>>
>>>
>>>
>>> > -Original Message-
>>> > From: jrmuniz [mailto:jrmu...@sfsailing.com]
>>> > Sent: Tuesday, January 12, 2010 4:16 PM
>>> > To: cf-talk
>>> > Subject: Problem deleting structure in an array
>>> >
>>> >
>>> > Hello:
>>> >
>>> > Sorry, I forgot the subject in my last post.
>>> >
>>> > I'm having an issue deleting a form structure that is in a shopping
>>> cart
>>> > array.
>>> > I'm sure it's something simple I'm doing wrong, but it's driving me
>>> crazy.
>>> >
>>> > I have a checkbox to select which items to delete.
>>> > If only one item is selected there is no error and it works fine.
>>> > If more than one item is selected then the error is triggered.
>>> > Strangely, if I resubmit the form after the error it works OK.
>>> >
>>> > If I select two items to delete the error is:
>>> > The error message is "Element at position [3] doesn't
>>> exist in
>>> > array"
>>> >
>>> > Here is the form code:
>>> > 
>>> > 
>>> > 
>>> > 
>>> > 
>>> > 
>>> > >> > value="#session.shoppingcart[i].quantity#" size="3">
>>> > 
>>> > 
>>> > >> > value="#HTMLEditFormat(session.shoppingcart[i].catalog)#" size="10">
>>> > 
>>> > 
>>> > >> > value="#HTMLEditFormat(session.shoppingcart[i].description)#"
>>> > size="40">
>>> > 
>>> > >> > value="#session.shoppingcart[i].price#" size="3">
>>> > 
>>> > 
>>> > 
>>> >
>>> > Here is the cfc code:
>>> > 
>>> >
>>> >   
>>> >  
>>> > 
>>> > 
>>> >
>>> > Any help is greatly appreciated.
>>> >
>>> > Regards,
>>> > Jaime
>>> >
>>> >
>>> >
>>> >
>>> >
>>>
>>> 

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329604
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4


Re: Problem deleting structure in an array

2010-01-12 Thread Qing Xia

Nope, on 2nd thought, Chat was right. If your array index was messed up,
then the error would have occurred sooner while rendering the form.

I bet the error happens only if item 3 is selected. If you do 1 and 2 then
you'll get the original number 2 remaining in the array.

On Tue, Jan 12, 2010 at 4:51 PM, Qing Xia  wrote:

> You are looping over the array sequentially from 1 but are you sure your
> array key values are sequential from 1 as well?
>
> Your loop goes 1, 2, 3, which means it will expect to find
> session.shoppingCart[1].itemid, session.shoppingCart[2].itemid and
> session.shoppingCart[3].itemid.  But are you sure those are indeed the key
> values in the session array? If your array key values go 1,3,4 then that
> will definitely break things.
>
> On Tue, Jan 12, 2010 at 4:31 PM, Chad Gray  wrote:
>
>>
>> My best guess is if you remove one item it changes the structure of the
>> array and when it goes to remove the next one it cannot be found?
>>
>> Use CFDump to display the array as you are looping over it to help debug.
>>  This way you can see the way the array is changing as you are removing
>> items.
>>
>>
>>
>> > -Original Message-
>> > From: jrmuniz [mailto:jrmu...@sfsailing.com]
>> > Sent: Tuesday, January 12, 2010 4:16 PM
>> > To: cf-talk
>> > Subject: Problem deleting structure in an array
>> >
>> >
>> > Hello:
>> >
>> > Sorry, I forgot the subject in my last post.
>> >
>> > I'm having an issue deleting a form structure that is in a shopping cart
>> > array.
>> > I'm sure it's something simple I'm doing wrong, but it's driving me
>> crazy.
>> >
>> > I have a checkbox to select which items to delete.
>> > If only one item is selected there is no error and it works fine.
>> > If more than one item is selected then the error is triggered.
>> > Strangely, if I resubmit the form after the error it works OK.
>> >
>> > If I select two items to delete the error is:
>> > The error message is "Element at position [3] doesn't
>> exist in
>> > array"
>> >
>> > Here is the form code:
>> > 
>> > 
>> > 
>> > 
>> > 
>> > 
>> > > > value="#session.shoppingcart[i].quantity#" size="3">
>> > 
>> > 
>> > > > value="#HTMLEditFormat(session.shoppingcart[i].catalog)#" size="10">
>> > 
>> > 
>> > > > value="#HTMLEditFormat(session.shoppingcart[i].description)#"
>> > size="40">
>> > 
>> > > > value="#session.shoppingcart[i].price#" size="3">
>> > 
>> > 
>> > 
>> >
>> > Here is the cfc code:
>> > 
>> >
>> >   
>> >  
>> > 
>> > 
>> >
>> > Any help is greatly appreciated.
>> >
>> > Regards,
>> > Jaime
>> >
>> >
>> >
>> >
>> >
>>
>> 

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329603
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


RE: Problem deleting structure in an array

2010-01-12 Thread Leigh

> My best guess is if you remove one item it changes the
> structure of the array and when it goes to remove the next
> one it cannot be found?


Yes. 





delete element [#i#] array size = #arrayLen(myArray)# 




When deleting within a loop, iterate in _descending_ order.




delete element [#i#] array size = #arrayLen(myArray)# 





  

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329602
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Problem deleting structure in an array

2010-01-12 Thread Qing Xia

You are looping over the array sequentially from 1 but are you sure your
array key values are sequential from 1 as well?

Your loop goes 1, 2, 3, which means it will expect to find
session.shoppingCart[1].itemid, session.shoppingCart[2].itemid and
session.shoppingCart[3].itemid.  But are you sure those are indeed the key
values in the session array? If your array key values go 1,3,4 then that
will definitely break things.

On Tue, Jan 12, 2010 at 4:31 PM, Chad Gray  wrote:

>
> My best guess is if you remove one item it changes the structure of the
> array and when it goes to remove the next one it cannot be found?
>
> Use CFDump to display the array as you are looping over it to help debug.
>  This way you can see the way the array is changing as you are removing
> items.
>
>
>
> > -Original Message-
> > From: jrmuniz [mailto:jrmu...@sfsailing.com]
> > Sent: Tuesday, January 12, 2010 4:16 PM
> > To: cf-talk
> > Subject: Problem deleting structure in an array
> >
> >
> > Hello:
> >
> > Sorry, I forgot the subject in my last post.
> >
> > I'm having an issue deleting a form structure that is in a shopping cart
> > array.
> > I'm sure it's something simple I'm doing wrong, but it's driving me
> crazy.
> >
> > I have a checkbox to select which items to delete.
> > If only one item is selected there is no error and it works fine.
> > If more than one item is selected then the error is triggered.
> > Strangely, if I resubmit the form after the error it works OK.
> >
> > If I select two items to delete the error is:
> > The error message is "Element at position [3] doesn't
> exist in
> > array"
> >
> > Here is the form code:
> > 
> > 
> > 
> > 
> > 
> > 
> >  > value="#session.shoppingcart[i].quantity#" size="3">
> > 
> > 
> >  > value="#HTMLEditFormat(session.shoppingcart[i].catalog)#" size="10">
> > 
> > 
> >  > value="#HTMLEditFormat(session.shoppingcart[i].description)#"
> > size="40">
> > 
> >  > value="#session.shoppingcart[i].price#" size="3">
> > 
> > 
> > 
> >
> > Here is the cfc code:
> > 
> >
> >   
> >  
> > 
> > 
> >
> > Any help is greatly appreciated.
> >
> > Regards,
> > Jaime
> >
> >
> >
> >
> >
>
> 

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329600
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4


RE: Problem deleting structure in an array

2010-01-12 Thread Chad Gray

My best guess is if you remove one item it changes the structure of the array 
and when it goes to remove the next one it cannot be found?

Use CFDump to display the array as you are looping over it to help debug.  This 
way you can see the way the array is changing as you are removing items.



> -Original Message-
> From: jrmuniz [mailto:jrmu...@sfsailing.com]
> Sent: Tuesday, January 12, 2010 4:16 PM
> To: cf-talk
> Subject: Problem deleting structure in an array
> 
> 
> Hello:
> 
> Sorry, I forgot the subject in my last post.
> 
> I'm having an issue deleting a form structure that is in a shopping cart
> array.
> I'm sure it's something simple I'm doing wrong, but it's driving me crazy.
> 
> I have a checkbox to select which items to delete.
> If only one item is selected there is no error and it works fine.
> If more than one item is selected then the error is triggered.
> Strangely, if I resubmit the form after the error it works OK.
> 
> If I select two items to delete the error is:
> The error message is "Element at position [3] doesn't exist in
> array"
> 
> Here is the form code:
> 
> 
> 
> 
> 
> 
>  value="#session.shoppingcart[i].quantity#" size="3">
> 
> 
>  value="#HTMLEditFormat(session.shoppingcart[i].catalog)#" size="10">
> 
> 
>  value="#HTMLEditFormat(session.shoppingcart[i].description)#"
> size="40">
> 
>  value="#session.shoppingcart[i].price#" size="3">
> 
> 
> 
> 
> Here is the cfc code:
> 
> 
>   
>  
> 
> 
> 
> Any help is greatly appreciated.
> 
> Regards,
> Jaime
> 
> 
> 
> 
> 

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329597
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4