The source code has now been modified. The argument type DaysPerYear has been changed:
extern "C" __declspec( dllexport )
LPXLOPER HISTVOL(const COper* Prices, const COper* DaysPerYear)
{
...
}
In addition, a new local variable valDaysPerYear, has been declared, and some lines have been generated to populate it.
extern "C" __declspec( dllexport )
LPXLOPER HISTVOL(const COper* Prices, const COper* DaysPerYear)
{
CXlOper xloResult;
BOOL bOk = TRUE;
std::vector<double> vecPrices;
bOk = bOk && Prices->ReadVector(vecPrices, "Prices", xloResult);
double valDaysPerYear = 250.0;
bOk = bOk && DaysPerYear->ReadOptional(valDaysPerYear, "DaysPerYear", xloResult);
if (!bOk)
return xloResult.Ret();
//}}XLP_SRC
Notice that the local variable is first initialised to the value (250.0) that we specified in the Function Wizard. Then the ReadOptional() method is called, which will do one of the following:
Change your code to use the new local variable, so that it reads as shown below:
extern "C" __declspec( dllexport )
LPXLOPER HISTVOL(const COper* Prices, const COper* DaysPerYear)
{
CXlOper xloResult;
BOOL bOk = TRUE;
std::vector<double> vecPrices;
bOk = bOk && Prices->ReadVector(vecPrices, "Prices", xloResult);
double valDaysPerYear = 250.0;
bOk = bOk && DaysPerYear->ReadOptional(valDaysPerYear, "DaysPerYear", xloResult);
if (!bOk)
return xloResult.Ret();
//}}XLP_SRC
double dHistVol;
if (CalcHistVol(vecPrices.begin(), vecPrices.size(), valDaysPerYear, &dHistVol))
xloResult = dHistVol;
else
xloResult = xlerrNum;
return xloResult.Ret();
}
This technique can also be used to read in optional boolean, integer and string values. For more details see COper::ReadOptional() in the class reference.