VB.Net - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

VB.Net Functions

VB.Net Functions

shape Description

A Function is a User Defined Data Type. A function is used to perform some action it consists of Names,Parameters and Statements.In general function can be defined as a gathering of statements.In VB.Net functions will be treated as procedures where the sub is also a procedure. Following is a syntax which describes the functionality of each and every part.

shape Syntax

[vbnet] [AccessModifiers] Function Function_Name[(AttributeList)] As Datatype [Statements] End Function[/vbnet] s
Parts Description
Modifiers Used to provide Access permission by Access Public,Priviate,protected
FunctionName Indicates the name of the Function
ParameterList Specifies the List of the Parameter
ReturnType Specifies the datatypeo f the variable and function returns

Returning Values in Function

shape Description

A function can return one value only. In PC programming, a return statement causes execution to leave the present subroutine and resume at the point in the code instantly after where the subroutine was called, known as its return address.We can return values in functions in two ways as follows.

shape Example

Following is an example which describes the functionality of a function. [vbnet] Module FunctionExample Function Add(ByVal x As Integer, ByVal y As Integer) As Integer Dim Result As Integer Result = x + y Add = Result 'Returns a value End Function Sub Main() Dim a As Integer = 10 Dim b As Integer = 20 Dim result As Integer result = Add(a, b) Console.WriteLine("Addition of two numbers is : {0}", result) Console.ReadLine() End Sub End Module [/vbnet] Output: Output will be as follows in the console.

Summary

shape Points

  • The role of function is same in all the computer languages.
  • The body of function will have a gathering of statements.
  • Main method is also a function.