1 / 7

Sub Procedures, Part II (Continue)

Sub Procedures, Part II (Continue). Local Variable. A variable declared inside a Sub procedure with a Dim statement Space reserved in memory for that variable until the End Sub – then the variable ceases to exist. Local Variables. Private Sub btnOne_Click(...) Handles btnOne_Click

elinor
Télécharger la présentation

Sub Procedures, Part II (Continue)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sub Procedures, Part II (Continue) Chapter 4

  2. Local Variable • A variable declared inside a Sub procedure with a Dim statement • Space reserved in memory for that variable until the End Sub – then the variable ceases to exist Chapter 4

  3. Local Variables Private Sub btnOne_Click(...) Handles btnOne_Click Dim num As Integer = 4 SetFive() txtBox.Text = CStr(num) End Sub Sub SetFive() Dim num As Integer = 5 End Sub Output: 4 Chapter 4

  4. Class-Level Variables • Visible to every procedure in a form’s code without being passed • Dim statements for class-level variables are placed • Outside all procedures • At the top of the program region Chapter 4

  5. Class-Level Variables Dim num As Integer = 4 Private Sub btnOne_Click(...) Handles btnOne_Click txtBox.Text = CStr(num) SetFive() txtBox.Text = CStr(num) End Sub Sub SetFive() num = 5 End Sub Output: 5 Chapter 4

  6. Scope • The scope of a variable is the portion of the program that can refer to it. Chapter 4

  7. Scope • Class-level variables have class-level scope and are available to all procedures in the class. • Variables declared inside a procedure have local scope and are only available to the procedure in which they are declared. Chapter 4

More Related