SyntaxIn a subroutine or Set property accessor: Return In a function or property Get accessor: Return returnValue
DescriptionThe Return statement returns control to the calling procedure from a sub procedure, property, or function. When used from functions and property Get accessors, it also returns an associated value to the calling procedure. Usage at a Glance
ExamplePublic Sub AddAndDisplayNumbers( ) Dim returnedValue As Double = GetNumbers( ) MsgBox("The sum of values is " & returnedValue) End Sub Public Function GetNumbers( ) As Double ' ----- Prompts for up to 10 numbers and returns the sum. Dim counter As Integer = 1 Dim userInput As String Dim sumOfNumbers As Double = 0# Do ' ----- Get the number from the user. userInput = InputBox("Enter number " & counter & ":", "Sum") If (userInput = "") Then Exit Do ' ----- Check for valid input. If IsNumeric(userInput) Then sumOfNumbers += CDbl(userInput) counter = counter + 1 End If Loop While (counter <= 10) ' ----- All added and ready to return. Return sumOfNumbers End Function Version DifferencesIn VB 6, the Return statement was used in a block of code accessed through a GoSub statement. The GoSub statement is no longer supported in VB under .NET, and the Return statement now serves a different purpose. See AlsoExit Statement |