1 / 6

Sub Procedure Parameters: ByVal vs ByRef

Learn about passing variables in sub procedures by value (ByVal) or by reference (ByRef), and understand the differences between local and class-level variables. Also, explore debugging techniques.

collette
Download Presentation

Sub Procedure Parameters: ByVal vs ByRef

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 • Passing by Value • Passing by Reference • Local Variables • Class-Level Variables • Debugging Chapter 4

  2. ByVal and ByRef • Parameters in Sub procedure headers are proceeded by ByVal or ByRef • ByVal stands for By Value • ByRef stands for By Reference Chapter 4

  3. Passing by Value • When a variable argument is passed to a ByVal parameter, just the value of the argument is passed. • After the Sub procedure terminates, the variable has its original value. Chapter 4

  4. Example Dim n As Double = 4 Triple(n) txtBox.Text = CStr(n) End Sub Sub Triple(ByVal num As Double) num = 3 * num End Sub Output: 4 Chapter 4

  5. Same Example: n num Dim num As Double = 4 Triple(num) txtBox.Text = CStr(num) End Sub Sub Triple(ByVal num As Double) num = 3 * num End Sub Output: 4 Chapter 4

  6. Passing by Reference • When a variable argument is passed to a ByRef parameter, the parameter is given the same memory location as the argument. • After the Sub procedure terminates, the variable has the value of the parameter. Chapter 4

More Related