El tipo no coincide al manipular la línea de asunto de un correo electrónico (Lotusscript)

I am running a Lotusscript Agent on "Before mail arrives". I need it to grab the text in the subject line after the "#" symbol. No matter how I try to get the Subject field (Evaluate, getFirstItem, getItemValue, etc), I always end up with an error. Usually it is a type mismatch or object variable not set.

The code below is my current code and returns an error 13 on line 14 "type mismatch"

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 

preguntado el 09 de marzo de 12 a las 14:03

2 Respuestas

Before New Mail Arrives does not return NotesDocumentCollection. Use...

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

instead of UnprocessedDocuments...

respondido 09 mar '12, 15:03

[14A0:0012-0F74] 03/09/2012 10:19:46 AM Router: Agent printing: Error 13 in agent on line 15: Type mismatch - Estudios de desarrollo PRNDL

It depends, what you have on line 15 now. Try to add some Prints to a console. - JiKra

The problem lies with "result = Evaluate ("@Right(Subject;""#"")", doc)" Whenever I try to get the Subject field, I always get an object not set or Type mismatch. But when i check the document properties, the subject field is there and contains text. - Estudios de desarrollo PRNDL

Ok, I modified the example. This is the most simple way to achieve your needs. - JiKra

FYI: the reason you got the 'type mismatch' is because Evaluate returns an array of strings. You had "Print Result" instead of "Print Result(0)" - Richard Schwartz

With reference to your original question about the Type Mismatch when using Evaluate, please note the Designer help, under "Using the Evaluate statement":

"valor devuelto is an array in which the type and number of elements reflect the formula result; a scalar value is returned to element 0 of the array. You should use a variant for the return value, since you may not know how many elements are being returned."

Therefore, try the following changes:

    ...
    Dim result As Variant
    ...
    result = Evaluate (|@Right(Subject;"#")|, doc)
    ' Treat result as an array
    Print result(0)
    ...

respondido 11 mar '12, 22:03

Plus of course using StrRight is more practical than using Evaluate plus formula - Alexei Zimarev

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.