How to: Create a Procedure that Returns a Value - Visual Basic (original) (raw)

Use a Return statement to return the value to the calling code.

The following Function procedure calculates the longest side, or hypotenuse, of a right triangle, given the values for the other two sides.

Function Hypotenuse(side1 As Double, side2 As Double) As Double
    Return Math.Sqrt((side1 ^ 2) + (side2 ^ 2))
End Function

The following example shows a typical call to hypotenuse.

Dim testLength, testHypotenuse As Double
testHypotenuse = Hypotenuse(testLength, 10.7)