首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从视图中获取数据的LotusScript

从视图中获取数据的LotusScript
EN

Stack Overflow用户
提问于 2015-02-25 15:01:08
回答 2查看 2.8K关注 0票数 1

我对很陌生,我正在尝试从视图中获取数据并将其保存到字符串中。但是每次我这样做,我都会得到初始化对象变量在第36行中没有设置的错误。在我的多米诺骨牌设计师第36行就在ItemNames(6)下面。

我试图使用我的朋友的代码,我和我得到了同样的错误,而他的工作没有问题。

请帮帮我,我不顾一切地想让这件事成功。

代码语言:javascript
复制
Sub Initialize

    On Error GoTo ERRSUB

    Dim nSession As New NotesSession
    Dim nDb As NotesDatabase
    Dim nDoc As NotesDocument
    Dim view As NotesView
    Dim nitem As NotesItem

    Dim strRecord As String
    Dim DataString As String
    Dim nList List As String
    Dim ListCount As Integer
    Dim FirstLine As String 
    Dim counter As Integer
    counter = 0

    Dim ItemNames(6) As String  
    ItemNames(0) = "Date"
    ItemNames(1) = "Name"
    ItemNames(2) = "Name of buyer"
    ItemNames(3) = "Naziv of project"
    ItemNames(4) = "value"
    ItemNames(5) = "source"
    ItemNames(6) = "status" 

    Set nDb = nSession.Currentdatabase
    Set view = nDb.Getview("X_view_1")
    Set ndoc = view.Getfirstdocument()

    Do Until (ndoc Is nothing)

        ForAll item In ItemNames
            Set nitem = ndoc.Getfirstitem(item)
            DataString = nitem.Values & ";"
            counter = counter + 1
        End ForAll

        DataString = DataString & Chr(13)

        Set ndoc = view.Getnextdocument(ndoc)
    Loop    

    GoTo DONE

    DONE:   

    MessageBox counter
    Exit Sub    

    ERRSUB:

    Call logger("Error",nSession.currentagent.name,"Initialize","","")
    GoTo done       

End Sub
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-25 15:13:40

第36行是DataString = nitem.Values & ";"。错误是nitem没有正确设置。可能该项目在某个文档中不可用。对nitem的测试不是Nothing

将ForAll循环更改为

代码语言:javascript
复制
    ForAll item In ItemNames
        Set nitem = ndoc.Getfirstitem(item)
        If Not nitem Is Nothing then
            DataString = DataString & nitem.Text
        End If 
        DataString = DataString & ";"
        counter = counter + 1
    End ForAll
票数 3
EN

Stack Overflow用户

发布于 2015-02-25 17:12:52

我会把它写成这样的。

我在您的代码中注意到:*您在错误处理程序中使用GoTo,应该是一份简历。*当代码到达时,您已经完成了"GoTo完成“,这是不需要的。*声明了几个不使用的变量。*你不用太多的错误检查,克努特的建议是个不错的建议。

这是我的建议,这就是我要导出的观点:

代码语言:javascript
复制
Sub Initialize
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim view As NotesView
    Dim col As NotesViewEntryCollection
    Dim entry As NotesViewEntry
    Dim DataString As String
    Dim cnt List As Long

    On Error GoTo errHandler
    Set db = session.Currentdatabase
    Set view = db.Getview("X_view_1")
    Set col = view.AllEntries
    '*** Set counters
    cnt("total") = col.Count
    cnt("processed") = 0
    '*** Loop though all view entries, much faster that documents
    Set entry = col.GetFirstEntry()
    Do Until entry Is Nothing
        '*** Update status bar every 100 documents
        If cnt("processed") Mod 100 = 0 Then 
            Print "Processed " & cnt("processed") & " of " & cnt("total") & " documents."
        End If
        '*** Read view columns and add to string
        ForAll cv In entry.ColumnValues
            DataString = cv & ";"
        End ForAll
        '*** Add line break to string
        DataString = DataString & Chr(13)
        '*** Update counter and get next entry in view collection
        cnt("processed") = cnt("processed") + 1
        Set entry = col.GetNextEntry(entry)
    Loop    

exitSub: 
    MsgBox "Processed " & cnt("processed") & " of " & cnt("total") & " documents.",,"Finished" 
    Exit Sub    

errHandler:
    Call logger("Error",session.CurrentAgent.Name,"Initialize","","")
    Resume exitSub       
End Sub

另一种方法是直接从NotesDocument读取该值:

代码语言:javascript
复制
DataString = doc.GetItemValue(item)(0) & ";"

当然,这只会读取任何多值字段的第一个值,但您可以这样修复:

代码语言:javascript
复制
DataString = Join(doc.GetItemValue(item),"~") & ";"

这将在每个值之间加上一个~,如果有一个以上的值,那么您可以按照自己喜欢的方式处理。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28722325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档