Visual Basic includes built-in, or intrinsic functions, like Sqr, Cos or Chr. In addition, you can use the Function statement to write your own Function procedures.
[Private|Public][Static]Function procedurename (arguments) [As type]
Like a Sub procedure, a Function procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments. Unlike a Sub procedure that does not return any value, you use a Function procedure if you would like the procedure to return a value to the calling procedure.
There are three differences between Sub and Function procedures:
1. Generally, you call a function by including the function procedure name and arguments on the right side of a larger statement or expression ( returnvalue = function() ).
2. Function procedures have data types, just as variables do. This determines the type of the return value. (In the absence of an As clause, the type is the default Variant type.)
3. You return a value by assigning it to the procedure name itself. When the Function procedure returns a value, this value can then become part of a larger expression.
In the next page you will see an example.