Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Plant SCADA

Option Statements

  • Last UpdatedJul 18, 2023
  • 2 minute read

VBA supports the use of file scope Option statements which determine the default behaviour of some VBA functions. For instance, the Option Explicit statement causes the VBA compiler to produce compile errors whenever it encounters the use of previously undeclared variables. The Option Compare statement sets the default comparison method for string comparisons. The Option Base statement sets the default base number for VBA variable arrays to either zero or one.

clare all option statements in VBA at the beginning of your VBA code files.

Option Explicit Statement

As in other BASIC programming languages, VBA supports the declaration of variables both implicitly and explicitly. An unfortunate consequence of implicit variable declaration is the possible misspelling of the variable name in subsequent code writing, with unreliable program behaviour and unpredictable consequences.

To minimize implicit declaration, and to foster good, consistent programming standards, use the option explicit statement at the beginning of all your VBA files:

Option Explicit

This causes the VBA compiler to produce a compile error whenever it encounters an undeclared variable. This can be useful in locating and identifying variable name typing errors in your VBA code at compile time, thus trapping and minimizing the likelihood of runtime errors caused by such mistakes.

Option Compare Statement

The Option Compare statement determines how strings are compared within a VBA file, and like other Option statements in VBA, should be declared at the beginning of your VBA code files.

When strings are compared using VBA functions such as StrComp()or InStr(), VBA determines whether they contain equivalent characters and how they differ if they do not match.

Note: When comparing strings, VBA compares the ANSI values of each character in the strings. For example, the character capital 'A' has the ANSI value of 65, and the character lowercase 'a' has the ANSI value of 97. For a listing of ANSI character values, see ASCII/ANSI Character Code Listings.

You can use the Option Compare statement to specify the default case-sensitivity behavior for VBA functions when making string comparisons.

The Option Compare statement in VBA has two settings:

  • Option Compare Binary: String comparisons are case-sensitive, and this is the default string-comparison setting.

  • Option Compare Text: String comparisons are case-insensitive.

Option Base Statement

The Option Base statement determines the default base number for the indexing of variable arrays created within a VBA file, and like other Option statements in VBA, should be declared at the beginning of your VBA code files.

There are two settings for the Option Base statement in VBA:

  • Option Base 0: Variable arrays are indexed from number zero, and this is the default setting.

  • Option Base 1: Variable arrays are indexed from number one.

For an example of using the Option Base statement, see Fixed Size Arrays.

See Also

VBA Function Reference

In This Topic
TitleResults for “How to create a CRG?”Also Available in