VB.Net

VB.Net Subs

VB.Net Subs

Subprocedures are those procedures that do not yield any value. When a program starts, control is passed to the Main Sub procedure, which then executes any other statements in the program's body.

Defining Sub Procedures

The Sub statement is used to declare a sub procedure's name, parameters, and body. The Sub statement has the following syntax: 

[Modifiers] Sub SubName [(ParameterList)] 

   [Statements]

End Sub

Where,

  • Modifiers − indicate the procedure's access level; acceptable options include Public, Private, Friend, Protected, Protected Friend, and information about overloading, sharing, overriding, and shadowing.
  • SubName – is the name of the Sub
  • ParameterList – gives the list of the parameters

Passing parameters by value

This is the standard approach for supplying parameters to a method. When a method is called in this way, a new storage location is established for each value parameter. The actual parameter values are copied into them. As a result, changes to the parameter within the method have no effect on the argument.

The reference parameters are declared in VB.Net using the ByVal keyword.

Using a Reference to Pass Parameters

A reference parameter is a pointer to a variable's memory location. In contrast to value parameters, when you pass parameters by reference, no new storage place is generated for these parameters. The reference parameters are stored in the same memory location as the method's actual arguments.

The reference arguments are declared in VB.Net using the ByRef keyword.

Top course recommendations for you

    Docker Projects
    2 hrs
    Intermediate
    4.3K+ Learners
    4.69  (86)
    Competitive Programming Course
    2 hrs
    Beginner
    8.6K+ Learners
    4.08  (64)
    Android Studio Tutorial
    1 hrs
    Beginner
    13.1K+ Learners
    4.47  (636)
    Web Scraping with Python
    1 hrs
    Beginner
    13.8K+ Learners
    4.45  (746)
    Python for Non-Programmers
    1 hrs
    Beginner
    43.5K+ Learners
    4.5  (1841)
    Visual Graphics in C
    2 hrs
    Intermediate
    13.9K+ Learners
    4.52  (405)
    Swift Tutorial
    2 hrs
    Beginner
    3.4K+ Learners
    4.43  (140)
    Systematic Inventive Thinking Innovations
    1 hrs
    Beginner
    2.1K+ Learners
    4.57  (101)
    React JS Tutorial
    2 hrs
    Beginner
    53.1K+ Learners
    4.51  (2845)
    Linux Tutorial
    2 hrs
    Beginner
    42.3K+ Learners
    4.51  (2607)