473,378 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

"Date Is Nothing" fails

apparently references of type Date can not assume the value Nothing, because
the following code fails:

Dim d As Date
.......other code......
If d Is Nothing Then

End If

so then what is the equivalent to Nothing for a reference of type Date ?
Nov 20 '05 #1
13 25256
Date is a value type and value types cannot be null. Think of another way
to identify if the d variable has been given a specific value.
"John A Grandy" <johnagrandy-at-yahoo.com> wrote in
news:#w**************@TK2MSFTNGP10.phx.gbl:
apparently references of type Date can not assume the value Nothing,
because the following code fails:

Dim d As Date
......other code......
If d Is Nothing Then

End If

so then what is the equivalent to Nothing for a reference of type Date
?


Nov 20 '05 #2
* "John A Grandy" <johnagrandy-at-yahoo.com> scripsit:
apparently references of type Date can not assume the value Nothing, because
the following code fails:

Dim d As Date
......other code......
If d Is Nothing Then

End If

so then what is the equivalent to Nothing for a reference of type Date ?


'DateTime' is a so called "value type", not a reference type like
classes are.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
John,
As the other have pointed out Date is a value type, you never really have a
reference to a Date. Unless of course you box the date value, by placing the
date in an object reference, that however is a different matter...

You can however check to see if d = Date.MinValue to see if the date has
been set to a value yet or not.
Dim d As Date
......other code......
If d = Date.MinValue Then
Hope this helps
Jay

"John A Grandy" <johnagrandy-at-yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... apparently references of type Date can not assume the value Nothing, because the following code fails:

Dim d As Date
......other code......
If d Is Nothing Then

End If

so then what is the equivalent to Nothing for a reference of type Date ?

Nov 20 '05 #4
heh....null dates can be a problem :-)

Try this

Declare at class level:
Private _NullDate As Date = Nothing

Then at procedural level try this:

Dim MyDate As Date = Nothing

Dim ThisDate As Date = Now

If MyDate.CompareTo(Me._NullDate) = 0 Then

MsgBox("Date Is Nothing")

End If

If ThisDate.CompareTo(Me._NullDate) <> 0 Then

MsgBox("this is a valid date")

End If
In otherwords, you can set a date to nothing. But you can not directly
compare that date to nothing using the IS verb. Instead use the DateType's
CompareTo() method to compare your working date to a date already set to
nothing.

:-D
Ibrahim (formerVB-MVP)Malluf



"John A Grandy" <johnagrandy-at-yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
apparently references of type Date can not assume the value Nothing, because the following code fails:

Dim d As Date
......other code......
If d Is Nothing Then

End If

so then what is the equivalent to Nothing for a reference of type Date ?

Nov 20 '05 #5
Hi John,.

The following produces the message box.

Dim D as Date
D = Nothing
If D = Nothing Then
MsgBox (D)
End If

This works because although Nothing is a null reference and usually
requires the Is keyword, it is also the default for valuetypes. Thus, in an
equality test with a Date,. the Nothing is taken as a default Date.

Regards,
Fergus
Nov 20 '05 #6
Cor
Hi John,
When I see so many answers, I cannot resist making too an answer, it has to
be something else than all others, this time is was a very hard to do that,
I hope I succeed. It is a little bit an addition to Jay B and Fergus their
answers.
Dim d As Date
......other code......
If d Is Nothing Then


Dim d As Date
Dim mydateSaterdayNight As String
If Not mydateSaterdayNight Is Nothing Then
d = Nothing
'...............
End If

I hope you get a lot more of other responses.

Cor
Nov 20 '05 #7
* hi***************@gmx.at (Herfried K. Wagner [MVP]) scripsit:
apparently references of type Date can not assume the value Nothing, because
the following code fails:

Dim d As Date
......other code......
If d Is Nothing Then

End If

so then what is the equivalent to Nothing for a reference of type Date ?


'DateTime' is a so called "value type", not a reference type like
classes are.


