M
Mark Rae
Hi,
I have a Web Service with a WebMethod called getRepaymentSchedule which
returns an array. Internally, the array is built up using a struct, as
follows:
public struct RepaymentSchedule
{
public int nPeriod;
public double dRepaymentAmt;
public double dInterestAmt;
}
The WebMethod is as follows:
[WebMethod]
public RepaymentSchedule[] getRepaymentSchedule(int nStartingPeriod,
double dCapital, double dRepayment, double dIntRate, int nPeriod, int nTerm)
{
RepaymentSchedule[] Repayments = null;
double dRepaymentAmt = 0; // repayment amount of monthly repayment
double dInterestAmt = 0; // interest amount of monthly repayment
int intPeriod = 0;
if(dIntRate > 1)
{
dIntRate = dIntRate / 100;
}
Repayments = new RepaymentSchedule[nPeriod];
for(intPeriod = 1; intPeriod <= nTerm; intPeriod++)
{
if(intPeriod <= nPeriod)
{
dRepaymentAmt = Microsoft.VisualBasic.Financial.PPmt(dIntRate / 12,
intPeriod, nTerm, -dCapital, 0, Microsoft.VisualBasic.DueDate.EndOfPeriod);
dRepaymentAmt = Convert.ToDouble(((dRepaymentAmt + 0.005) * 100) /
100);
dInterestAmt = dRepayment - dRepaymentAmt;
dInterestAmt = Convert.ToDouble(((dInterestAmt + 0.005) * 100) / 100);
Repayments[intPeriod -1].nPeriod = (nStartingPeriod - 1) + intPeriod;
Repayments[intPeriod -1].dRepaymentAmt = dRepaymentAmt;
Repayments[intPeriod -1].dInterestAmt = dInterestAmt;
}
}
return Repayments;
}
No problem to call this Web Service from another C# Web app or C# Windows
app, as follows:
Array aSchedule = getRepaymentSchedule(1, dCapital, dMR1, dIR1, nPeriod1,
nTerm);
That returns me an array. I can interrogate its Length, but I don't know how
to reference the individual parts of each element in the array. From the
Debug window, I can write something like:
?aSchedule.GetValue(0).nPeriod
which works, but this creates an error if I add it to the body of the code.
I'm obviously missing something totally obvious, and it's driving me crazy!
Any assistance gratefully received.
Best regards,
Mark Rae
I have a Web Service with a WebMethod called getRepaymentSchedule which
returns an array. Internally, the array is built up using a struct, as
follows:
public struct RepaymentSchedule
{
public int nPeriod;
public double dRepaymentAmt;
public double dInterestAmt;
}
The WebMethod is as follows:
[WebMethod]
public RepaymentSchedule[] getRepaymentSchedule(int nStartingPeriod,
double dCapital, double dRepayment, double dIntRate, int nPeriod, int nTerm)
{
RepaymentSchedule[] Repayments = null;
double dRepaymentAmt = 0; // repayment amount of monthly repayment
double dInterestAmt = 0; // interest amount of monthly repayment
int intPeriod = 0;
if(dIntRate > 1)
{
dIntRate = dIntRate / 100;
}
Repayments = new RepaymentSchedule[nPeriod];
for(intPeriod = 1; intPeriod <= nTerm; intPeriod++)
{
if(intPeriod <= nPeriod)
{
dRepaymentAmt = Microsoft.VisualBasic.Financial.PPmt(dIntRate / 12,
intPeriod, nTerm, -dCapital, 0, Microsoft.VisualBasic.DueDate.EndOfPeriod);
dRepaymentAmt = Convert.ToDouble(((dRepaymentAmt + 0.005) * 100) /
100);
dInterestAmt = dRepayment - dRepaymentAmt;
dInterestAmt = Convert.ToDouble(((dInterestAmt + 0.005) * 100) / 100);
Repayments[intPeriod -1].nPeriod = (nStartingPeriod - 1) + intPeriod;
Repayments[intPeriod -1].dRepaymentAmt = dRepaymentAmt;
Repayments[intPeriod -1].dInterestAmt = dInterestAmt;
}
}
return Repayments;
}
No problem to call this Web Service from another C# Web app or C# Windows
app, as follows:
Array aSchedule = getRepaymentSchedule(1, dCapital, dMR1, dIR1, nPeriod1,
nTerm);
That returns me an array. I can interrogate its Length, but I don't know how
to reference the individual parts of each element in the array. From the
Debug window, I can write something like:
?aSchedule.GetValue(0).nPeriod
which works, but this creates an error if I add it to the body of the code.
I'm obviously missing something totally obvious, and it's driving me crazy!
Any assistance gratefully received.
Best regards,
Mark Rae