A compressed group can contain any number of scalar (single-cell) arguments. Each of these inner arguments must be defined as one of the following types:
The four inner arguments will appear in Excel as a single array argument. For example, take a group argument, PaymentDetails, that contains four inner arguments, as follows:
| Name | Type |
|---|---|
| StartDate | Double |
| EndDate | Double |
| AccountType | String |
| PaymentDays | Long |
The wizard will generate code that inspects the outer (Excel) argument. This code will fail and return a helpful error message unless the argument is one of the following shapes:
| 01-Jan-2000 |
| 31-Dec-2009 |
| ROLLING |
| 7 |
| 01-Jan-2000 | 31-Dec-2009 | ROLLING | 7 |
| AccountType | ROLLING |
| PaymentDays | 7 |
| StartDate | 01-Jan-2000 |
| EndDate | 31-Dec-2009 |
The wizard-generated code to unpack this group will look like this:
extern "C" __declspec( dllexport )
LPXLOPER GroupedFn(const COper* PaymentDetails)
{
CXlOper xloResult;
BOOL bOk = TRUE;
double StartDate;
bOk = bOk && PaymentDetails->ReadVectorItem(StartDate, "PaymentDetails", 0, "StartDate", xloResult);
double EndDate;
bOk = bOk && PaymentDetails->ReadVectorItem(EndDate, "PaymentDetails", 1, "EndDate", xloResult);
short AccountType;
bOk = bOk && PaymentDetails->ReadVectorItem(AccountType, "PaymentDetails", 2, "AccountType", xloResult);
long PaymentDays;
bOk = bOk && PaymentDetails->ReadVectorItem(PaymentDays, "PaymentDetails", 3, "PaymentDays", xloResult);
if (!bOk)
return xloResult.Ret();
//}}XLP_SRC
...
}
If the input-checking code fails, then a useful error message will be returned, such as:
#Error in cell 4 of PaymentDetails (PaymentDays): expected an integer
If all the input-checking code is successful, then the variables StartDate, EndDate, AccountType and PaymentDays will be populated and ready for use.
There are two ways to create a compressed group in the Function Wizard.
You can see an example of grouped arguments in use in the LabelledArgs sample project.