XLL+ Class Library (7.0)

Constraining array sizes

Constraining the size of an argument

The function is now almost complete, and ready for building and testing.

It needs one more piece of work: we need to constrain the size of the matrix Z to be the same width as X and the same height as Y. Our core function, LinearInterp2D() assumes that these constraints have been satisfied.

Launch the Argument Editor for Z. There are several ways to do this:

  1. In the XLL+ ToolWindow, select INTERP2D in the upper half of the window, and double-click on Z in the lower half.
  2. Launch the XLL+ Function Wizard to edit INTERP2D, and select Z. Then click on the Details tool just above the argument grid.
  3. Alternatively, in the XLL+ Function Wizard, select Z and press ALT+Enter.

In the Argument Editor, select the Matrix tab:

In the Constraints group box, use the "Height is equal to" and "Width is equal to" combo-boxes to set the constraints:

Bounding variables

The result of these changes will be to create two new bounding variables, sizeOfX and sizeOfY. These will be set to the sizes of X and Y respectively when X and Y are evaluated. They they will then be checked against the height and width of Z respectively.

// Named bounds 
long sizeOfX = -1;
long sizeOfY = -1;
// Validate and translate inputs
XlReadMatrix(*Z_op, mtx_adapter(Z), L"Z", XLA_TRUNC_ONEMPTY|
    XLA_TRUNC_ONBLANK, &sizeOfY, 0, &sizeOfX);

If either constraint fails, then an exception will be thrown, and an appropriate message will be returned to Excel, e.g.: Expected 5 rows for Z.

Displaying the constraints

You can see the constraints displayed in the Function Wizard:

They will also show up in the Properties window when you select X, Y or Z in the ToolWindow:

Validation errors

Build and run the add-in.

Try out the validation code. If you are using English as your language, you can get errors such as the following:

#ERROR: Expected 3 columns in Z
#ERROR: Expected 3 rows in Z
#ERROR: Expected number for Z[1,4]

Next: Matrix containers >>