如何在LotusScript中创建列表数组

Jak*_*ubM 2 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)
       Person("Name") = name
       MyACL = ArrayAppend(MyACL,Person)
   End ForAll
Run Code Online (Sandbox Code Playgroud)

它抛出错误"类型不匹配".你知道吗,如何创建一个列表数组?谢谢.

Kar*_*son 6

这是您想要使用类的典型示例,并创建该类的数组.反过来,该类可以包含列表(以及其他内容).可以非常强大!

更新:

使用类的好处是您可以在类中添加业务逻辑,并且以后可以使用更多功能扩展它.以下是基于上述问题的示例,但具有其他功能.

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
Run Code Online (Sandbox Code Playgroud)

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

Dim person List As PersonObject
Dim personname As String

ForAll n in names
    '*** Create person object based on name
    person(n) = New PersonObject(n)
    '*** Store additional info about this person
    person.AddAttribute("Age","35")
End ForAll    
Run Code Online (Sandbox Code Playgroud)

希望这能让您了解如何使用课程.

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

http://blog.texasswede.com/object-oriented-lotusscript-for-beginners-part-1/

http://blog.texasswede.com/object-oriented-lotusscript-for-beginners-part-2/