Deleting One Item in a Text List

Mindwatering Incorporated

Author: Tripp W Black

Created: 08/26/1999 at 07:51 PM

 

Category:
Notes Developer Tips
Forms/Subforms, Formulas

Objective:
Remove an entry (string) from an array/list of values in a field.



******************************* Solution 1 ****************************************

Function FldRemoveStr(srcFld As NotesItem, killstr As String, replacestr As String) As Variant
' this function removes killstr from a list of string values in srcFld

On Error Goto FErrorHandler

' temporary arrays to hold the values
Dim Temp_Arr1() As String
Dim Temp_Arr2() As String
Dim No_Of_Entries As Integer

If (srcFld Is Nothing) Then
Redim Temp_Arr1(0) As String
Temp_Arr1(0) = ""
FldRemoveStr = Temp_Arr1()
Exit Function
End If
If (srcFld.Text = "") Then
Redim Temp_Arr1(0) As String
Temp_Arr1(0) = ""
FldRemoveStr = Temp_Arr1()
Exit Function
End If

' get number of values in the item
No_Of_Entries=0
Forall i In srcFld.values
No_Of_Entries=No_Of_Entries+1
End Forall

' now that we know the number of values in the item, Redim both the arrays
Redim Temp_Arr1(No_Of_Entries-1) As String
Redim Temp_Arr2(No_Of_Entries-1) As String ' cannot subtract two, or if only one value in srcFld, will go negative

' fill all the values in the item into the first array
For v=0 To (No_Of_Entries-1)
Temp_Arr1(v) = srcFld.Values(v)
Next

Count%=0

For v=0 To No_Of_Entries-1
If (Temp_Arr1(v) = killstr) Then
If Not (replacestr = "") Then
Temp_Arr2(Count%) = replacestr
Count%=Count%+1
End If
Goto Here
End If
Temp_Arr2(Count%) = Temp_Arr1(v)
Count%=Count%+1
Here:
Next v

' return filtered array
FldRemoveStr = Temp_Arr2

FExit:
Exit Function

FErrorHandler:
Print "(FldRemoveStr) Error importing line: " & linetxt & ", Error: " & Cstr(Err) & ", " & Error$ & ", code line: " & Cstr(Erl) & "."
Resume FExit
End Function




******************************* Solution 2 ****************************************
Author:
Greg Douglass
Date:
Thursday, 8/05/99 5:25 AM EDT
Subject:
Re: Deleting one element from a list




Try This


items = notesitem.values
forall i in items
if i = "value to remove" then
i = ""
end if
next
notesitem.values = items

Greg.
Greg_Douglass@*******.com

******************************* Solution 3 ****************************************
Author:
Jo Bruce
Date:
Thursday, 8/05/99 6:50 AM EDT
Subject:
Re: Deleting one element from a list




This is using formulas rather than script....

It is the formula behnd a Remove Entry button for a dynamic table so it is removing one value in the same
position from several fields :


Items := @Elements(CMNo);
@If(@IsDocBeingEdited; ""; @Command([EditDocument])) ;
LNo := @If(Items > 1; @TextToNumber(@Prompt([OKCANCELEDIT]; "Car Mileage Information - Remove Entry.";
"Enter the Number of the row that you wish to Remove. There are " + @Text(Items) + " rows available."; 0));
1);
@If(Lno > Items | Lno <= 0; @Do(@Prompt([OK]; "Car Mileage Information. Error."; "Invalid Number. The number
MUST be between 1 and " + @Text(Items) + "."); @Return(0)); "");

FIELD CMNo := @If(Items = 1; @DeleteField; @Subset(CMNo; Items - 1));

FIELD CMDate := @If(Items = 1; @DeleteField; LNo = 1; @Subset( CMDate; Lno - Items) ; LNo > 1 & LNo !=
Items; @Subset( CMDate; Lno - 1 ) : @Subset( CMDate; LNo - Items); LNo = Items; @Subset(CMDate; Items -
1); "");
FIELD CMFrom := @If(Items = 1; @DeleteField; LNo = 1; @Subset( CMFrom; Lno - Items) ; LNo > 1 & LNo !=
Items; @Subset( CMFrom; Lno - 1 ) : @Subset( CMFrom; LNo - Items); LNo = Items; @Subset(CMFrom; Items -
1); "");
FIELD CMTo := @If(Items = 1; @DeleteField; LNo = 1; @Subset( CMTo; Lno - Items) ; LNo > 1 & LNo != Items;
@Subset( CMTo; Lno - 1 ) : @Subset( CMTo; LNo - Items); LNo = Items; @Subset(CMTo; Items - 1); "");
FIELD CMMiles := @If(Items = 1; @DeleteField; LNo = 1; @Subset( CMMiles; Lno - Items) ; LNo > 1 & LNo !=
Items; @Subset( CMMiles; Lno - 1 ) : @Subset( CMMiles; LNo - Items); LNo = Items; @Subset(CMMiles; Items -
1); "");
FIELD CMvat := @If(Items = 1; @DeleteField; LNo = 1; @Subset( CMvat; Lno - Items) ; LNo > 1 & LNo != Items;
@Subset( CMvat; Lno - 1 ) : @Subset( CMvat; LNo - Items); LNo = Items; @Subset(CMvat; Items - 1); "");
FIELD CMPur := @If(Items = 1; @DeleteField; LNo = 1; @Subset( CMPur; Lno - Items) ; LNo > 1 & LNo != Items;
@Subset( CMPur; Lno - 1 ) : @Subset( CMPur; LNo - Items); LNo = Items; @Subset(CMPur; Items - 1); "");

@PostedCommand([ViewRefreshFields]);
NULL

Author:
cpinheiro@mail.******.pt
Date:
Thursday, 8/05/99 7:07 AM EDT
Subject:
Re: Deleting one element from a list


******************************* Solution 4 ****************************************

Hi.
You can assign the field contents to a variant. This variant will contain a list of values - all the items of the
field.
You can work this variant as an array. So, you can remove the items that you want and finally you assign the
variant to the field.
Example: this example will remove the 2º item from the field x (the first position of the variant is 0)

v = doc.x
for i = 1 to UBound( v ) - 1
v( i ) = v( i + 1 )
next
redim v( UBound( v ) - 1 )
doc.x =v

Best regards
cpinheiro@mail.*********.pt


previous page