Results 1 to 6 of 6

Thread: [RESOLVED] Random exception thrown when setting valid month values.

  1. #1

    Thread Starter
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Resolved [RESOLVED] Random exception thrown when setting valid month values.

    The exception message I am receiving is this...
    "Year, Month, and Day parameters describe an un-representable DateTime."

    Now I've traced my values being passed and everything is correct. Values loops through 1 to 12 but still I continue to receive an exception. Only way I can avoid this is by throwing a Try, Catch statement around where I'm passing over the value. Now I'm un settling with this as a solution so I'd prefer to figure this out and fix it rather than over looking it with a try, catch.

    Here's my code..

    Code:
    001 Dim Calendar(11) As AppointmentBookControl.AppointmentBookControlMonthlyOverviewCalendarControl
    002
    003 For i As Integer = 0 to Calendar.GetUpperBound(0)
    004    Calendar(i) = New AppointmentBookControl.AppointmentBookControlMonthlyOverviewCalendarControl
    005
    006    Me.CalendarContainer.Controls.Add(Calendar(i))
    007    With Calendar(i)
    008       .BackColor = Color.White
    009       .Width = [Region].Width-16
    010       .Location = New Point(8, 8+i*(.Height+8))
    011      .Month = i+1
    012       .Name = "CalendarControl" & i.ToString()
    013    End With
    014 Next i

    Line '011 .Month = i+1' is where the problem is located. The values for (i+1) maintain within the bounds of 1 through 12.. yet still cause an issue.

    Any help would be greatly appreciated.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,174

    Re: Random exception thrown when setting valid month values.

    Just because you are using a valid month value, doesn't mean that the combination of year, month and day values represents a valid date. Presumably the day is not valid for the month.

  3. #3

    Thread Starter
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: Random exception thrown when setting valid month values.

    Thanks jmcilhinney with that in mind I'll dig a little deeper into this. I'm still unsure of why my day's would be invalid for a particular month when I've created a function to return the length of any given month even for leap year. All values for which are returning correctly.

  4. #4
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Random exception thrown when setting valid month values.

    Check what are the values of .day and .year before you set .month to i+1.

    What properties and how they initialized in a NEW AppointmentBookControl
    Last edited by kaliman79912; May 30th, 2011 at 11:56 AM.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,174

    Re: Random exception thrown when setting valid month values.

    There's already a function to return the length of any given month even for leap years, i.e. Date.DaysInMonth.

    The exception says that the year, month and day are not a valid date. What are the year month and day values when the exception is thrown? That should obviously be the first thing you look at, given that that's what the exception refers to specifically.

  6. #6

    Thread Starter
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: Random exception thrown when setting valid month values.

    I figured it out! I checked which month was causing the exception and it turned out to be February. So from there I broke it down to see which date was actually trying to be set as a date that was invalid. So I found from within my calendar control that I had a property for day, which now I'm unsure of why I even had it to begin with.. However though this value was being initialized along side the calendars value property which initialized as today's date then can be changed accordingly by run time or design time. When I changed the month property, the day value gets passed too so when it was time for February the day being passed was today of course, the 30th. Which is not a valid date for February.

    The 'Date.DaysInMonth' function I did not know of. I'm actually still in the process of migrating to .net from many many years of working with vb6, so you can understand that I'm used to doing things myself lol

    Thanks for all your help guys!
    Last edited by DavesChillaxin; May 30th, 2011 at 09:44 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width