Contact TLCC

Option Declare: LotusScript's Compile-Time Spell Checker Click here to see all the Developer/Admin Tips

Date tip published:09/07/2004
Description:The "Option Declare" option prevents implicit declarations in a script. When you set this option, you must explicitly declare all variables, including variant variables. Using this option provides a built-in spell checker for your script because any misspelled variable names will cause a compile-time error that you can easily locate and correct. For this reason, you should always use this feature.


To learn more about Using the Option Declare statement in LotusScript code use the following links:

Beginner LotusScript for Notes Domino 6
Intermediate LotusScript for Notes Domino 6
Advanced LotusScript for Notes Domino 6






Option Declare: LotusScript's Compile-Time Spell Checker

The "Option Declare" option prevents implicit declarations in a script. When you set this option, you must explicitly declare all variables, including variant variables. Using this option provides a built-in spell checker for your script because any misspelled variable names will cause a compile-time error that you can easily locate and correct. For this reason, you should always use this feature.




Example: Innocent Spelling Errors in a Script

Consider the following code and note the spelling error in the multiplication expression in Line 6. When the code in this example executes, Notes implicitly declares a new nQantity variable and initializes it to zero. The result of this calculation is then zero when it should be 1295. That's quite a difference!

1.

Dim vntResult As Variant

2.

Dim nQuantity As Integer

3.

Dim dPrice As Double

4.

nQuantity = 100

5.

dPrice = 12.95

6.

vntResult = nQantity * dPrice

7.

Messagebox vntResult, MB_OK, "Total Cost"

    Finding this type of error in a simple script may take a few minutes. In a more complex script, finding a spelling error could take hours!

    With the Option Declare statement set for this script, Notes raises a compile-time error when you attempt to save the script because no explicit declaration exists for the misspelled variable. In this case, the LotusScript Editor displays the offending line of code in red making it very easy to locate and fix.








    Procedure: Setting Option Declare

    Follow these steps to enable the Option Declare built-in spell checker:

    1. In Domino Designer, expand the desired design object in the Objects list in the Programmer's Pane to display its events.
    2. Select the (Options) event and enter the Option Declare statement in the script area.

    3. Save your changes.




    Tip
    Automatically Set Option Declare

    The use of Option Declare is a recommended best practice. Follow these steps to automatically add the Option Declare option whenever a new design element is coded using LotusScript:

    1. In Designer, right click in the script area of the Programmer's Pane to access its context menu. Select Programmer's Pane Properties... from the context menu to open the properties dialog.

    2. In the Programmer's Pane properties dialog, click the Format tab. Check the option to Automatically add "Option Declare".