User`s guide
Processing varargin and varargout Arguments
Processing varargin and varargout Arguments
When varargin and/or varargout are present in the MATLAB function that
you are using for the Excel component, these parameters are added to the
argument list of the class method as the last input/output parameters in the
list. You can pass multiple arguments as a
varargin array b y creating a
Variant array, ass igning e ach element of the array to the respective input
argument.
The following example creates a
varargin array to call a method resulting
from a MATLAB function of the form
y = foo(varargin):
Function foo(x1 As Variant, x2 As Variant, x3 As Varaint, _
x4 As Variant, x5 As Variant) As Variant
Dim aClass As Object
Dim v(1 To 5) As Variant
Dim y As Variant
On Error Goto Handle_Error
v(1) = x1
v(2) = x2
v(3) = x3
v(4) = x4
v(5) = x5
aClass = CreateObject("mycomponent.myclass.1_0")
Call aClass.foo(1,y,v)
foo = y
Exit Function
Handle_Error:
foo = Err.Description
End Function
The MWUtil class included in the MWComUtil utility library provides the
MWPack helper function to create varargin parameters. See “Utility Library
Classes” o n page C-3 for more de tails.
The next exa mple processes a
varargout parameter into three separate Excel
Ranges. This function uses the MWUnpack function in the utility library. The
MATLAB function used is
varargout = foo(x1,x2).
2-11