Tip

Extract Items In An Array

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.