VB.net contains built-in or internal functions, such as MsgBox, CStr, and so on. In addition, you can use function statements to write your own function procedures. The syntax for a Function procedure is:
{private| public| friend|} Function functionname (argument list) [as data type]
Statements
End Function
Like a Sub procedure, a Function procedure is also a separate process that reads a parameter, executes a series of statements, and changes the value of its arguments. Unlike a Sub procedure, a Function procedure can return a value to the calling procedure. There are three differences between a Sub procedure and a Function procedure:
(1) Generally speaking, the right side of the statement or expression contains the Function procedure name and parameter (returnvalue=function), which invokes the function.
(2) The function process has the data type exactly like the variable. This determines the type of return value (if there is no as clause, the default data type is Object).
(3) You can assign a value to functionname, which is the value returned.
When a Function procedure returns a value, the value can become part of the expression. For example, the following is a value that is known to be right-angled to the right triangle and calculates the third side (hypotenuse) function:
Function hypotenuse (A as integer,b as Integer) as String
HYPOTENUSE=MATH.SQRT (a^2+b^2)
End Function
The method that calls a Function procedure in Visual Basic is the same as the method that calls any intrinsic function:
Label1.text=cstr (Hypotenuse (CInt (Text1.Text), CInt (Text2.text)))
Strx=cstr (hypotenuse (width,height))