• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

What’s Scope?

In this chapter, you add an important building block to your programming foundation. Specifically, this chapter discusses when a variable or procedure is accessible to code in another procedure. Two interlocking concepts control which variables a procedure can use: the scope of a variable dictates its visibility to other code, and the lifetime of a variable dictates when it contains valid data. Although the examples use variables, the information in this chapter also applies to constants.

Most variables work within the confines of the procedure in which they’re declared. Sometimes you need a variable that can be seen by (is accessible to) other procedures. A variable’s visibility is known as its scope. Variable scope is similar to the concept discussed in “Declaring Procedures as Public or Private” in Chapter 4. Just as a procedure can be called from another module, a variable can be seen by other procedures. There are three levels of variable scope:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint