Visual Basic 2008 Programming: Business Applications with a Design Perspective
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9
Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Appendix A Appendix B Appendix C Home
Loading
Last change: February 13 2016 18:48:19.

 Chapter in PDF

Table of Contents

Chapter 4: Data, Operations, and Built-In Functions
Last change: February 13 2016 18:47:36.
<<PreviousNext>>

4.2     Scope and Lifetime of Variables

The code window associated with the form is recognized as the class module. When you first start a new project, its code window should contain two statements at follows:

Public Class Form1 End Class

These two statements define a class, which is the template for an object. All statements pertaining to the class must be placed between these two statements. Classes will be discussed in detail in Chapter 12, “Object Based Programming,” and Chapter 13, “Object Oriented Programming.” Most of the code that you write for the module should be placed between these two statements. (Option statements such as Option Explicit should be placed at the beginning before the Class statement.) All the event procedures that you have coded have been placed in this area. If you have any variable declaration statements to be placed outside of any procedure, you should place them in this area first, before any code for any procedure. This area shall be called the general declaration area.

Variables and constants have their scope and lifetime (duration). Scope refers to how widely a variable is recognized (accessible); lifetime refers to how long a variable remains in computer memory. The placement of a variable declaration can affect both the scope and the duration of that variable.

Last change: February 13 2016 18:47:36.
  1. Declaring Constants
  2. Declaring Variables
  3. Rules for Variable Declaration
  • 4.2 Scope and Lifetime of Variables
    1. Form (Class)-Level Declaration
    2. Procedure-Level Declaration
    3. Static Declaration
    4. Scope and Lifetime: A Recap
    5. Scope and Program Modularity
    6. Constant and Variable Naming Convention
    7. <<PreviousNext>>