Como: Criar um procedimento que retorna um valor (Visual Basic)
You use a Function procedure to return a value to the calling code.
To create a procedure that returns a value
Outside any other procedure, use a Function statement, followed by an End Function statement.
In the Function statement, follow the Function keyword with the name of the procedure, and then the parameter list in parentheses.
Follow the parentheses with an As clause to specify the data type of the returned value.
Place the procedure's code statements between the Function and End Function statements.
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(ByVal side1 As Single, ByVal side2 As Single) As Single Return Math.Sqrt((side1 ^ 2) + (side2 ^ 2)) End Function
O exemplo a seguir mostra uma chamada típica a hypotenuse.
Dim testLength, testHypotenuse As Single testHypotenuse = hypotenuse(testLength, 10.7)
Consulte também
Tarefas
Como: Retornar um valor de um procedimento (Visual Basic)
Como: Chamar um procedimento que retorna um valor (Visual Basic)
Referência
Instrução Function (Visual Basic)
Conceitos
Subprocedimentos (Visual Basic)
Procedimentos de propriedade (Visual Basic)