Kardi Teknomo
Kardi Teknomo Kardi Teknomo Kardi Teknomo
   
 
  Research
  Publications
  Tutorials
  Resume
  Personal
  Contact

 

Function Procedure

By Kardi Teknomo, PhD.

<VB Tutorial | Contents | Previous | Next >

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.

Syntax:
[Private|Public][Static]Function procedurename (arguments) [As type]
statements
[Exit Function]
statements
End Function


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 example.

<VB Tutorial | Contents | Previous | Next >

Rate this tutorial or give your comments about this tutorial

This tutorial is copyrighted.

Preferable reference for this tutorial is

Teknomo, Kardi. Visual Basic Tutorial . http:\\people.revoledu.com\kardi\ tutorial\VB

 

 

 

 
© 2007 Kardi Teknomo. All Rights Reserved.
Designed by CNV Media