|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
best way to tell if a date is not assigned?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? I would compare it with DateTime.MinValue instead of hardcoding what you
have there. Show quoteHide quote "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? > 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 -- Show quoteHide quoteBest 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? > 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... 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. -- Show quoteHide quoteBest 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... >
length of string
Adding Button Programatically - have an answer??? XML to ODBC DataView Multiple Change Sub Main is not waiting!!!?? Visual Studio 2003 Menu on form.vb Adding data to database Sending web email including resource files XmlDocument object to string - plase help with unusual character! |
|||||||||||||||||||||||