Additional information: In VS.NET Whidbey generics will be introduced
and according to notes posted on the internet there will be a generic
'Nullable' type available (in C#: 'System.Nullable<DateTime>'). Maybe
this will make a solution easier to implement in 2004.

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #8
Herfried,
'Nullable' type available (in C#: 'System.Nullable<DateTime>'). Maybe
I saw that, I thought of the mass of developers who have struggled with
implementing their own.

System.Data.SqlTypes gives you Nullable types now, unfortunately VB.NET does
not yet have the overloaded operators to really leverage the
System.Data.SqlTypes.

Jay
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl... * hi***************@gmx.at (Herfried K. Wagner [MVP]) scripsit:
apparently references of type Date can not assume the value Nothing, because the following code fails:

Dim d As Date
......other code......
If d Is Nothing Then

End If

so then what is the equivalent to Nothing for a reference of type Date
?
'DateTime' is a so called "value type", not a reference type like
classes are.


Additional information: In VS.NET Whidbey generics will be introduced
and according to notes posted on the internet there will be a generic
'Nullable' type available (in C#: 'System.Nullable<DateTime>'). Maybe
this will make a solution easier to implement in 2004.

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #9
Hi John

Test for MinValue if you have not set your date value to anything it will
generally be the minimum value (I think it is #12:00:00 AM# or something
like that)

eg

dim dt as date
if dt = dt.MinValue then
.....
end if
"John A Grandy" <johnagrandy-at-yahoo.com> wrote in message
news:#w**************@TK2MSFTNGP10.phx.gbl...
apparently references of type Date can not assume the value Nothing, because the following code fails:

Dim d As Date
......other code......
If d Is Nothing Then

End If

so then what is the equivalent to Nothing for a reference of type Date ?

Nov 20 '05 #10
Here you can find a solution that work today:
http://nullabletypes.sourceforge.net/

In late 2004 VS.NET Whidbey (.NET Framework 2.0) will give
another general-pourpose solution implemented with
generics that's System.Nullable<T>.

If you wanna compare know more about System.Nullable<T>
and NullableTypes read this:

http://discuss.develop.com/archives/wa.exe?
A2=ind0310e&L=dotnet-cx&T=0&F=&S=&P=2537

Regards, (luKa)
NullableTypes Project Manager

-----Original Message-----
apparently references of type Date can not assume the value Nothing, becausethe following code fails:

Dim d As Date
.......other code......
If d Is Nothing Then

End If

so then what is the equivalent to Nothing for a reference of type Date ?

.

Nov 20 '05 #11
Luca Minudel wrote:
Regards, (luKa)
NullableTypes Project Manager


That's a job title I'd have problems explaining to my mom & grandmother...
<g>

-- Mark
Nov 20 '05 #12
ROFL
Nov 20 '05 #13
~~ NullableTypes Project Manager

Sounds like the team that designs Execution Devices for Death Row.

[No offence Luca, I hope ;-) ]

Fergus
Nov 20 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Westcoast Sheri | last post by:
When I used the "date("nj")" function to generate an invoice, about 1 out of 500 times, nothing comes up <?php $invoicedate = date("nj"); ?> <html><head></head><body> Invoice date: <?php...
0
by: charlesb | last post by:
I have a query that works in the rest of the SQL world "SELECT invoice.*, invoice.Date FROM invoice WHERE (DateDiff("m", Date, Now())=1);" which will give me all of last month's invoices. ...
2
by: ITM | last post by:
Does anyone have an example of an SQL query which returns rows for the year-to-date, but where the "year" commences on August 1st? e.g. select * from mytable where datefield > last august 1st ...
12
by: Yannick | last post by:
Hi, I've got a problem accessing a ms-access db with a sql statement like this: SELECT * FROM laTable WHERE laDate = #05/21/2004# ; with asp.net (vb code) laTable contains a "laDate"...
12
by: Emi Lu | last post by:
Hello all, I have a question about "date" & "timestamp" types in PostgreSQL. I want to setup the default value '0000-00-00' and "0000-00-00 00:00:00" for them. However, it seems that PostgreSQL...
2
by: Oenone | last post by:
In our applications, we use the special value of DateTime.MinValue to represent "null dates" throughout all our code. We recently ran into an issue where we wanted an optional date parameter for a...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
5
by: veaux | last post by:
I'm thinking this is easy but can't get it. I have a table with following: Table1 Date 1/1/2007 Table2 Type 0107 (This is MMYY of above) So I'm having trouble using a query to turn the...
0
by: Curious | last post by:
Hi, I have two columns defined as DateTime type in the Visual Designer, i.e., Dataset.xsd. In the grid to which the columns are bound, they're both displayed as date, for instance, 5/23/2007....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.