I am a beginner in LotusScript, I have the following error in my agent:
My goal is to be able to connect to the server with the following code:
Option Public
Option Declare
Sub Initialize
Dim myServer As String
Dim myMailfile As String
myServer = "server"
myMailfile = "mailfile"
Dim filePath As String
Dim intErgebnis As Integer
Dim objNotes As Object
Dim LNdb As Object
Dim LNView As Object
Dim LNDoc As Object
Dim LNItem As Object
Dim strSubject As String
Dim LNWorkspace As Object
Dim LNAttachment As Variant
intErgebnis = 0
Set objNotes = GetObject("", "Notes.NotesSession")
Set LNdb = objNotes.GETDATABASE(myServer, myMailfile)
Set LNWorkspace = CreateObject("notes.notesuiworkspace")
LNWorkspace.OpenDatabase myServer, myMailfile
End Sub
Does anyone have any idea how to solve this? Thank you for your help
There is no data type called Object in Lotusscript. You need to declare those variables with their proper object types, e.g. NotesDatabase, NotesView, NotesDocument, etc.
Also, you should declare and initialize a NotesSession object, not use GetObject() in Lotusscript. It looks like you are trying to write COM code, not Lotusscript.
Another suggestion is to use variable names that are conforming to the de-facto (established) naming convention. If you look at other Lotusscript code, you will notice that the variables generally are named the same way, making it much easier to read other developer's code. Yet another recommendation is to declare all Notes objects/classes first, grouped/sorted in the order they are being used, followed by the rest of the variables, before any of them are assigned values.
Your code should look more like this:
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim item As NotesItem
Dim ws As New NotesUIWorkspace
Dim uidoc as NotesUIDocument
Dim mailServer As String
Dim mailFileName As String
Dim filePath As String
Dim resultCount As Integer
Dim subject As String
mailServer = "server"
mailFileName = "mailfile.nsf"
resultCount = 0
' *** Open the specified mail file using back-end classes
Set db = new NotesDatabase(mailServer, mailFileName)
' *** Get the document currently open in the Notes client using front-end classes
Set uidoc = ws.CurrentDocument
End Sub
You see how much easier this is to read, not to mention it is both shorter and working.
I also recommend to always use variable names in English. If you ever need to ask someone for help, for example here on Stack Overflow, it is much easier for them to understand your code if you use variable names that are easy to understand. This is also the reason why you should use the standardized names for Notes objects/classes.
I wrote a series of articles about how to write better Lotusscript code, I think they may help you: http://blog.texasswede.com/how-to-write-better-code-in-notesdomino/