Remove list item: Attempt to remove item 0 of the list

Hi all,

Small issue that I can't quite seem to wrap my head around. I have a grocery app that I'm developing for a project, users can add and remove items to their grocery list, as usual. When a user deletes an item from their grocery list, it checks against a predefined list to see if it's a perishable item and asks if they would like to add it to another list, with an expiry date, so that they can better track items that may be close to expiring and plan to use accordingly.

The issue is that when I remove more than one item from the perishables list, I get a the below error;

This only seems to happen when perishable_date_picker is set to .Day, if I set it to .Text for example, it removes the line item without an issue.

I can see from the Do It that the 'Index in list' block has a value of 3 if I have 3 items currently on the list, but if I remove 1, the Do It shows that the value drops to 0. This clearly causes the error for when I remove more than one item from the list, but I'm unsure as to why.

shopping_list_app.aia (8.3 KB)

Any insights would be much appreciated.

it looks like you are trying to remove some item from a list, but this list does not contain this item.
Make sure the item is in this list before removing it.

I'm pretty confident the item is on the list, unless the way that I'm calling it is incorrect? Though, the issue arises when I delete more than one item from the list so it works to a point.

Here's the list with 3 items in it;

This is after I remove 1 item from the list;

Then the code throws the Runtime Error if I attempt to remove any more items.

Note that it only does this for the 'date' portion of the code. If I remove that, it works fine when removing just the item (eggs, bread, etc).

If you are trying to delete an item from this list which doesn't exist this index will be 0...

Where are you changing the date?

If you want to remove from both list the same item (index) do something like this:

1 Like

I recommend a global variable-ectomy for those two lists you keep in TinyDB.

Keeping global variables with copies of the real data in TinyDB trips you up when the variables get out of sync with the TinyDB data.

Use local variables when you need to update TinyDB lists, to force you to use fresh data.

2 Likes

This is great, thanks!

For reference, the date is being added on the first red circled block in my initial post.

I can see that this is the case with the solution that Ramon provided, though I'm a little perplexed as to why it happens. Especicially when changing the format to something else allows it to work fine.

Why does that happen?

Ramon is a quick study.

The burden of maintaining global variables is not obvious.

Give him time.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.