Page 1 of 1
multiple values
Posted: 23 Jul 2019 14:03
by Rafi4
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
Re: multiple values
Posted: 23 Jul 2019 16:55
by Desmanto
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.
Re: multiple values
Posted: 24 Jul 2019 00:36
by Rafi4
hi desmanto
I am trying to remove as you said. but it was removing wrong elements.any modifications required?
from record4
Re: multiple values
Posted: 24 Jul 2019 06:11
by Desmanto
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.
Re: multiple values
Posted: 25 Jul 2019 14:37
by Martin
@Desmanto: The bug was actually caused by a similar problem that was caused by fromJSON converting to an unexpected type internally.
Re: multiple values
Posted: 16 Mar 2020 00:11
by Rafi4
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])}
Re: multiple values
Posted: 18 Mar 2020 19:16
by Desmanto
@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.