Option Commands (Option Explicit / Option Base etc) - Scope

A

Alan

Hi All,

I have my VBE set to always use Option Explicit at the top of each new
module.

I occasionally use Option Base 0 or Option Base 1 as required.

If I use one of those at the top of any module within a project, does
it apply to *all* modules in that project unless and until explicitly
changed, or does it only ever apply to the module in which it resides?

Hope that is clear, but if not, feel free to ask me to explain more.

Thanks,

Alan.
 
N

Norman Jones

Hi Alan,

Usage of any of the Option statements is at module level.

It follows, therefore, that different Option statements can be employed with
different modules and, more particularly, that different Option Bases can be
employed in different modules.
 
A

Alan

Norman Jones said:
Hi Alan,

Usage of any of the Option statements is at module level.

It follows, therefore, that different Option statements can be employed with
different modules and, more particularly, that different Option Bases can be
employed in different modules.

Thanks Norman.
 
J

John Green

Alan,

Option Explicit only applies to the module in which it resides. All the
variables used in that module must be explicitly declared using Dim or one
of its variations (Public, Static, etc.)

Option Base also applies to only the module it is in.
 
A

Alan

John Green said:
Alan,

Option Explicit only applies to the module in which it resides. All the
variables used in that module must be explicitly declared using Dim or one
of its variations (Public, Static, etc.)

Option Base also applies to only the module it is in.

Thanks John.

As a follow up, does it therefore make sense to put all my public
variable declarations into a separate module on their own, and avoid
using public in other modules?

That way, if I only Dim vars in the other modules, I know they only
reside there.

How about forms? Should I also use option explicit in each separate
form, or do they all follow the same command?

Thanks,

Alan.
 
C

Chip Pearson

Alan,

As a matter of organization, I tend to put all public variables
and constants in their own separate module, typically named
modGlobals. You'll need to put Option Explicit in the code module
for each form.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
A

Alan

Chip Pearson said:
Alan,

As a matter of organization, I tend to put all public variables
and constants in their own separate module, typically named
modGlobals. You'll need to put Option Explicit in the code module
for each form.

Thanks Chip.

I am only just getting to the level of complexity where these things
become an issue so it is all somewhat new to me (at least to have to
stop and really think about it systematically).

I guess I should extend my systematic naming conventions to the module
and form names too since there are getting to be many of them.....

Regards,

Alan.
 

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