Link to home
Start Free TrialLog in
Avatar of roopi
roopi

asked on

Argument 'DateValue' cannot be converted to type 'Date'.

This is the line giving me the error: Dim CP = DateAdd("m", CouponMonths, CurrentCoupon)

That line is located in the following function:

Function CoupPrev(ByVal CurrentCoupon As Object, ByVal MaturityDate As Object, ByVal PaymentsPerYear As Double, ByVal Basis As Integer)
        ' Date of previous coupon to Current Coupon
        Dim CouponMonths = (12 / PaymentsPerYear) * -1
        Dim CP = DateAdd("m", CouponMonths, CurrentCoupon)
        If EndOfMonth(CurrentCoupon) And Not EndOfMonth(CP) Then
            Do
                CP = DateAdd("d", 1, CP)
            Loop Until EndOfMonth(CP) = True
        End If
        CoupPrev = CP
    End Function

This is the call to a function that then calls the function above causing the error:

BondPrice = KJUNK.BondPrice(CDbl(Me.txtParValue.Text), _
                                          (10 - 12 - 1999), _ ' these will be changed to variables once the code works
                                          (11 - 13 - 2001), _ ' these will be changed to variables once the code works
                                          CDbl(Me.txtRate.Text), _
                                          CDbl(Me.txtYield.Text), _
                                          CDbl(Me.txtRedemption.Text), _
                                          periods, _
                                          0)

I have been given the code to calculate Bond Price and I just need to call the code in the file KJUNK.  I'm not sure what is causing the problem but I feel it has something to do with the way I am passing in the Dates.  I've read up on some documentation but it seems right to me according to everything I have read so far.

Any thoughts?
ASKER CERTIFIED SOLUTION
Avatar of M_o_n_t_y
M_o_n_t_y

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of roopi
roopi

ASKER

Monty I'm going to try that.  CurrentCoupon is a date.

The thing is I was provided with alot of VB6 code and now I'm building an ASP.NET application that uses this code.

I'm not sure if you can tell but this is a Financial Calculator for Bond Price.  Pretty much all I need to do is pass the data into the provided code and display the answer.  However I seem to be getting alot of errors and they are all relating to the date and ojects.

The code wasn't documented so it is difficult to follow and all the dates are being passed as objects.  I'm going to try your suggestion and if it works without to many headaches I'll go with it otherwise I'll cut my loses and just start from scratch and code it myself.

I'll post an update.
A bit off subject, but...  coincidentally I know of an org looking for a Bond Management piece... is your software for Bond Management? If so, is it for those who issue bonds or for those that purchase them? If it's the former, please let me know. Thanks, and good luck!
Avatar of roopi

ASKER

Monty thanks for the advice.  It was excellent and worked perfectly.  We are developing simple financial calculators and a stock market simulator.   Nothing with Bond Management yet...

Thanks again,

Roopi