Five Reusable Lotusscript Functions For Working With Lists

When working with lists, the same functions seem to come up time and time again. We thought that it would be useful...

to group some of these LotusScript functions together so that you could find them in a single resource. Here are the basics that are covered: 1. Remove from List 2. Add to List 3. Remove Item from List 4. Entry in List 5. Remove Range from List Function RemoveFromList (Value As Variant, ValueList As Variant) Dim tmpValueList() As String x = 0 Redim Preserve tmpValueList(x) Forall vals In ValueList If Not Value = vals Then Redim Preserve tmpValueList(x) tmpValueList(x) = vals x = x + 1 End If End Forall RemoveValueFromList = tmpValueList End Function Function AddToList (Value As Variant, ValueList As Variant) Dim tmpValueList As Variant ' Load the array element by element so that the datatype is preserved Redim tmpValueList(Ubound(ValueList)) For i = 0 To Ubound(ValueList) tmpValueList(i) = ValueList(i) Next ' Determine if we are dealing with a new list, if absolutely no values in the first entry, then add new value to 0 If Ubound(tmpValueList) = 0 And Cstr(tmpValueList(0)) = "" Then x = 0 Else x = Ubound(tmpValueList) + 1 End If Redim Preserve tmpValueList(x) tmpValueList(x) = Value AddToList = tmpValueList End Function Function RemoveItemFromList (intItem As Integer, ValueList As Variant) ' *** intItem should be passed in zero based as well as ValueList Dim tmpValueList() As Variant Dim intItemCnt As Integer ' Init the temporary list Redim tmpValueList(0) intItemCnt = 0 For x = 0 To Ubound(ValueList) If Not intItem = x Then 'Not equal, we must keep this one in the list Redim Preserve tmpValueList(intItemCnt) tmpValueList(intItemCnt) = ValueList(x) intItemCnt = intItemCnt + 1 ' Count the items we have kept so that we can adjust the array properly End If Next RemoveItemFromList = tmpValueList End Function Function EntryInList (Value As Variant, ValueList As Variant) As Integer ' This will return a 1 based value if the position in the list EntryInList = 0 i = 1 Forall Entries In ValueList If Entries = Value Then EntryInList = i Exit Function End If i = i + 1 End Forall End Function Function RemoveRangeFromList (intStartPos As Integer, intEndPos As Integer, varInput As Variant) As Variant Dim tmpList() As Variant Dim intPosCnt As Integer intPosCnt = 0 For i = 0 To Ubound(varInput) If i < intStartPos Or i > intEndPos Then Redim Preserve tmpList(intPosCnt) tmpList(intPosCnt) = varInput(i) intPosCnt = intPosCnt + 1 End If Next RemoveRangeFromList = tmpList End Function

This was first published in November 2000

Dig Deeper



Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...