• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

11. Functions and Subroutines > 11.1. Calling Functions

Calling Functions

A function declaration has the form:

[Public or Private] FunctionFunctionName(Param1 As DataType1, _
         Param2 As DataType2,...) As ReturnType

Note that we must declare the data types not only of each parameter to the function, but also of the return type. Otherwise, VBA declares these items as variants.

I will discuss the optional keywords Public and Private later in this chapter, but you can probably guess that they are used here to indicate the scope of the function, just as they are used in variable declarations. For example, the AddOne function in Example 11-1 adds 1 to the original value.

Example 11-1. The AddOne function
Public Function AddOne(Value As Integer) As Integer
   AddOne = Value + 1
End Function

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint