Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-11-18
4
Medium Priority
?
2,134 Views
Last Modified: 2013-12-03
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?
0
Comment
Question by:roopi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
M_o_n_t_y earned 1000 total points
ID: 9773445
Hi Roopi,

You're getting the error because CurrentCoupon is not a Date datatype. Make sure you are passing your dates in as a date type, like so:

CType("11-13-2001", Date)

Also, you may want to change your dim statement to:

Dim CP as Date = DateAdd("m", CouponMonths, CurrentCoupon)

Also, is your CurrentCoupon object supposed to be a Date? It's hard to tell 'cause it comes into the function "as Object". Are you sure you don't mean to be adding the date to MaturityDate or something?

                                     Monty
0
 

Author Comment

by:roopi
ID: 9773804
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.
0
 
LVL 1

Expert Comment

by:M_o_n_t_y
ID: 9774068
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!
0
 

Author Comment

by:roopi
ID: 9789392
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
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question