Extract Items In An Array

This Content Component encountered an error
There are many situations in which you need to extract certain values from an
item using Lotus Script. A simple example is a multivalue authors field where
you need to remove an author from the document. The following SubRoutine will
help you remove the value in the item and also push the values below it upwards
so that you do not have any blank values in the item.
Sub Extract(ID_Item As Notesitem, Value_To_Replace As String)
'Two Temporary arrays to hold the values
Dim Temp_Arr1() As String
Dim Temp_Arr2() As String

'Get the No of Values in the Item
Dim No_Of_Entries As Integer
No_Of_Entries=0
Forall i In ID_Item.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-2) As String

'Fill all the values in the item into an array
For v=0 To (No_Of_Entries-1)
Temp_Arr1(v) = ID_Item.Values(v)
Next

Count%=0

For v=0 To No_Of_Entries-1
If Temp_Arr1(v) = Value_To_Replace Then Goto Here
Temp_Arr2(Count%) = Temp_Arr1(v)
Count%=Count%+1
Here:
Next
ID_Item.values = Temp_Arr2
End Sub


********************************************************************************
****************************
Review for: Extract Items in an Array
By: Jeff Cassens
Company: SOLARCOM, Inc.
********************************************************************************
****************************
There are ways to do this much more efficiently. For instance, you don't need
to count the items in an array, you just use UBound(). And PLEASE stay away
from GOTOs!

Here is my suggestion for a function that takes a passed array as a variant and
a text string to pluck out:

Function Extract(aryOld As Variant, txtReplace As String) As Variant

Dim aryNew() As String 'Placeholder for returned version
Dim i, j As Integer 'Loop counters

j = 0 'initialize new loop counter
For i = 0 To Ubound(aryOld) 'go through passed array
If aryOld(i) <> txtReplace Then 'if not skipped value
Redim Preserve aryNew(j + 1)' expand new array by one
aryNew(j) = aryOld(i) ' put value in last place
j = j + 1 ' add one to j for next value
End If
Next

Extract = aryNew 'Return placeholder array as variant
End Function
********************************************************************************
********
Just my $.02,
Jeff Cassens
CLP Principal Application Developer (R5)
********************************************************************************
******************************
This was first published in November 2000

Dig deeper on Lotus Notes Domino Administration Tools

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close