|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Returns control to the code that called a Sub, Function, or Property procedure.
- Required in a Function procedure or a Property procedure that retrieves the property's value. An expression that represents the value to be returned to the calling code.
For a Sub procedure or a Property procedure that sets the property's value, the Return statement is equivalent to an Exit Sub statement, and expr must not be supplied.
For a Function procedure or a Property procedure that retrieves the property's value, expr must be present and must evaluate to a data type that is convertible to the return type of the function. In this form, Return is equivalent to assigning the expression to the function name as the return value and then executing an Exit Function statement.
This example uses the Return statement several times to return to the calling code when the procedure does not need to do anything else.
Public Function GetAgePhrase(Age As Integer) As String If Age > 60 Then Return "Senior" If Age > 40 Then Return "Middle-aged" If Age > 20 Then Return "Adult" If Age > 12 Then Return "Teen-aged" If Age > 4 Then Return "School-aged" If Age > 1 Then Return "Toddler" Return "Infant" End Function