Event handler app

this is my code for an event handler app and my button remove is not working because I don't understand what index to put in or if I should completley change my code for that button

You used the wrong For Each block to find what to remove.

Instead, use the For Each Number From 1 to length of list(your global list, which you should name TaskList.)

This way, you will have the index in the Number variable when it comes time to remove an item.

is this what youre saying to do?

Oops, I forgot that the index numbers collapse when you remove them.

Reverse the direction of travel:

From Number = length of list (global list) to 1 by -1

Use the number from the loop as the index for the delete, not that global index variable 'index' which is useless.

Screenshot 2024-04-22 1.17.30 PM

this is what i switched my code to but it is still not working

1 Like

Screenshot 2024-04-22 9.13.46 PM

this is my code it is still not deleting the item from the list

i think it might be because there is an infinite loop

why do you think so? how do you use that procedure?
how does the list look like in the beginning and after using that procedure?
show us a screenshot including Do it results

where exatly do you think, there is an infinite loop?

Taifun

use Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools
Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

here is all of my code

i showed my code above!!!

As you can see it works. Check your list before and after your procedure like Taifun has suggested you.

In your blocks you are not displaying the list again once you have removed some items.

1 Like

Alternatively:

1 Like

thank you! could you explain how this works I'm a little confused

Yes, as @ABG indicated above, you use a loop in reverse order from the length of the list to 1 (so you go thorough all the index numbers of your list).

For each number (index=number) yo take that element of the list and check if that element contains the "text". If yes, then remove that element (index = number).

If, for example, your list has 7 elements, it will start by 7.

In the fist iteration "number"=7. It checks if the element 7th of the list contains the text. In my example is "seven" contains "ve". Like yes, then it removes the element 7th of the list.

In the next iteration "number"=6. It checks if the 6th element of the list contains "ve". Like not, it continues with the next one....and so on.