Campbell Scientific CR9000X Measurement and Control System User Manual

Page 183

Advertising
background image

Section 5. Program Declarations

SubName

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

VariableList

List of variables that are passed to the Subroutine when it is
called. Multiple variables are separated by commas. The
variable type can be declared as Float, Long, String, or The
list of Subroutine variables to pass is optional. Subroutines
can operate on the global program variables declared by the
Public or Dim statements. The advantage of passing
variables is that the subroutine can be used to operate on
whatever program variable is passed (see example).

When the Subroutine is called, the call statement must list
the program variables or values to pass into the subroutine
variable. The number and sequence of the program
variables/values in the call statement must match the number
and sequence of the variable list in the sub declaration.
Changing the value of one of the variables in this list inside
the Subroutine changes the value of the variable passed into
it in the calling procedure. (CRBasic passes all arguments
into a subroutine by reference (that is, a reference to the
memory location of the variable is passed, rather than an
actual value). Therefore, if the value of an argument is
changed by the subroutine, the change will take effect in the
main program as well.)

The call may pass constants or expressions that evaluate to
constants (i.e., do not contain a variable) into some of the
variables. If a constant is passed, the “variable” it is passed
to becomes a constant and cannot be changed by the
subroutine. If constants will be passed, the subroutine
should not attempt to change the value of the “variables”
that they will be passed into.

statementblock

Any group of statements that are executed within the body
of the Subroutine.
Boolean. Float is used for the default type if not declared.
To declare the type, use the "AS" command:

Sub SubName(Var1 as String * 20, Var2 as Long).

Exit Sub

Causes an immediate exit from a Subroutine. Program
execution continues with the statement following the
statement that called the Subroutine. Any number of Exit
Sub
statements can appear anywhere in a Subroutine.

End Sub

Marks the end of a Subroutine.

5-13

Advertising