VB.Net

VB.Net Functions

VB.Net Functions

A procedure is a collection of statements that, when called, complete a task. After the procedure is completed, control returns to the statement that is called the procedure. There are two kinds of procedures in VB.Net −

  • Functions- return a value
  • Sub procedures or Subs- do not return a value

Defining a Function

The Function statement is used to declare a function's name, parameters, and body. The Function statement has the following syntax−

[Modifiers] Function FunctionName [(ParameterList)] As ReturnType

[Statements]

End Function

Where,

  • Modifiers − specify the function’s access level; possible values are Public, Private, Friend, Protected, Protected Friend and information regarding overloading, sharing, overriding, and shadowing.
  • FunctionName − indicates the name of the function
  • ParameterList – used to specify a list of the parameters
  • ReturnType – used to specify the data type of the variable that the function returns

Function Return a Value

A function in VB.Net can return a value to the caller code in two ways: 

  • by using the return statement 
  • by assigning the value to the function name

Recursive Function

A recursive function can call itself. This is called recursion. 

Param Arrays

When declaring a function or subroutine, you may be unsure of the number of arguments supplied as parameters. At this point, VB.Net param arrays (or parameter arrays) come in handy.

An array can be passed as a function argument in VB.Net. 

Top course recommendations for you

    Front End Development - HTML
    2 hrs
    Beginner
    505.8K+ Learners
    4.51  (40059)
    Front End Development - CSS
    2 hrs
    Beginner
    186.1K+ Learners
    4.51  (14465)
    Blockchain Basics
    3 hrs
    Beginner
    84.2K+ Learners
    4.55  (4668)
    Data Structures in C
    2 hrs
    Beginner
    181.8K+ Learners
    4.39  (13192)
    Excel for Beginners
    5 hrs
    Beginner
    1.3M+ Learners
    4.48  (66589)
    My SQL Basics
    5 hrs
    Beginner
    264.6K+ Learners
    4.46  (14007)
    Android Application Development
    2 hrs
    Beginner
    161.3K+ Learners
    4.42  (7049)
    OOPs in Java
    2 hrs
    Beginner
    115.4K+ Learners
    4.45  (6770)
    Building Games using JavaScript
    2 hrs
    Beginner
    33.5K+ Learners
    4.46  (655)
    Introduction to DevOps
    3 hrs
    Beginner
    68.8K+ Learners
    4.56  (4346)