Campbell Scientific CR9000X Measurement and Control System User Manual

Page 178

Advertising
background image

Section 5. Program Declarations

THE FUNCTION DECLARATION STATEMENT HAS THESE PARTS:

Part Description

Function

Marks the beginning of a

Function

.

FunctionName

The FunctionName argument provides the name for the
Function. The field length is limited to 16 characters.
Function names follow the same rules that constrain the
names of other variables.

VariableList

List of variables that are passed to the Function when it is
called. The list of variables to pass is optional. The
advantage of passing variables is that the Function can be
used to operate on whatever program variable(s) is passed.
Multiple variables are separated by commas. The variable
type can be declared as Float, Long, String, or Boolean.
To declare the type, use the "AS" command. The
following construct sets Var1 as a String with 20
characters, Var2 as a Long, and the value returned by the
Function as a Boolean variable type:

Function FunctionName(Var1 as String * 20,
Var2 as Long
) as Boolean.

If 'AS Type' is not specified for a variable, the default
parameter type is Float. When a function is called, the
parameters are copied into the Function's local parameter
list, as is the case when subroutines are called. However,
unlike subroutines which copy the local parameter values
back out to any variables that were passed in, Functions
do not write over (pass back) values to the list of variables
in the Call expression. A Function simply returns a value
to be used by the expression that invoked the function the
same way a built in function would.

statementblock

Any group of statements that are executed within the body
of the Function.

Return(expression) Causes an immediate exit from a Function. The value

returned by the Function is determined by the expression
listed as part of the Return instruction. An alternative
method of returning a value is to assign an expression to
the Function's name, as is done in the example code
above: Secant = 1/Cos(F_Angle). If neither method is
used, then NAN will be returned.

ExitFunction

Causes an immediate exit from the Function. Any number
of ExitFunction statements can appear anywhere in a
Function. If a value assignment has not been made to the
Function (see Return) prior to encountering the
ExitFunction command, the Function will return NAN.

EndFunction

Marks the end of the Function. If a value assignment has
not been made to the Function (see Return) prior to

5-8

Advertising