User`s guide

Calling the Methods of a Class Instance
Calling the Me thods of a Class Instance
After you have created a class instance, you can call the class methods
to access the compiled M ATLAB functions. MATLAB Builder for Excel
applies a standard mapping from th e origina l MATLAB f un cti o n syntax to
the method’s argument list. See “Calling Conventions” on page A-11 for a
detailed description of the mapping from MATL AB functions t o COM class
method calls.
When a method has output arguments, the first argument is always
nargout,
which is of type
Long. This input parameter passes the normal MATLAB
nargout parameter to the com piled function and specifies how many outputs
are requested. Methods that do not have output arguments do not pass a
nargout argument. Following nargout are the output parameters listed
in the same order as they appear on the left side of the original MATLAB
function. Next come the input parameters listed in the same order as they
appear on the right side of the original MATLAB function. All input and
output arguments are typed as
Variant, the default Visual Basic data type.
The
Variant type can hold any of the basic VBA types, arrays of any ty pe,
and object references. See “Data Conversion Rules” on page B-2 for a detailed
description o f how to convert
Variant types of any basic type to and from
MATLAB data type s. In general, you can supply any Visual Basic type as an
argumen t to a class method, with the except ion of Visual Basic
UDTs. You can
also pass Exce l
Range objects directly as input and output arguments.
When you pass a simple
Variant type as an output parameter, the called
method allocates the received data and frees the original contents of the
Variant. Inthiscaseitissufficienttodimension each output argument as
asingle
Variant. Whenanobjecttype(likeanExcelRange)ispassedasan
output parameter, the object reference is passed in both directions, and the
object’s
Value property receives the data.
The following examples illustrate the process of passing input and output
parameters from VBA to Excel Builder component class methods.
The first example is a formula function that takes two inputs and returns one
output. This function dispatches the call to a class m ethod that corresponds to
a MATLAB function of the form
function y = foo(x1,x2).
2-9