I’m currently working with some fields, with multiple values, to make them into lists.
The values the clients will put in the list, will often be the same, and my problem here is how to delete just 1 of the elements.
example, 1 field containing following values:
“Eurocard”
“Eurocard”
“Cash”
“Other”
“Eurocard”
“Cash”
Now, how do i delete the second “Eurocard”?
I havent been able to find any method, since there doesn’t seems to be any @ function allowing the program to delete an element. So i hope anyone here can help me out.
Subject: Deleting specific element in a list in formula.
Hi,
You can use :
- @Unique(). This function removes duplicate values from a text list by returning only the first occurrence of each member of the list.
Exemple:
varSL := Field01
@Unique(varSL) => “Eurocard”, “Cash”, “Other”, “Cash” .
- @For . This function executes one or more statements iteratively while a condition remains true.
Exemple:
varSL := Field01
@For( n :=1; n <=@Elements(varSL) ; n := n + 1;
Temp := @If( @Contains( varSL[n] ; “Eurocard” ) & n = 2; Temp ; Temp : varSL[n] ) ;
FIELD Field01 = Temp.
Karim.
Subject: RE: Deleting specific element in a list in formula.
Thanks for you response, allthough finding the uniques wasn’t quite my problem, just needed to delete 1 of the eurocards, and not all except 1.
Anyway i found my own solution, and it is here if anyone else will need it, i just hope you can find you way around in it:
tempList := originalList;
@If( numberOfelements = 1 & lineToDelete = 1; tempList := “”;
(@If( lineToDelete = 1; (_temp := @Subset(tempList ;(-numberOfelements +1))) & (tempList := _temp);
(@If( numberOfelements = lineToDelete; (_temp := @Subset(tempList ;(numberOfelements -1))) & (tempList := _temp);
(_temp1 := @Subset(tempList ;(lineToDelete-1))) &
(_temp2 := @Subset(tempList ;(-numberOfElements +lineToDelete))) &
(tempList := _temp1 : _temp2)
)))));
FIELD originalList := tempList;
What happends here is in basic, the list is copyed to a temporary variable, being split into 2 different lists, the part before the element to delete, and the part after. And after the run, it gathers the two parts and puts it back into the original list.
Beside that, it checks if theres only 1 element, if the client is trying to delete the first, or the last.
If anyone at any time have a shorter code than this, which does the same, please write it. This works, but gives a load of code.
Subject: RE: Deleting specific element in a list in formula.
Have you see my second solution ? I use @for :
varSL := YourFiled ;
@For( n := 1; n <=@Elements(varSL) ; n := n + 1 ;
Temp := @Trim( @If( @Contains( varSL[n] ; “Eurocard” ) & n = 2 ; Temp ; Temp : varSL[n] ) )
) ;
FIELD YourFiled := Temp ;
Karim.