Visual Basic Return Statement

In visual basic, the Return statement is useful to terminate the execution of the method in which it appears and return the control back to the calling method.

 

Generally, in visual basic, the Return statement is useful whenever we want to value the other methods. We can also omit the usage of return statement in our methods by using void as a return type.

Visual Basic Return Statement Syntax

Following is the syntax of using Return statement in a visual basic programming language.

 

Return return_val

If you observe the above syntax, we used Return keyword as return type, and the value parameter return_val is used to return the value. The return_val parameter value can be either string or integer or array or list of object based on our requirements.

 

Now, we will see how to use Return statement in a visual basic programming language with examples.

Visual Basic Return Statement Example

Following is the example of using Return statement in a visual basic programming language.

 

Module Module1
  Sub Main()
    Dim i As Integer = 10, j As Integer = 20, result As Integer = 0
    result = SumofNumbers(i, j)
    Console.WriteLine("Result: {0}", result)
    Console.WriteLine("Press Enter Key to Exit..")
    Console.ReadLine()
  End Sub
  Public Function SumofNumbers(ByVal a As Integer, ByVal b As Integer) As Integer
    Dim x As Integer = a + b
    Return x
  End Function
End Module

If you observe the above code, we used Return statement in the SumofNumbers method. Here, whenever we call SumofNumbers method it will execute and return the resultant value using Return statement.

Result of Visual Basic Return Statement Example 

We will get the following result when we execute the above visual basic program.

 

Visual Basic Return Statement Example Result

 

This is how we can use Return statement in a visual basic programming language based on our requirements.