- This example shows the simplest case of an error handler. The
first statement establishes a handler for all errors. The handler
prints the error number and message, and exits. If the user enters
the name of a non-existent file, an error is raised on "Set dc = db.AllDocuments."
Sub Initialize
On Error Goto processError
Dim dc As NotesDocumentCollection
Dim db As New NotesDatabase("", _
Inputbox("Database?"))
Set dc = db.AllDocuments
Exit Sub
processError:
Messagebox "Error " & Err() & ": " & Error()
Exit Sub
End Sub
- This example traps the error that occurs when you later try to
use a NotesDatabase object that did not open because of a bad file
name specification. In addition, the example handles other errors.
If the user enters a bad name, the error handler allows the user to
retry or cancel. For a retry, the error handler calls the Open method
and then resumes execution in the mainline code.
(Declarations)
%INCLUDE "lsconst.lss"
%INCLUDE "lsxbeerr.lss"
Sub Initialize
On Error Goto processError
On Error lsERR_NOTES_DATABASE_NOTOPEN _
Goto processNotOpen
Dim dc As NotesDocumentCollection
Dim db As New NotesDatabase("", Inputbox("Database?"))
Set dc = db.AllDocuments
Exit Sub
processNotOpen:
reply = Messagebox _
("Database name is wrong", MB_RETRYCANCEL)
If reply = IDRETRY Then
Call db.Open("", Inputbox("Database?"))
Resume
Else
Messagebox "Error " & Err() & ": " & Error()
Exit Sub
End If
processError:
Messagebox "Error " & Err() & ": " & Error()
Exit Sub
End Sub
- This example tests the effect of the New method with the IsOpen
property.
(Declarations)
%INCLUDE "lsconst.lss"
Sub Initialize
Dim dc As NotesDocumentCollection
Dim db As New NotesDatabase("", _
Inputbox("Database?"))
Do While Not db.IsOpen
reply = Messagebox _
("Database name is wrong", MB_RETRYCANCEL)
If reply = IDRETRY Then
Call db.Open("", Inputbox("Database?"))
Else
Messagebox "Database can't be opened"
Exit Sub
End If
Loop
Set dc = db.AllDocuments
End Sub
- This example tests the effect of the Open method by examining
its return value.
(Declarations)
%INCLUDE "lsconst.lss"
Sub Initialize
Dim dc As NotesDocumentCollection
Dim db As New NotesDatabase("", "")
Do While Not db.Open("", Inputbox("Database?"))
reply = Messagebox _
("Database name is wrong", MB_RETRYCANCEL)
If reply <> IDRETRY Then
Messagebox "Database can't be opened"
Exit Sub
End If
Loop
Set dc = db.AllDocuments
End Sub