multiple values

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
Rafi4
Posts: 281
Joined: 01 Dec 2017 05:23

multiple values

Post by Rafi4 » 23 Jul 2019 14:03

hi Martin and all
how can I remove multiple values from list and map?

example
list values =1,2,3,4,5,6,7,8,9,10

in above example list how can I remove 1,2,3 values from list using multi choice in input Dialog?

from record4
No.1 Automation app in play store Automagic Premium
Samsung Galaxy j2 non rooted.
Android 5.1.1

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: multiple values

Post by Desmanto » 23 Jul 2019 16:55

Create the new list using script

Code: Select all

choice = newList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
Then use this list in the input dialog - multiple choice, {choice,listformat,comma}

After that, put script to remove the {choice} based on the {value} you have chosen in input dialog. For other list which contains strings, you can use this single line script.

Code: Select all

removeAllElementValues(choice, value);
However, since {choice} has all the elements in number type and the output value of the input dialog always string type, the above code won't remove the {choice} element, because of type mismatch (number vs string).
You have to convert the {value} from string to number first by multiplying it with 1. But that is too long, better just loop remove using the indices (plural version of index)

Code: Select all

for(i in indices)
  removeElement(choice, i);
check the result using debug dialog to make sure.

@Martin : Can it be possible that the previous removeAllElementValues() bug is caused by this kind of type mismatch? If yes, do Automagic try to match the vartype before removing? There can be some logic flaw here, which can result in catastrophy for someone's flow. And it can be very difficult to trace to this cause. I think we may need extra information, that the value given by input dialog - single choice/single choice menu/multiple choices are always in string type.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
Rafi4
Posts: 281
Joined: 01 Dec 2017 05:23

Re: multiple values

Post by Rafi4 » 24 Jul 2019 00:36

hi desmanto
I am trying to remove as you said. but it was removing wrong elements.any modifications required?

from record4

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: multiple values

Post by Desmanto » 24 Jul 2019 06:11

Try exactly my code above first and see if it is working as expected. Then modify a little for the list element, try again.

Most likely you remove the wrong element because you add some new element when showing it in the multiple choices.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: multiple values

Post by Martin » 25 Jul 2019 14:37

@Desmanto: The bug was actually caused by a similar problem that was caused by fromJSON converting to an unexpected type internally.

User avatar
Rafi4
Posts: 281
Joined: 01 Dec 2017 05:23

Re: multiple values

Post by Rafi4 » 16 Mar 2020 00:11

Hi Martin and all
After a long time Finally I have got the accurate solution for removing multiple values.

Code: Select all

global_a = newList("Wonderful","Amazing","Useful","Genius","Accurate","Record4")
I think this is the right solution. Any modifications ? Please post.
From record4

Code: Select all

set = reverse(indices);
for (i in [0 to length  (set)-1])
{removeElement(global_a,set[i])}
No.1 Automation app in play store Automagic Premium
Samsung Galaxy j2 non rooted.
Android 5.1.1

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: multiple values

Post by Desmanto » 18 Mar 2020 19:16

@Rafi4 : Oh, I see now. My bad, I never use this method actually in any of my script.

We must remove from the last indices first. Since if we remove the first indices, the rest of the index will be shifted down and the order now messed up. By reversing the indices first, we make sure it start removes from the last choice. Thanks for showing the correct method to do this.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply