User`s guide
Calling the Methods of a Class Instance
3-9
Calling the Methods of a Class Instance
After you have created a class instance, you can call the class methods to access
the compiled MATLAB functions. MATLAB Excel Builder applies a standard
mapping from the original MATLAB function syntax to the method’s argument
list. See section “Calling Conventions” on page A-7 for a detailed description of
the mapping from MATLAB functions to 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 compiled 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 type, and
object references. Appendix B, “Data Conversion” describes in detail how to
convert
Variants of any basic type to and from MATLAB data types. In
general, you can supply any Visual Basic type as an argument to a class
method, with the exception of Visual Basic
UDTs. You can also pass Excel 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. In this case it is sufficient
to dimension each output argument as a single
Variant. When an object type
(like an Excel
Range) is passed as an 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 MATLAB 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 method that corresponds to
a MATLAB function of the form
function y = foo(x1,x2).
Function foo(x1 As Variant, x2 As Variant) As Variant
Dim aClass As Object
Dim y As Variant
On Error Goto Handle_Error