Notes中幾個處理多值域的通用函式

hannover發表於2016-02-03

1.查詢出查詢內容在多值域中的索引值

getItemIndex(域名,域值,文件)

Public Function getItemIndex(ByVal fieldName As String, ByVal itemVal As Object, 
ByVal doctt As NotesDocument) As Integer Dim i As Integer Dim j As Integer Dim item As NotesItem item = doctt.GetFirstItem(fieldName) j = Ubound(item.Values) For i = 0 To j If itemVal = item.Values(i) Then getItemIndex = i Exit Function End If Next getItemIndex = -1 End Function

2.刪除多值域中的資料
delItemValues(多值域名,更改的索引值,所在文件物件)

Public Sub delItemValues(ByVal fieldName As String, ByVal index As Integer, ByVal doctt As NotesDocument)
    Dim i As Integer
    Dim temp() As Object
    Dim item As NotesItem
    item = doctt.GetFirstItem(fieldName)
    Dim j As Integer

    j = Ubound(item.values)
    '-----------
    If j = 0 Then
        '當J為0時,即僅有一個值,給予空值即可
        Call doctt.ReplaceItemValue(fieldName, "")
        Exit Sub
    End If
    '------------
    If Trim(item.Values(0)) = "" Then
        index = j
    End If
    If index > j Then
        '仍然做為最後一個資料加入  
        j = j + 1  '索引位僅增加1
        index = j  '重定義索引位,防止超出範圍
    End If

 Redim temp(j-1) As Variant '重定義陣列 
    For i = 0 To index - 1
        temp(i) = item.values(i)
    Next

    For i = index To j - 1
        temp(i) = item.values(i + 1)
    Next

    Call doctt.ReplaceItemValue(fieldName, temp)
    'End If
    'End If
End Sub

3.更改多值域中的資料
editItemValues(多值域名,更改的索引值,更改的內容,所在文件物件)

Public Sub editItemValues(ByVal fieldName As String, ByVal index As Integer, ByVal itemVal As Object, 
ByVal doctt As NotesDocument) Dim i As Integer Dim temp() As Object Dim item As NotesItem item = doctt.GetFirstItem(fieldName) Dim j As Integer j = Ubound(item.values) If Trim(item.Values(0)) = "" Then index = j End If If index > j Then '仍然做為最後一個資料加入 j = j + 1 '索引位僅增加1 index = j '重定義索引位,防止超出範圍 End If Redim temp(j) As Variant '重定義陣列 For i = 0 To j If i = index Then temp(i) = itemVal Else temp(i) = item.values(i) End If Next Call doctt.ReplaceItemValue(fieldName, temp) 'End If 'End If End Sub

 

相關文章