22. Setting options

[<<<] [>>>]

ScriptBasic implements many features, operators, functions, and statements. The developers defined the behavior of a statement, function or operator. For example ScriptBasic has an equality test operator like any other language. This is the well know = sign that result TRUE if the two values compared are equal and FALSE otherwise. This is simple when the values are integer or real values. But what about strings? Should strings be compared case sensitive or case insensitive? Should the developers of ScriptBasic decide instead of you? Not at all.

The statement option allows the programmer to alter the behavior of certain features. For example you can say

OPTION COMPARE sbCaseInsensitive

and string comparison as well as pattern matching becomes case insensitive when the line is executed. To switch it to case sensitive the programmer can write

OPTION COMPARE sbCaseSensitive

and comparison is case sensitive again. Note that the option statement alters the behavior of the feature globally. No matter where the option statement is executed. It can be inside a function, somewhere in a module: it alters the feature for the program execution at top level.

The syntax of the instruction is:

OPTION symbol expression

symbol is any symbol that an instruction is looking at. Expression should result an integer value. Options are always integer values.

Also note that there is no checking if you misspell the symbol name. If you write

OPTION COMPARA sbCaseInsensitive

the statement will execute without error. It will set the option for the symbol COMPARA instead of COMPARE and the statement does not ever know that there is no one interested in the value associated with COMPARA. Option values are available for commands as well as for external modules.

You can set the value of the option RaiseMathError. This will alter the behavior of certain mathematical operators and mathematical functions. When an operator gets an operand or a functions and argument that is out of the scope of the operation or function it returns undef by default. In many cases this is inconvenient and error prone, because this way errors may propagate further. Using this option these operators alter their behavior. There are three constants that the programmer can use to alter argument handling:

These values can be joined together using the bit operator OR, for example

OPTION RaiseMathError sbMathErrDiv OR sbMathErrUndef

means that ScriptBasic will raise error when division with zero occurs or a mathematical operator gets undef as argument.

[<<<] [>>>]