【问题标题】:Lotus Notes - lotusscript Forall loop until specified valueLotus Notes - lotusscript Forall 循环直到指定值
【发布时间】:2016-09-05 16:18:58
【问题描述】:

我在 Lotus Notes 中有数据库,我尝试编写一个 LotusScript,它将遍历所有表单,直到选择指定的表单名称。选择指定的表单名称后,执行其余代码。

基本上,我正在尝试做一个

Forall  Form  In db.Forms
 For form.name <> "Server Information"
    Next form
(loop until "Server Information)
 ...... (rest of code)

End Forall

以下是我正在使用的完整代码。

Sub Initialize

    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim fileName As String
    Dim fileNum As Integer
    Dim headerstring As String
    Dim values As String
    Dim selection As String
    Dim collection As NotesDocumentCollection
    Dim doc As notesdocument
    Dim exportField List As String

    On Error Resume Next

    exportField("ServerName_5") = "ServerName_5"

    Set db = session.CurrentDatabase


    Forall  Form  In db.Forms
        'I WANT TO SKIP ALL FORM NAMES UNTIL "Server Information" is the current or selected form
        'Once the entire loop is complete I don't to go to the next form
        If Isempty(form.Fields) Then
            Messagebox form.Name & " has no fields"
        Else
            If form.Name = "Server Information" Then            
                fieldCount = 0
                msgString = ""
                fileNum% = Freefile()
                fileName$ = "c:\temp\" & form.Name & ".csv"
                Open FileName$ For Output As fileNum%

                Forall field In form.Fields
                    If Iselement(exportField(field)) Then                   
                        msgString = msgString & Chr(10) & _
                        "" & field
                        fieldCount = fieldCount + 1  
                        headerstring=headerstring & |"| &field &|",| 
                    End If
                End Forall

                Write #fileNum%,  |",| & headerstring & |"|
                headerstring=""
            Else
            End If



        End If



        selection = |Form="| & form.Name & |"|
        Set collection=db.Search(selection, Nothing, 0)

        For x = 1 To collection.count
            Set doc =collection.GetNthDocument(x)
            values=""
            Forall formfield In form.Fields
                If Iselement(exportField(formfield)) Then
                    newvalue=doc.GetItemValue(formfield)
                    values=values & |"| & Cstr(newvalue(0)) & |",| 
                End If   
            End Forall

            Write #fileNum%,  |",| & values &|"|
            values=""
        Next

'now check aliases
        If Isempty(form.Aliases) Then
'Messagebox form.Name & " has no aliases"
        Else
            Forall aliaz In form.Aliases
                If aliaz = form.Name Then
                    Goto NextAliaz   'alias is same as form name
                End If
                selection = |Form="| & aliaz & |"|  
                Set collection=db.Search(selection, Nothing, 0)

                For x = 1 To collection.count
                    Set doc =collection.GetNthDocument(x)
                    values=""
                    Forall formfield In form.Fields
                        If Iselement(exportField(formfield)) Then
                            newvalue=doc.GetItemValue(formfield)
                            values=values & |"| & Cstr(newvalue(0)) & |",| 
                        End If   
                    End Forall

                    Write #fileNum%,  |",| & values &|"|
                    values=""
NextAliaz:
                Next
            End Forall
        End If

        Close fileNum%
    End Forall

End Sub

【问题讨论】:

  • 您到底想要做什么?将表单字段写入标题行,然后将带有服务器信息表单的文档导出到 CSV?仅将这些文档中的 ServerName_5 字段写入文件?整个“isElement()”是否在测试文档是否具有该字段?
  • 您的问题是什么?运行代码时会发生什么?以及您期望发生的事情不会发生。请具体。

标签: lotus-notes lotusscript lotus


【解决方案1】:

首先,我教你how to fish

只要您仍处于经典 Notes 开发领域,一种更快、更容易的钓鱼技术:Help\help85_designer.nsf(从 IBM 网站获取,如果您使用的是版本 9,则从 here 获取)

那么,这是你今天的鱼。

do
   (...stuff...)
until (the condition you want)

但是请注意,这会带来可怕的无限循环的典型风险,因为可能永远无法达到所需的条件。

您可能更喜欢使用NotesDatabase 类的getForm() 方法。 不要低估 LotusScript 的面向对象特性和 Domino API 的现成的内置类的力量和表现力。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多