Using Option Explicit in Visual Basic for Applications - Microsoft Excel

preview_player
Показать описание
The option explicit statement is used at the module level to force explicit declaration of all variables used in that module, it has to be placed at the top of the module before any sub procedures. The idea is that the user must explicitly declare all variables by using the Dim, Private, Public, ReDim, or Static statements.

If the user attempts to use an undeclared variable name, an error occurs at compile time.

If option explicit is not stated and a variable is not declared, it is treated as a variant type variable.

Basically, what the user must do is type the statement "Option Explicit" right at the top of the module to enforce the declaration of variables.

Option Explicit should be used to avoid incorrectly typing the name of an existing variable or to avoid confusion in code where the scope of the variable is not clear.

It is a very useful thing to implement and good housekeeping as a coder to keep code nice and clean.
Рекомендации по теме
visit shbcf.ru