Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't find an error in my code

Status
Not open for further replies.

jayjay60

Programmer
Jun 19, 2001
97
FR
I have created a function which returns parameters from a database. The database (Access) have 2 columns, where in the first there are dates, and in 2nd Rate. I use ADO method. In the following code, InterpoleDate is a simple linear interpolation method , i have tested and which runs correctly. My problem is that the method ReturnParamSimple returns stupid values. So, i would like to know if anybody could help me to find my error?

double EuropeanSwaption ::ReturnParamSimple(COleDateTime EndDate,_variant_t IndexColumn,_variant_t ParameterTable)
{
double Parameter1,Parameter2,Parameter;
COleDateTime Date1,Date2;
CString strTemp;
strTemp.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Swaption\\taux.mdb;");
_bstr_t strcnn(strTemp);
_RecordsetPtr pTp("ADODB.Recordset");


try
{

pTp->Open(ParameterTable,strcnn,adOpenStatic,adLockOptimistic,adCmdTableDirect);
pTp->MoveFirst();
if(EndDate<pTp->Fields->GetItem(&quot;date&quot;)->Value)
{
Date1=pTp->Fields->GetItem(&quot;date&quot;)->Value;
Parameter1=pTp->Fields->GetItem(IndexColumn)->Value;
pTp->MoveNext();
Date2=pTp->Fields->GetItem(&quot;date&quot;)->Value;
Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;
Parameter=InterpolDate(Date1,Date2,EndDate,Parameter1,Parameter2);
}
else
{
while(EndDate>pTp->Fields->GetItem(&quot;date&quot;)->Value)
{
pTp->MoveNext();
if(pTp->EndOfFile)
{
pTp->MovePrevious();
Date2=pTp->Fields->GetItem(&quot;date&quot;)->Value;
Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;
pTp->MovePrevious();
Date1=pTp->Fields->GetItem(&quot;date&quot;)->Value;
Parameter1=pTp->Fields->GetItem(IndexColumn)->Value;
Parameter=InterpolDate(Date1,Date2,EndDate,Parameter1,Parameter2);
}
}
if(EndDate==pTp->Fields->GetItem(&quot;date&quot;)->Value)
{
Parameter=pTp->Fields->GetItem(&quot;IndexColumn&quot;)->Value;
}
else
{
Date2=pTp->Fields->GetItem(&quot;date&quot;)->Value;
Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;
pTp->MovePrevious();
Date1=pTp->Fields->GetItem(&quot;date&quot;)->Value;
Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;
Parameter=InterpolDate(Date1,Date2,EndDate,Parameter1,Parameter2);
}
}
pTp->Close();
}
catch(_com_error &e)
{
AfxMessageBox(&quot;Ne peut pas accéder à la table&quot;);
pTp->Close();
}
return Parameter;
}

thanks in advance

jayjay
 
Try to see if you get single byte(ansi) or two byte(unicode) strings as result. If you get unicode, try to convert to ansi. Also use more intensive _variant_t. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top