Lotus notes 如何在LotusScript中创建列表数组

Lotus notes 如何在LotusScript中创建列表数组,lotus-notes,lotusscript,Lotus Notes,Lotusscript,我有这样的代码: Dim MyACL As Variant Dim Person As List Redim MyACL(0) Person("Detail1") = "Something1" . . . Person(Detailx") = "Somethingx" ForAll name in names ReDim Preserve MyAcl(Ubound(MyACL)+1) Per

我有这样的代码:

    Dim MyACL As Variant
    Dim Person As List

    Redim MyACL(0)

    Person("Detail1") = "Something1"
    .
    .
    .
    Person(Detailx") = "Somethingx"

    ForAll name in names
       ReDim Preserve MyAcl(Ubound(MyACL)+1)
       Person("Name") = name
       MyACL = ArrayAppend(MyACL,Person)
   End ForAll
Dim max As Integer
max = 0
ForAll thisName In names
    ReDim Preserve MyAcl(max)
    Person("Name") = thisName
    MyACL(max) = Person
    max = max + 1
End ForAll
person = MyACL(1)
detail = person("Detail1")

它抛出错误“类型不匹配”。您知道如何创建列表数组吗?谢谢。

如果您明确地将变量声明为数组(就像您在Redim语句中所做的那样),则无法使用arrayappend对其进行“重新分配”

而且没有必要这样做。只需将行
MyACL=ArrayAppend(MyACL,Person)
替换为
MyACL(Ubound(MyACL))=Person

注意:使用该示例代码,您永远不会填充MyACL(0),因为填充的第一个元素是MyACL(1)

要开始用元素0填充数组,需要如下更改代码:

    Dim MyACL As Variant
    Dim Person As List

    Redim MyACL(0)

    Person("Detail1") = "Something1"
    .
    .
    .
    Person(Detailx") = "Somethingx"

    ForAll name in names
       ReDim Preserve MyAcl(Ubound(MyACL)+1)
       Person("Name") = name
       MyACL = ArrayAppend(MyACL,Person)
   End ForAll
Dim max As Integer
max = 0
ForAll thisName In names
    ReDim Preserve MyAcl(max)
    Person("Name") = thisName
    MyACL(max) = Person
    max = max + 1
End ForAll
person = MyACL(1)
detail = person("Detail1")
但是:我不知道,这是否是一个好主意,因为您不能直接访问Person的“Detail1-Property”

差不多

detail = MyACL(1)("Detail1")
这是不可能的。您必须始终具有这样一个临时变量:

    Dim MyACL As Variant
    Dim Person As List

    Redim MyACL(0)

    Person("Detail1") = "Something1"
    .
    .
    .
    Person(Detailx") = "Somethingx"

    ForAll name in names
       ReDim Preserve MyAcl(Ubound(MyACL)+1)
       Person("Name") = name
       MyACL = ArrayAppend(MyACL,Person)
   End ForAll
Dim max As Integer
max = 0
ForAll thisName In names
    ReDim Preserve MyAcl(max)
    Person("Name") = thisName
    MyACL(max) = Person
    max = max + 1
End ForAll
person = MyACL(1)
detail = person("Detail1")

这是一个典型的示例,说明您希望改用类并创建该类的数组。该类可以包含一个列表(以及其他内容)。可以非常强大

更新:

使用类的好处是,您可以在类中添加业务逻辑,并且很容易在以后使用更多功能对其进行扩展。下面是一个基于上述问题的示例,但具有附加功能

Class PersonObject
    Public PersonAttribute List As String
    Public NABdoc As NotesDocument
    Public PersonName As String

    Public Sub New(personname As String)
        Dim nab as New NotesDatabase("Server/Domain","names.nsf")
        Dim view as NotesView
        '*** Get person document from Domino directory
        Set view = nab.GetView("PeopleByFirstName")
        Set me.NABdoc = view.GetDocumentByKey(personname)
        '*** Set person name in object
        me.PersonName = personname
        '*** Set some values from person doc
        me.PersonAttribute("Email") = GetValue("InternetAddress")
        me.PersonAttribute("Phone") = GetValue("OfficePhone")
    End Sub

    Public Function GetValue(fieldname as String) as String
        GetValue = me.NABdoc.GetItemValue(fieldname)(0)
    End Function

    Public Sub AddAttribute(attributename as String, value as string)
        me.PersonAttribute(attributename) = value
    End Sub

End Class
现在,您可以使用该类(并假设名称是唯一名称的列表)非常轻松地构建列表:

希望这能让您了解如何使用类

您还可以查看以下两篇关于面向对象Lotusscript基础知识的博客文章:


谢谢你,同时我自己也找到了答案,它看起来很像你的解决方案,而且很有效:)你所说的问题对我来说很好,因为我将在所有循环中使用它。在这种情况下,我可以直接访问它。我完全同意你的看法,一个类可以更好地完成这个任务,但是没有任何示例代码,这个答案不够具体…为什么你认为使用类更好?我在考虑这个选项,但列表数组对我来说更简单。然而,我问过的每个人都建议使用课堂。你有什么具体的理由,为什么更好?