PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
best way to tell if a date is not assigned?
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
best way to tell if a date is not assigned?
![]() |
best way to tell if a date is not assigned? |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
I want to tell if a date is invaid (not assigned yet)
right now i am doing this dim aDate as datetime if aDate.date = #12:00:00 AM# ' not assigned else 'assigned end if which seems to work, but is this the best way to do this? |
|
|
|
#2 |
|
Guest
Posts: n/a
|
I would compare it with DateTime.MinValue instead of hardcoding what you
have there. "Brian Henry" <nospam@nospam.com> wrote in message news:exCS236RGHA.4300@TK2MSFTNGP14.phx.gbl... >I want to tell if a date is invaid (not assigned yet) > > right now i am doing this > > dim aDate as datetime > > > if aDate.date = #12:00:00 AM# > ' not assigned > else > 'assigned > end if > > which seems to work, but is this the best way to do this? > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
If you are using .NET 1.x, you have to use a magic value as you are doing.
You can use Date.MinValue since it is unlilely that you use it. If you are using .NET 2.0 you can use the new nullable value types: Dim dtDate As Nullable(Of Date) If dtDate.HasValue Then MessageBox.Show(dtDate.Value.ToString) Else MessageBox.Show("No date") End If -- Best regards, Carlos J. Quintero MZ-Tools: Productivity add-ins for Visual Studio You can code, design and document much faster: http://www.mztools.com "Brian Henry" <nospam@nospam.com> escribió en el mensaje news:exCS236RGHA.4300@TK2MSFTNGP14.phx.gbl... >I want to tell if a date is invaid (not assigned yet) > > right now i am doing this > > dim aDate as datetime > > > if aDate.date = #12:00:00 AM# > ' not assigned > else > 'assigned > end if > > which seems to work, but is this the best way to do this? > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
wow didn't know abou the nullable types... definatly going to have to look
into that... now if the controls just were nullable like in a date time picker and such... |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Hi Brian,
Nullable types are new in .NET 2.0 using the new generics (Of T) capabilities. In .NET 1.x you had to use magic values or implement your own NullableDate type (there were some implementations out there). For backwards compatibility the controls may not accept nullable types, but you can extend them easily with a user control and a new property. The datetime picker has a ShowCheckbox property or similar. -- Best regards, Carlos J. Quintero MZ-Tools: Productivity add-ins for Visual Studio You can code, design and document much faster: http://www.mztools.com "Brian Henry" <nospam@nospam.com> escribió en el mensaje news:O7C19sCSGHA.524@TK2MSFTNGP10.phx.gbl... > wow didn't know abou the nullable types... definatly going to have to look > into that... now if the controls just were nullable like in a date time > picker and such... > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

