测试环境:Lotus Designer8.5.1
使用ArrayReplace
'SP_AryDelNItem() Dim sourceArray(5) As Integer Dim compareArray(10) As Integer Dim replaceArray(8) As Integer Dim i As Integer Dim vResult As Variant sourceArray(1) = 1 sourceArray(2) = 2 sourceArray(3) = 3 sourceArray(4) = 4 sourceArray(5) = 8 compareArray(1) = 2 compareArray(2) = 4 compareArray(3) = 6 compareArray(4) = 8 replaceArray(1) = 22 replaceArray(2) = 44 vResult = ArrayReplace( sourceArray, compareArray, replaceArray) MsgBox UBound(vResult) For i = 1 To UBound(vResult) msgbox vResult(i) Next
结合FullTrim删除数组中的重复值
Dim sourceArray(5) As String Dim compareArray(10) As String Dim replaceArray(8) As String Dim i As Integer Dim vResult As Variant Dim vTrimResult As Variant sourceArray(1) = "1" sourceArray(2) = "2" sourceArray(3) = "3" sourceArray(4) = "4" sourceArray(5) = "8" compareArray(1) = "2" compareArray(2) = "4" compareArray(3) = "6" compareArray(4) = "8" replaceArray(1) = "" vResult = ArrayReplace( sourceArray, compareArray, replaceArray) MsgBox "before fulltrm is :" & UBound(vResult) vTrimResult = FullTrim(vResult) MsgBox "after fulltrm is :" & UBound(vTrimResult) For i = 1 To UBound(vTrimResult) msgbox vTrimResult(i) Next
整理自定义函数
Function DelOverlapElementOfArray(arrSource As Variant,arrCompare As Variant) As Variant Dim arrReplace(1) As String Dim i As Integer Dim vResult As Variant Dim vTrimResult As Variant arrReplace(1) = "" vResult = ArrayReplace( arrSource, arrCompare, arrReplace) vTrimResult = FullTrim(vResult) DelOverlapElementOfArray = vTrimResult End Function
完整的测试用例:(放在代理中执行)
%REM Agent 测试数组操作 Created Jan 21, 2010 by lion.lv/sunmedia Description: Comments for Agent %END REM Option Public Option Declare Option Base 1 Dim sess As NotesSession Dim dbCur As NotesDatabase Dim docContext As NotesDocument Dim dcUnprocessed As NotesDocumentCollection Dim arrObject() As String Dim arrSource() As String Dim itmObject As NotesItem Dim itmSource As NotesItem Sub Initialize() '得到数组A中Item在数组B中的位置,然后删除 'SP_AryDelNItem() Dim sourceArray(5) As String Dim compareArray(10) As String Dim replaceArray(8) As String Dim i As Integer Dim vResult As Variant Dim vTrimResult As Variant sourceArray(1) = "1" sourceArray(2) = "2" sourceArray(3) = "3" sourceArray(4) = "4" sourceArray(5) = "8" compareArray(1) = "2" compareArray(2) = "4" compareArray(3) = "6" compareArray(4) = "8" replaceArray(1) = "" vTrimResult = DelOverlapElementOfArray(sourceArray,compareArray) For i = 1 To UBound(vTrimResult) msgbox vTrimResult(i) Next End Sub %REM Function DelOverlapElementOfArray Description: Comments for Function %END REM Function DelOverlapElementOfArray(arrSource As Variant,arrCompare As Variant) As Variant Dim arrReplace(1) As String Dim i As Integer Dim vResult As Variant Dim vTrimResult As Variant arrReplace(1) = "" vResult = ArrayReplace( arrSource, arrCompare, arrReplace) vTrimResult = FullTrim(vResult) DelOverlapElementOfArray = vTrimResult End Function