IF Statements And Debugging

Getting Started

The first step is to identify a constant to use during the process. My favorite is cDEBUG. While you can use DEBUG, just be cautious that your vendor does not add DEBUG as a keyword in the future thus breaking your program. However, you can use whatever you like.

Const cDEBUG = True

I then take advantage of this constant in my code with lines such as the following:

If cDEBUG then STOP
If cDEBUG then Print “Information about a variable” + Cstr(Variable)
If cDEBUG then Print “We Reached Step 1”
If cDEBUG then Print “We Completed Step 1”

Once I have this setup, then I can turn debugging on and off simply by changing the Constant at the top from True to False.

The above are some simple examples. We can get as complex as we like with this.

Say, when we want to run the debugger, we want to turn off our On Error statement. However, we would like to run the rest of the time. We have two options:

Option 1

Const cDEBUG = True
If Not cDEBUG then On Error GoTo errhandler

Option 2

Const cDEBUG = True
Const cNOTDEBUG = Not cDEBUG
If Not cNOTDEBUG then On Error GoTo errhandler

Troubleshooting a specific document

Sometimes we need a customized line to help our debugger get where we are trying to troubleshoot.

Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set doc = collection.GetFirstDocument()
While Not(doc Is Nothing)
If cDEBUG and “testdoc” = lcase(doc.field(0)) then Stop
Set doc = collection.GetNextDocument( doc)
Wend

Key Line

If cDEBUG and “testdoc” = lcase(doc.testfield(0)) then Stop

Both conditions need to be true to execute the Stop command in the debugger. Therefore, if cDEBUG is false, then the rest of the line does not matter. If the document does not contain a “testdoc” in a field ”testfield”, then continue to the next document. However, it both is true then the debugger will execute the Stop command. (Note: you have to be in the debugger for this to function)

While we could put the Stop on its own line and hit continue a number of times. Imagine a view with thousands of documents. You may be there all day to get to the right document or worst, you stepped right over it without noticing it.

While there, are a number of ways to turn a debug variable on and off, having lines in your code that can help you and make your life easier.