-
Book Overview & Buying
-
Table Of Contents
Visual Basic Quickstart Guide
By :
In VB, the Return statement is used to exit a function or a Sub procedure and return control to the calling code. It is used to provide a result or value back to the caller if necessary. The Return statement can be used in different contexts, depending on whether you work with a function or a procedure.
Here is an example of using the Return statement in the VB function:
Function myMult(n1 As Integer, n2 As Integer) As Integer Dim m As Integer m = n1 * n2 Return m End Function
In this example, the Return statement returns the result of the two numbers, n1 and n2, multiplied together to the caller. We saw earlier that a return value can also be set by assigning the function name a value. The second method does not stop execution at that point compared to the Return statement, which will immediately return to the calling code.
Here is an example of using the Return statement in the VB...