Option Question

S

SkippyPB

I've noticed that many of VBA subroutines shown by various people in
this newsgroup all start with the statement:

Option Explicit

What is the purpose of this statement?

Thanks.

(o o)
-oOO--(_)--OOo-
He didn't tell his mother that he ate some glue.
His lips were sealed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Remove nospam to email me.

Steve
 
M

Martin Brown

I've noticed that many of VBA subroutines shown by various people in
this newsgroup all start with the statement:

Option Explicit

What is the purpose of this statement?

To force a compile time error when undeclared and undefined variables
are used. It imposes some discipline on a language that otherwise
permits dangerously ambiguous constructs and variables to go unchecked.
The default is everything is a variant something or other (which can
lead to some very interesting bugs in the wrong hands).

With Option Explicit you have to define each variable before first use.

Regards,
Martin Brown
 
S

SkippyPB

To force a compile time error when undeclared and undefined variables
are used. It imposes some discipline on a language that otherwise
permits dangerously ambiguous constructs and variables to go unchecked.
The default is everything is a variant something or other (which can
lead to some very interesting bugs in the wrong hands).

With Option Explicit you have to define each variable before first use.

Regards,
Martin Brown

Thanks Martin. Makes perfect sense.

Cheers,
(o o)
-oOO--(_)--OOo-
He didn't tell his mother that he ate some glue.
His lips were sealed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Remove nospam to email me.

Steve
 
Top