VBSyntax Variables
VBSyntax Variables
NET Guide
Variables:
Declare variables using the following syntax:
It is good practice to use a 3 letter prefix to indicate the variable scope and type in the
name. The name should also be intrinsically meaningful, identifying the purpose of
the variable.
Scope:
l – local
m – modular
g – global
Type:
Examples:
Variables can be declared at various levels – ie: to be used within different areas of
your project. Local variables (variables to be used only within a specific procedure or
function) and modular variables (variables that can be used throughout a class – the
code associated with a form) are both declared using the key word Dim. Variables can
be declared with modular scope by placing the declaration at the top of the page of
code; or locally by placing the declaration within the sub-routine. Global variables
can be declared using the key word Public. Global variables can be used throughout
the project but should be used rarely & with care as they are harder to track and can
cause confusion. It is good practice to put OPTION EXPLICIT at the top of the
page as it will enforce the declaration of variables.
Page 1 of 1