The syntax for custom functions in Basic syntax is very similar to the syntax for functions in Visual Basic.
Function name [(argList)] [As type]
[statements]
[name=expression]
[Exit Function]
...
End Function
Required. This is the name of the function. It must be the same as the name given to the function when you created it. The name cannot begin with a number, and cannot contain any spaces or punctuation marks other than the underscore. Also, it cannot be the same as a keyword in either Basic or Crystal syntax.
Optional. Represents the type of the data value returned by the function. May be any of the simple Crystal Reports types (Number, Currency, String, Boolean, Date, Time, DateTime) or range types (Number Range, Currency Range, String Range, Date Range, Time Range, DateTime Range). If the return type is omitted, it is deduced by the type of the expression in the first assignment to name (implicit typing).
Note If an array return type is desired, you must use the implicit typing since there is no explicit notation for this.
Assign expression to name to specify the value returned by the function. If type is specified, then this is optional, otherwise, it is required so that Crystal Reports will know the return type of the function through implicit typing.
The Exit Function statement causes Crystal Reports to immediately exit from the function. You can use this statement any number of times, anywhere in the body of the function.
Note The only statements you can place before the start of the function, or after the end of the function declaration are comments either with apostrophes or Rem statements.
[Optional] varName [()] As varType [=defaultValue]
Optional. Indicates that the argument can be omitted when the custom function is called. If an argument is optional, all subsequent arguments must be optional as well. If you supply a value for an optional argument, then you must supply a value for each preceding argument.
Required. Specifies the name of the variable representing the argument.
Optional. If present, then it means that the argument variable is an array variable.
Required. Indicates the type of the argument variable. It can be any of the seven simple or six range types mentioned in the argList description above. If the optional parentheses are present, the type is an array type whose elements are of type varType.
Required for optional arguments. defaultValue is a constant or constant expression, that is, an expression involving no variables that can be simplified at compile time to a constant value. If an optional argument is omitted when the function is called, then the default value for the argument will be used.
Note Unlike Visual Basic, if an argument is optional, a default value must be supplied.
All arguments are passed by value. In Visual Basic, arguments can be passed either by value or by reference, and are passed by reference by default. However, custom functions do not support reference arguments.
Custom Function Syntax Rules | Custom Function Evaluation Time