Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 162 Visual Basic I Programming. Storage Classes Determines the “lifetime” of an identifier Types: –Automatic Default Memory is allocated for the variable.

Similar presentations


Presentation on theme: "CSC 162 Visual Basic I Programming. Storage Classes Determines the “lifetime” of an identifier Types: –Automatic Default Memory is allocated for the variable."— Presentation transcript:

1 CSC 162 Visual Basic I Programming

2 Storage Classes Determines the “lifetime” of an identifier Types: –Automatic Default Memory is allocated for the variable when the procedure is executed and is destroyed at the termination of the procedure Variable loses value after each execution of the procedure –Static Memory is allocated for the variable when the program (form) is executed and is destroyed at the termination of the program (form) Variable retains value between each execution of the procedure

3 Static Storage Class Each variable can be declared to be static: Private Sub PrintNums() Static intA As Integer Static intB As Integer Dim intC As Integer ' Automatic storage class... End Sub –This is the preferred method, since it explicitly declares whether it is Automatic or Static. (Note: Static takes the place of Dim.) All variables can be declared to be static: Private Static Sub PrintNums() Dim intA As Integer Dim intB As Integer... End Sub –By using Static in the Procedure declaration, all variables are implicitly made Static.

4 Why use the Static storage class? Good for counters or timers that need to continue between executions.

5 Scope Rules Determines the region in which an identifier can be referenced Types: (from innermost to outermost level of scope) –Local Variable is only available in the procedure –Private (Module) Variable (or identifier) is only available in the module –Public Variable (or identifier) is available to all modules in the project When variables (or identifiers) within the same project have the same name, the one with the innermost scope has precedence. Instead of relying on precedence, use explicitly different names.

6 Classwork Program Trace Figure 6.15 (Pages 199-200) Page 240 #6.40 (Together) Page 240 #6.41 (Individually) Homework Read Chapter 6.9-6.10, 6.14-6.17


Download ppt "CSC 162 Visual Basic I Programming. Storage Classes Determines the “lifetime” of an identifier Types: –Automatic Default Memory is allocated for the variable."

Similar presentations


Ads by Google