Understanding Scope

Scope is a term used to describe when and where a variable or procedure is available. There are three levels of scope:

Procedure. Variables declared at this level (using the Dim keyword) are only available within the procedure. Also referred to as local.

Module. Variables and procedures declared at this level (using the Dim keyword or—for improved readability—the Private keyword) are available anywhere within a form, class, or module. Also referred to as private.

Note Declaring a variable with module-level scope should not be confused with the idea of simply declaring a variable in a module. By default, variables declared in a module are available only within the module (module scope), but declaring a variable with the Public keyword makes it available everywhere (global scope).

Global. Variables and procedures declared at this level (using the Public keyword) are available throughout your program. Also referred to as public.

The value stored in any variable is temporary, dependent upon where it was declared. When ^

a variable goes out of scope it is reset to its default value, such as 0 for numeric variables. In the ®

case of a local variable, for example, it goes out of scope when the procedure in which it is ®

declared has been completed. °

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment