Date Property

  • Thread starter Thread starter Avanti
  • Start date Start date
A

Avanti

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("testDate").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
 
Hi,

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

http://msdn.microsoft.com/library/d...f/html/frlrfsystemdatetimeclassparsetopic.asp

Ken
-------------------
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("testDate").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
 
Avanti,

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

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top