Manage Learn to apply best practices and optimize your operations.

Remove from text-list

The function can be used to remove all occurrences of the specified item as well as only the first one.

You Can View User Feedback To This Tip

There was shortly a tip about removing an entry from a text-list, which was almost the same as I did back in the R4 timeframe. The function is pretty useful, as it mimics the behavior, that the UI is showing: if you remove an entry from a multivalue-textfield, it gets automatically compressed (oh, well, which is not always looked for, as if you have it in a table, the lines get troubled). At least, as long as you don't have any other blank entries or entries, that have a space (" ") in it, you can do the same thing in R5 with as little as a handful of lines, as there are some really nice new array-functions since R5

The function can be used to remove all occurrences of the specified item as well as only the first one. If the source is neither a String-Array nor a simple string, the function returns a Null-Value.

Function RemoveFromTextList(SourceArray As Variant,RemoveItem As 
String, AllFlag As Integer)As Variant ' Removes the first found Item from the Source-Array ' If you set the AllFlag, it will recurse until there are no items in the list Dim Ind As Variant ' to find the position Dim ArrayType As String Dim TempArray As Variant ' used that the source-Array is left untouched TempArray=SourceArray ArrayType = Typename(TempArray) Select Case ArrayType Case "STRING" : ' Simple string, no array If TempArray=RemoveItem Then RemoveFromTextList="" Else RemoveFromTextList=TempArray End If Case "STRING( )" ' String-Array, As expected Ind = Arraygetindex(TempArray,RemoveItem) If Not Isnull(Ind) Then If AllFlag Then Do TempArray(Ind)="" Ind = Arraygetindex(TempArray,RemoveItem) Loop Until Isnull(Ind) Else TempArray(Ind)="" End If RemoveFromTextList=Fulltrim(TempArray) Else RemoveFromTextList=Fulltrim(TempArray) End If Case Else: RemoveFromTextList=Null ' Error, no strings End Select End Function


  • This tip will work on R5 only as new R5 array functions are used. But if your users use both R4 and R5, it would be a problem. Below is a different version of "remove from text list" which is quite simple and works for both R4 and R5. This little script contains two routines, the first one, RemoveFromTextList, which removes an item from a text list; this first routine calls the second routine, RemoveFromList, which can be used as a more generic routine that removes any item from an array and returns the updated array.


    Sub RemoveFromTextList(fieldName As String, doc As NotesDocument, compareValue As String)
      'The parameters passed in are the name of the text list field on the document, the document itself, 
      'and the value to be removed from the list.  The field will be replaced in the document with the updated list. 
      'It is up to the caller routine to save the doucment.
      Dim item As NotesItem
      Set item = doc.GetFirstItem(fieldName)
      'Replace the field with the updated list of values (could be empty)
      Call doc.ReplaceItemValue(fieldName, RemoveFromList(item.Values, compareValue))
    End Sub
    Function RemoveFromList(inArray As Variant, compareValue As Variant) As Variant
      'This routine will remove any items that match compareValue from inArray.  
      Dim n As Integer
      Dim newVals() As Variant
      'Delete the input value from the input array
      n = Lbound(inArray)
      Redim newVals(n)
      Forall value In inArray
        'Only copy a value if it isn't equal to the compare value (the one that's to be removed)
        If value < > compareValue Then
          Redim Preserve newVals(Lbound(inArray) To n)
          newVals(n) = value
          n = n + 1
        End If
      End Forall
      RemoveFromList = newVals
    End Function
    —Long Yu

Dig Deeper on Domino Resources - Part 4

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...