Types of Scope in Visual Basic 6 Project.

Spread the love

An object’s scope means its visibility to other classes, module, procedure etc. There are two types of scope in Visual Basic projects: variable scope and procedure scope.

Variable Scope :

There are three levels of variable scope in Visual Basic: at the procedure level, at the form or module level, and at the global level.

Visual Basic declaring statements:


KeywordDoes this
DimUsing Dim alone creates variants. Use the As keyword to specify a variable type.
PrivateMakes variable available only in the current form/module
PublicMakes variable global—variable is available to the rest of program.
ReDimReallocates the memory for dynamic array variables.
StaticVariable preserves its value between procedure calls
TypeDeclares a user type

Procedure Scope :

You can restrict the scope of a procedure using keywords: Private, Public, Static, Friend.

Private: To make a procedure accessible in current Form/Module

Public: To make procedure global.

Friend: To make procedure available outside current Form but not outside current project.

Static: To make all variables of a function static.