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:

 

Keyword Does this
Dim Using Dim alone creates variants. Use the As keyword to specify a variable type.
Private Makes variable available only in the current form/module
Public Makes variable global—variable is available to the rest of program.
ReDim Reallocates the memory for dynamic array variables.
Static Variable preserves its value between procedure calls
Type Declares 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.