Extract Items In An Array



Download: IT certifications that stand out
Are you looking to advance your career? Expand your knowledge? Boost your credibility? Our editors put together this complimentary 19-page guide on everything you need to know about obtaining an IT certification—with special attention given to cloud and desktop certifications.
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
You also agree that your personal information may be transferred and processed in the United States, and that you have read and agree to the Terms of Use and the Privacy Policy.
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)
********************************************************************************
******************************
Start the conversation
0 comments