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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top