homecode zoneQuick Codedownloadssubmit codeabout usfeedbackscontact ussitemap
 
Beginners
Database
File System Object
General
Graphics
Multimedia
Networking
Shell Object
Timer
Array
Date/Time
Declaration
Error Handling
File/Folder
Logic
Loops & Conditional
Math
Miscellaneous
Strings
Values
Pro - Languages
C/C++
Java
Visual basic
asp
vb.net 2003/2005
asp.net
Quick Code
SUBMIT CODE
Mail List
LINKS
Submit LINK
 
ProgrammerGuide.net - VB Declaration.
Home » VB Zone » Declaration

Function Procedures

Declares the name, arguments, and code that form the body of a Function procedure.
Syntax: [Public | Private | Friend] [Static] Function name [(arglist)] [As type]
[statements]
[name = expression]
[Exit Function]
[statements]
[name = expression] End Function

The Function statement syntax has these parts:

Part Description
Public Optional. Indicates that the Function procedure is accessible to all other procedures in all modules. If used in a module that contains an Option Private, the procedure is notavailable outside the project.
   
Private

Optional. Indicates that the Function procedure is accessible only to other procedures in the module where it is declared.

   
Friend Optional. Used only in a class module. Indicates that the Function procedure is visible throughout the project, but not visible to a controller of an instance of an object.
   
Static Optional. Indicates that the Function procedure's local variables are preserved between calls. The Static attribute doesn't affect variables that are declared outside the Function,even if they are used in the procedure
   
Name Required.Name of the Function; follows standard variable naming conventions.
   
arglist Optional. List of variables representing arguments that are passed to the Function procedure when it is called. Multiple variables are separated by commas.
   
type Optional. Data type of the value returned by the Function procedure; may be Byte, Boolean, Integer, Long, Currency, Single, Double, Decimal (not currently supported), Date, String, or (except fixed length), Object, Variant, or any user-defined type.
   
statements Optional. Any group of statements to be executed within the Function procedure.
   
expression Optional. Return value of the Function.


The arglist argument has the following syntax and parts:
[Optional] [ByVal | ByRef] [ParamArray] varname[( )] [As type] [= defaultvalue]

Part Description
Optional Optional. Indicates that an argument is not required. If used, all subsequent arguments in arglist must also be optional and declared using the Optional keyword. Optional can't be used for any argument if ParamArray is used.
   
ByVal Optional. Indicates that the argument is passed by value.
   
ByRef Optional. Indicates that the argument is passed by reference. ByRef is the default in V.B.
   
ParamArray Optional. Used only as the last argument in arglist to indicate that the final argument is an Optional array of Variant elements. The ParamArray keyword allows you to provide an arbitrary number of arguments. It may not be used with ByVal, ByRef, or Optional.
   
varname Required. Name of the variable representing the argument; follows standard variable naming conventions.
   
type

Optional. Data type of the argument passed to the procedure; may be Byte, Boolean, Integer, Long, Currency, Single, Double, Decimal (not currently supported) Date, String (variable length only), Object, Variant, or a specific object type. If the parameter

   
defaultvalue

Optional. Any constant or constant expression. Valid for Optional parameters only. If the type is an Object, an explicit default value can only be Nothing.



Remarks
If not explicitly specified using Public, Private, or Friend, Function procedures are public by default. If Static isn't used, the value of local variables is not preserved between calls. The Friend keyword can only be used in class modules. However, Friend procedures can be accessed by procedures in any module of a project. A Friend procedure does't appear in the type library of its parent class, nor can a Friend procedure be late bound.

« Previous 1 2 3 4 Next »

Viewers: 16
Visitors:127291
Last Updated on:Sunday, January 17, 2010
Home | About us | Feedback | Contact us | Sitemap
Copyright © 2008 ProgrammerGuide.net. All rights reserved.
This site is best viewed in IE 6.0, Firefox 1.5 and above with screen resolution of 1024 X 768.