我正在运行一个Lotusscript Agent"在邮件到达之前"。我需要它来获取"#"之后的主题行中的文本。符号。无论我如何尝试获取Subject字段(Evaluate,getFirstItem,getItemValue等),我总是会遇到错误。通常是未设置的类型不匹配或对象变量。
以下代码是我当前的代码,并在第14行和第34行返回错误13;类型不匹配"
Option Public
Option Declare
Sub Initialize
On Error GoTo ErrorHandler
Dim s As New NotesSession
Dim db As NotesDatabase
Dim view As NotesDocumentCollection
Dim doc As NotesDocument
Dim nextdoc As NotesDocument
Dim result As String
Set db = s.CurrentDatabase
Set view = db.Unprocesseddocuments
If Not view Is Nothing Then
Set doc = view.Getfirstdocument()
While Not doc Is Nothing
result = Evaluate ("@Right(Subject;""#"")", doc)
Print result
Set nextDoc = view.GetNextDocument(doc)
Call doc.Remove(True)
Set doc = nextDoc
Wend
End If
Print "End"
Done:
Exit Sub
ErrorHandler:
Select Case Err
Case Else
Print "Error " & CStr(Err) & " in agent on line " & CStr(Erl) & ": " & Error
Resume Done
End Select
End Sub
答案 0 :(得分:3)
在New Mail Arrives之前不返回NotesDocumentCollection。 使用...
Sub Initialize
Dim Session As New NotesSession
Dim Doc As NotesDocument
Dim result As String
Set Doc = Session.DocumentContext
Let result = StrRight(Doc.Subject(0), "#")
End Sub
而不是UnprocessedDocuments ...
答案 1 :(得分:3)
在使用评估时,请参考有关Type Mismatch
的原始问题,请在“使用评估声明”下注意Designer帮助:
“ returnValue 是一个数组的类型和数量 反映公式结果;标量值返回到元素0 数组。您应该使用变量作为返回值 可能不知道有多少元素被归还。“
因此,请尝试以下更改:
...
Dim result As Variant
...
result = Evaluate (|@Right(Subject;"#")|, doc)
' Treat result as an array
Print result(0)
...