Some General Issues Concerning Functions
Introduction. In the last webpage we made use of user defined functions to compute some expectations for distributions. We defined the function in the Visual Basic IDE and passed information to it so that it could return a value to the spreadsheet or another function. Now we need to discuss some of the more general syntactic essentials for developing user defined functions. As we have seen, a user can develop a function that can be used
There is some syntax for declaring a function
The parameters in the declaration are discussed in the table below.
It is also possible to have other conditions within the function so that you can use an Exit Function command to leave the function early as we will see in the next webpage. Some Different Argument Lists. There are a large variety of possibilities when developing argument lists.
The following table contains a variety of possible argument lists. |
Type | Sample Function Declaration | Discussion |
None | Function Spacer() | This function doesn't require any information from elsewhere in order to work. |
One | Function CubeRoot(ANumber) as Double | This function finds the cube root of ANumber and returns it as a double precision value. |
Two Values | Function NRoot(ANumber, ARoot) | This function finds the n-th root of a number |
Two Arrays | Function MeanDist(Values, Probabilities) | This function actually brings in two arrays in order to return the mean of a distribution. |
Optional | Function Spacer(Optional ANumber) | This function produces a certain number of spaces if no number is passed. If ANumber is passed then it determines the number of spaces. |
Whenever you use an Optional argument you will almost surely use the IsMissing built-in function within the function to determine whether the the argument was omitted. You can include many optional arguments in the argument list if you want, but each must be preceded by the keyword Optional. |