Click to See Complete Forum and Search --> : BetaInv Calling problem


seguprasad
May 26th, 2006, 03:55 AM
Hi All,

I am working on Excel Add-in Development.

I want to do some calculations, for that I am using Excel's, BetaInv of Worksheetfunction class.

But If I call BetaInv, then my application is giving Access Violation error.

Can any body help me, how to implent BetaInv in VC++/V++ ?

Below is the code I wrote for this.
----------------------------
#include "stdafx.h"
#include "Calcs.h"
#include "excel9.h"

double Calcs::Beta2(double Alpha, double Beta, double a, double b, double RandNumber)
{
double dValue;
VARIANT v1;
VARIANT v2;

v1.dblVal = 0;
v2.dblVal = 1;

LPDISPATCH lpDisp; // Often reused variable.

_Application app;

if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Couldn't CreateDispatch() for Excel");
return 0;
}

WorksheetFunction objWF;
lpDisp = app.GetWorksheetFunction();
ASSERT(lpDisp);

objWF.AttachDispatch(lpDisp);

dValue = objWF.BetaInv(0.5, 2.5, 2.5, v1, v2); //If I execute this line, application is raising access violation error.
return dValue;
}
----------------------------------------

If possible please look at the above code, and let me know where I did wrong?

Thank you,
Segu.

Tom Frohman
May 30th, 2006, 09:53 AM
Something to try:

double dValue;
VARIANT v1;
VARIANT v2;

// Try adding these two lines to tell what type of value is stored in the //VARIANT
v1.vt=VT_R8;
v2.vt=VT_R8;


v1.dblVal = 0;
v2.dblVal = 1;

seguprasad
May 31st, 2006, 05:43 AM
Tom,

Thanks for the response.

I did try with your suggestion, but still it is giving the same error.