|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Date Errors in .NET 2.0***** Public Property DOB() As Date Get Try DOB = (msBirthMonth + "/" + msBirthDay + "/" + msBirthYear) Catch e As Exception DOB = Nothing End Try End Get Set(ByVal d As Date) Try msBirthMonth = Month(d).ToString msBirthDay = Day(d).ToString msBirthYear = Year(d).ToString Catch ex As Exception msBirthMonth = "" msBirthDay = "" msBirthYear = "" End Try End Set End Property **** values passed are: msBirthMonth = '01' msBirthDay = '01' msBirthYear = '1950' *** The error that I get is, "Conversion from String "01/01/1950" to type date is not valid" This code worked in .NET 1.1, now that I'm converting to .NET 2.0, this code no longer works. Any suggestions? Milissa,
Consider using a Date constructor instead: | DOB = (msBirthMonth + "/" + msBirthDay + "/" + Return New Date(CInt(msBirthYear), CInt(msBirthMonth), CInt(msBirthDay))| msBirthYear) -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net <melissa.n***@gmail.com> wrote in message news:1147123802.871945.44190@y43g2000cwc.googlegroups.com... | Here is my code: | | ***** | | Public Property DOB() As Date | Get | Try | | DOB = (msBirthMonth + "/" + msBirthDay + "/" + | msBirthYear) | | Catch e As Exception | | DOB = Nothing | End Try | End Get | Set(ByVal d As Date) | Try | msBirthMonth = Month(d).ToString | msBirthDay = Day(d).ToString | msBirthYear = Year(d).ToString | Catch ex As Exception | msBirthMonth = "" | msBirthDay = "" | msBirthYear = "" | End Try | End Set | | End Property | | **** | values passed are: | msBirthMonth = '01' | msBirthDay = '01' | msBirthYear = '1950' | | *** | | The error that I get is, "Conversion from String "01/01/1950" to type | date is not valid" | | This code worked in .NET 1.1, now that I'm converting to .NET 2.0, this | code no longer works. | | Any suggestions? | Ok, I tried returning the new date as you suggested - no luck...
I tried DOB = new date(...) no luck... I tried dim mydate as date - put values in there and then dob = mydate .... no luck Setting a date property should be easier than this... Had the issue been the fact that the string was originally in dd/mm/yyyy format, converting the strings to integers should have resolved any of those problems, but yet overriding the values and hard-coding the date value should have resolved something also, which it still errors. I have been stepping through debug, and msBirthMonth, ...day, ...year are passing properly. This is not the only date function that has errored on the conversion to .NET 2.0 - ALL dates in the application are not returning appropriate values. Instead all I get is #12:00:00 AM# for the dob values in my watch. These are simply drop down boxes on an ASPX page that stores their values into birthmonth, birthyear and birthday. Those are then converted by public properties to strings as msbirthmonth, msbirthday, msbirthyear - then those string values are put in the date... Melissa,
| Ok, I tried returning the new date as you suggested - no luck... By "no luck" what do you mean, what is the specific error you are getting. | I tried DOB = new date(...) no luck... Where specifically are you seeing a problem & what specifically is the problem. Are you certain (absolutely certain) that this routine is failing & not another routine? My code assumes that msBirthMonth, msBirthDay, and msBirthYear are strings with numbers in them and are in the respective ranges. Göran's code will ensure they are integers. For example: Dim msBirthMonth As String = "01" Dim msBirthDay As String = "01" Dim msBirthYear As String = "1950" Dim aDate As Date = New Date(CInt(msBirthYear), CInt(msBirthMonth), CInt(msBirthDay)) Sets the aDate variable to #1/1/1950#. Moving from .NET 1.1 to .NET 2.0 would not (should not) affect your date logic. | Setting a date property should be easier than this... Private m_dobIt is! Public Property DOB() As Date Get Return m_dob End Get Set(ByVal value As Date) m_dob = value End Set End Property Is all the code for DOB really needs. It really depends on how msBirthMonth, ...day, ...year are being used elsewhere if they are actually needed or not... | I have been Are you getting tripped up in PostBack? Remember a web page's object get | stepping through debug, and msBirthMonth, ...day, ...year are passing | properly. recreated each time they post back, if you set the DOB property when the page is initially displayed, then attempt to use DOB in the post back (in response to a button click for example) then msBirthMonth, ...day, ...year (ergo DOB) will have reverted to blanks... -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Melissa Nava" <melissa.n***@gmail.com> wrote in message news:1147133437.273314.293680@i40g2000cwc.googlegroups.com... | Ok, I tried returning the new date as you suggested - no luck... | I tried DOB = new date(...) no luck... | I tried dim mydate as date - put values in there and then dob = mydate | ... no luck | | Setting a date property should be easier than this... Had the issue | been the fact that the string was originally in dd/mm/yyyy format, | converting the strings to integers should have resolved any of those | problems, but yet overriding the values and hard-coding the date value | should have resolved something also, which it still errors. I have been | stepping through debug, and msBirthMonth, ...day, ...year are passing | properly. | | This is not the only date function that has errored on the conversion | to .NET 2.0 - ALL dates in the application are not returning | appropriate values. Instead all I get is #12:00:00 AM# for the dob | values in my watch. | | These are simply drop down boxes on an ASPX page that stores their | values into birthmonth, birthyear and birthday. Those are then | converted by public properties to strings as msbirthmonth, msbirthday, | msbirthyear - then those string values are put in the date... | > By "no luck" what do you mean, what is the specific error you are getting. By "no luck" I mean that no matter how I try to set the DOB as a date,> Where specifically are you seeing a problem & what specifically is the > problem. Are you certain (absolutely certain) that this routine is failing & > not another routine? I get the "Conversion from String "01/01/1950" to type date is not valid" exception error thrown in the get statement. Show quoteHide quote >| Public Property DOB() As Date In theory yes, this should work and if I put it in other areas of the>| Get >| Try >| DOB = (msBirthMonth + "/" + msBirthDay + "/" + msBirthYear) >| Catch e As Exception >| DOB = Nothing >| End Try >| End Get > My code assumes that msBirthMonth, msBirthDay, and msBirthYear are strings > with numbers in them and are in the respective ranges. Göran's code will > ensure they are integers. > For example: > Dim msBirthMonth As String = "01" > Dim msBirthDay As String = "01" > Dim msBirthYear As String = "1950" > Dim aDate As Date = New Date(CInt(msBirthYear), CInt(msBirthMonth), > CInt(msBirthDay)) > Sets the aDate variable to #1/1/1950#. project, it works and returns an appropriate value. Inside of my variableobject code within my Get/Set statement, this same code (that works elsewhere) fails with an exception. > It really depends on how msBirthMonth, ...day, ...year are being used They are used throughout the application for various purposes,> elsewhere if they are actually needed or not... determining the age of an applicant to see if they are filing the appropriate application, adding it to the database, checking for various things such as if an applicant states that they were born in 1999, but had an absence during 1998, it will let them know that they cannot report absences for a time before they were born...etc. So yes, the DOB and different day, month, year values are used multiple times throughout the application. > Are you getting tripped up in PostBack? Remember a web page's object get I wish it was that easy... For DOB to revert to blank it would have to> recreated each time they post back, if you set the DOB property when the > page is initially displayed, then attempt to use DOB in the post back (in > response to a button click for example) then msBirthMonth, ...day, ...year > (ergo DOB) will have reverted to blanks... have a value at some point. At this point I cannot get it to hold a value at all. Stepping through debugger, it never even gets a value, the values in the msBirthday, msBirthYear and msBirthMonth will hold appropriate values. I have even tried using other values as the application also holds birthdate information in regular Birthday, BirthMonth and BirthYear... I have found a way to bypass the DOB property, which will get me past the applications validations, error handling, and let me continue through the application, but at the end of the application since the DOB VO property is nothing it will error on database save. (So If I don't fix it now, I can bypass this problem, but eventually I have to figure it out. *bleh*) I have encorporated the help of a Systems Programmer V here at my work and this has him confused as well... Especially due to the fact that the code is working if it is outside of the variable object. Of course, thank you for your help, so far we have tried using everyone's suggestions to no avail, but we definately know a dozen ways that this won't work now! :) Melissa,
Can you post or send me a "Short but Complete" sample that demonstrates the problem? For "Short but Complete" see: http://www.yoda.arachsys.com/csharp/complete.html If you can get it down to 15 to 20 lines that consistently cause the problem feel free to post them here. If you have substantially more you may email directly, this email address is not mangled... -- Hope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Melissa Nava" <melissa.n***@gmail.com> wrote in message By "no luck" I mean that no matter how I try to set the DOB as a date,news:1147208212.619116.48520@g10g2000cwb.googlegroups.com... > By "no luck" what do you mean, what is the specific error you are getting. > Where specifically are you seeing a problem & what specifically is the > problem. Are you certain (absolutely certain) that this routine is failing > & > not another routine? I get the "Conversion from String "01/01/1950" to type date is not valid" exception error thrown in the get statement. Show quoteHide quote >| Public Property DOB() As Date In theory yes, this should work and if I put it in other areas of the>| Get >| Try >| DOB = (msBirthMonth + "/" + msBirthDay + "/" + >msBirthYear) >| Catch e As Exception >| DOB = Nothing >| End Try >| End Get > My code assumes that msBirthMonth, msBirthDay, and msBirthYear are strings > with numbers in them and are in the respective ranges. Göran's code will > ensure they are integers. > For example: > Dim msBirthMonth As String = "01" > Dim msBirthDay As String = "01" > Dim msBirthYear As String = "1950" > Dim aDate As Date = New Date(CInt(msBirthYear), > CInt(msBirthMonth), > CInt(msBirthDay)) > Sets the aDate variable to #1/1/1950#. project, it works and returns an appropriate value. Inside of my variableobject code within my Get/Set statement, this same code (that works elsewhere) fails with an exception. > It really depends on how msBirthMonth, ...day, ...year are being used They are used throughout the application for various purposes,> elsewhere if they are actually needed or not... determining the age of an applicant to see if they are filing the appropriate application, adding it to the database, checking for various things such as if an applicant states that they were born in 1999, but had an absence during 1998, it will let them know that they cannot report absences for a time before they were born...etc. So yes, the DOB and different day, month, year values are used multiple times throughout the application. > Are you getting tripped up in PostBack? Remember a web page's object get I wish it was that easy... For DOB to revert to blank it would have to> recreated each time they post back, if you set the DOB property when the > page is initially displayed, then attempt to use DOB in the post back (in > response to a button click for example) then msBirthMonth, ...day, ...year > (ergo DOB) will have reverted to blanks... have a value at some point. At this point I cannot get it to hold a value at all. Stepping through debugger, it never even gets a value, the values in the msBirthday, msBirthYear and msBirthMonth will hold appropriate values. I have even tried using other values as the application also holds birthdate information in regular Birthday, BirthMonth and BirthYear... I have found a way to bypass the DOB property, which will get me past the applications validations, error handling, and let me continue through the application, but at the end of the application since the DOB VO property is nothing it will error on database save. (So If I don't fix it now, I can bypass this problem, but eventually I have to figure it out. *bleh*) I have encorporated the help of a Systems Programmer V here at my work and this has him confused as well... Especially due to the fact that the code is working if it is outside of the variable object. Of course, thank you for your help, so far we have tried using everyone's suggestions to no avail, but we definately know a dozen ways that this won't work now! :) I put this thing aside for about a week worked on some other areas and
then returned to it about a half an hour ago. The solution was very simple. A combination of suggestions: DOB = new date(Cint(msbirthyear), Cint(msbirthmonth), Cint(msbirthday)) Return DOB I knew it had to be simple... I thought I tried that to begin with, but perhaps I didn't. Thanks for everyone's help. <melissa.n***@gmail.com> wrote in message
Show quoteHide quote news:1147123802.871945.44190@y43g2000cwc.googlegroups.com... for one thing, DOB is declared as Date and your GET returns a string value > Here is my code: > > ***** > > Public Property DOB() As Date > Get > Try > > DOB = (msBirthMonth + "/" + msBirthDay + "/" + > msBirthYear) > > Catch e As Exception > > DOB = Nothing > End Try > End Get > Set(ByVal d As Date) > Try > msBirthMonth = Month(d).ToString > msBirthDay = Day(d).ToString > msBirthYear = Year(d).ToString > Catch ex As Exception > msBirthMonth = "" > msBirthDay = "" > msBirthYear = "" > End Try > End Set > > End Property > .... > **** values passed to what ? how ? your SET wants a single Date argument ... > values passed are: > msBirthMonth = '01' > msBirthDay = '01' > msBirthYear = '1950' you're passing it three strings ? > *** you were probably doing implicit conversions with Option Strict Off ... I > > The error that I get is, "Conversion from String "01/01/1950" to type > date is not valid" > > This code worked in .NET 1.1, now that I'm converting to .NET 2.0, this > code no longer works. can't really follow your code or your intent; turning Option Strict OFF might do the trick here but I would re-think the whole thing and get all the data typing and logic straight it looks like you want to pass a date value in and then return a string value .... but then it doesn't .... it's confused; and the Try ... Catch in your GET is suspect ... what is it you're doing there ? why not just control the input ? and the purpose of setting DOB = Nothing is what ? I'm fixing mumbled jumbled contractor code while converting from .NET
1.1 to .NET 2.0. This was code that they origionally had a contractor do and on conversion it all died! So as far as the why's, what for's... I have no idea why they did half of anything to begin with. > values passed to what ? how ? your SET wants a single Date argument ... They passed string values from textboxes into variables, it's stored in> you're passing it three strings ? variables under applicant.dob.month, applicant.dob.day, applicant.dob.year - and then they passed it into the msBirthMonth, msBirthDay, msBirthYear ...and then changed to BirthMonth, BirthYear, BirthDay later... then converted into a date, but it still uses string values further in the application, but the end result is that it's stored as a date in SQLServer... o.O > you were probably doing implicit conversions with Option Strict Off ... I Thanks, I'll try that.> can't really follow your code or your intent; turning Option Strict OFF > might do the trick here but I would re-think the whole thing and get all the > data typing and logic straight > it looks like you want to pass a date value in and then return a string I can't even answer why they did that. Just that I have to fix all this> value .... but then it doesn't .... it's confused; and the Try ... Catch in > your GET is suspect ... what is it you're doing there ? why not just control > the input ? and the purpose of setting DOB = Nothing is what ? code. :| Melissa Nava wrote:
> I'm fixing mumbled jumbled contractor code while converting from .NET The problem isn't really the conversion from 1.1 to 2.0, but the fact > 1.1 to .NET 2.0. > > This was code that they origionally had a contractor do and on > conversion it all died! So as far as the why's, what for's... I have no > idea why they did half of anything to begin with. that the code is badly written to start with. (Apologies to the original author for being so frank...) It uses an implicit conversion from a string to date, which means that it uses the current culture to decide how to parse the string. Unless the application specifically sets the culture, the code is very sensetive to changes in the environment. For parsing the strings into a date you could use something like: Dim m as Integer, d as Integer, y as Integer If Integer.TryParse(msBirthYear, y) and Integer.TryParse(msBirthMonth, m) and Integer.TryParse(msBirthDay, d) Then DOB = New Date(y, m, d) Else DOB = Nothing End If [With reservations for errors - I don't usually program VB] >> values passed to what ? how ? your SET wants a single Date argument ... As it is a date, it should really be handled as a date throughout the >> you're passing it three strings ? > > They passed string values from textboxes into variables, it's stored in > variables under applicant.dob.month, applicant.dob.day, > applicant.dob.year - and then they passed it into the msBirthMonth, > msBirthDay, msBirthYear ...and then changed to BirthMonth, BirthYear, > BirthDay later... then converted into a date, but it still uses string > values further in the application, but the end result is that it's > stored as a date in SQLServer... o.O application, not a bunch of strings. Show quoteHide quote >> you were probably doing implicit conversions with Option Strict Off ... I >> can't really follow your code or your intent; turning Option Strict OFF >> might do the trick here but I would re-think the whole thing and get all the >> data typing and logic straight > > Thanks, I'll try that. > >> it looks like you want to pass a date value in and then return a string >> value .... but then it doesn't .... it's confused; and the Try ... Catch in >> your GET is suspect ... what is it you're doing there ? why not just control >> the input ? and the purpose of setting DOB = Nothing is what ? > > I can't even answer why they did that. Just that I have to fix all this > code. :| > "Melissa Nava" <melissa.n***@gmail.com> wrote in message oh. been there and done that ... I usually start over; it's faster and news:1147160412.015142.22590@i39g2000cwa.googlegroups.com... > I'm fixing mumbled jumbled contractor code while converting from .NET > 1.1 to .NET 2.0. you get better code ... provided that your "powers that be" can bear the thought of throwing away the garbage they paid for ....
VB .NET very slow in design
control array question for VB.Net 2005 File copy VB Exp 2005 Thread Sync Queue Problem umanaged code - array error Outlook Add In is not shown for 1 user... Regular expression rejecting invalid files Standarddrucker mit .Net ermitteln Option Strict On does not cause compilation error Ignoring mouse event from contained controls |
|||||||||||||||||||||||