xml.innertext to Date - cannot convert when innertext is blank

Kyle.Allbright

Active member
Joined
Apr 19, 2010
Messages
28
Programming Experience
1-3
Hey guys, Ok the problem is with this code:


Calc.DateLongToDateShort(tempxmlnodelist(j).Item("_date").InnerText) < Date.Now Then

If the innertext is a correct date, then the equation suceeds, however when the innerText is blank, which sometimes it will be, it throws exception cannot convert "" to Date. Now this makes sense of course.

I am wondering if there is a "simple" way to avoid this error, without needing to add lines such as:

if innertext <> "" then
if innertext < date

I am wondering this as the full expression I am running is similiar to:

If x = True Or Innertext < Date And innerText > prevDate
therefore I would need alot of added blocks of code, in order to prevent exceptions.

Thanks guys.

Note: The "Calc.DateLongToDateShort" method converts the input date of innerText from 19 February 2009 to 19/02/2009
 
If more lines of code are needed to proof your values and save you from throwing exceptions - especially when you know there is no guaranty of correct values then it is fine to do so. And it would be better practice then just simply Try/Catch for most cases.
 
Thanks guys; I have fixed the problem with doing a few overloaded if statements, not the neatest result I was hoping for, perhaps the method I was looking for does not exist lol.


[SOLVED]
 
Back
Top