By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

Date Property

P: n/a
I have a date property in the class and I wanted to assign it a min date.

Public class test

Public Property CreatedBy() As String

Get

Return mCreatedBy

End Get

Set(ByVal Value As String)

mCreatedBy = Value

End Set

End Property

Public Property StartDate() As Date

Get

Return mStartDate

End Get

Set(ByVal Value As Date)

mStartDate = Value

End Set

End Property

end class
<Root>
<row name='name1' testDate='' />
<row name='name1' testDate='2/12/04' />
</Root>

I have an xml and I wanted to be able to assign the values to the
properties.
If I have a date that has a "" value in xml how do I initialize the date
property

If I do

objclassTest.StartDate =
IIf(IsDate(objnode.Attributes.GetNamedItem("testDa te").Value.ToString),
CType(objnode.Attributes.GetNamedItem("testDate"). Value.ToString, Date),
Date.MinValue.ToShortDateString)

I get the error invalid cast from string "" to date.

Please help how do I do this.

Thanks,

Pranav


Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

Instead of using ctype to convert the string to a date try using
datetime.parse

http://msdn.microsoft.com/library/de...parsetopic.asp

Ken
-------------------
"Avanti" <ri******@yahoo.com> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
I have a date property in the class and I wanted to assign it a min date.

Public class test

Public Property CreatedBy() As String

Get

Return mCreatedBy

End Get

Set(ByVal Value As String)

mCreatedBy = Value

End Set

End Property

Public Property StartDate() As Date

Get

Return mStartDate

End Get

Set(ByVal Value As Date)

mStartDate = Value

End Set

End Property

end class
<Root>
<row name='name1' testDate='' />
<row name='name1' testDate='2/12/04' />
</Root>

I have an xml and I wanted to be able to assign the values to the
properties.
If I have a date that has a "" value in xml how do I initialize the date
property

If I do

objclassTest.StartDate =
IIf(IsDate(objnode.Attributes.GetNamedItem("testDa te").Value.ToString),
CType(objnode.Attributes.GetNamedItem("testDate"). Value.ToString, Date),
Date.MinValue.ToShortDateString)

I get the error invalid cast from string "" to date.

Please help how do I do this.

Thanks,

Pranav

Nov 21 '05 #2

P: n/a
Avanti,

I would not use the IIF. It gives mostly a lot of unpredicted results.

Cor
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.