Option Explicit Statement
Explicit to generate an error whenever a
variable that has not been declared is encountered.
Explicit statement must appear in a
script before any other statements; otherwise, a nontrappable
In modules where the
Explicit statement isn’t used, any
undeclared variables are declared automatically.
Explicit is used, all variables must
be declared using the
It’s considered good programming practice to always use
vbCrLfExplicit statement. The
following example shows why:
Dim iVariable iVariable = 100 iVariable = iVarable + 50 MsgBox iVariable
In this code snippet, a variable,
iVariable, has been declared.
However, because the name of the variable has been mistyped in
line 3, the message box shows its value as 50 instead of 150.
This is because
iVarable is assumed
to be an undeclared variant whose value is 0. If the
Explicit statement had been used, the
code wouldn’t have executed without generating an error, and
iVarable would have been highlighted
as the cause when Error 500, “Variable is undefined,” was
For ASP pages, the
Explicit statement must appear before the beginning of
the HTML stream. For example:
<% Option Explicit %> <HTML>
Explicit statement applies to
all script blocks in an ASP page.