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

Optional date parameter initialization

P: n/a
I am migrating my first vb6 app to vb.net 2003.

In the vb6 app a number of subs had optional date parameters:
Sub Fred ( ... ,optional FromDate as Date = 0...)

I need something like zero in there to see if the parameter has been used or
not.

In vb.net the imported code fails with:
Value of type 'Integer' cannot be converted to 'Date'

I have to supply a default value for the date - is there anything I can use
that obviously indicates that the parameter has not been supplied by the
caller?

--
John Austin
Nov 21 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
I have to supply a default value for the date - is there anything I can use
that obviously indicates that the parameter has not been supplied by the
caller?


No, you either have to pick one date value to magically represent the
missing state, or use method overloading.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2

P: n/a
"John Austin" <Jo*********@nospam.nospam> schrieb:
In the vb6 app a number of subs had optional date parameters:
Sub Fred ( ... ,optional FromDate as Date = 0...)

I need something like zero in there to see if the parameter has been used
or
not.

In vb.net the imported code fails with:
Value of type 'Integer' cannot be converted to 'Date'

I have to supply a default value for the date - is there anything I can
use
that obviously indicates that the parameter has not been supplied by the
caller?


I have recently written an article in German about supporting nullable date
and time values. Maybe you'll find some of the code snippets useful:

<URL:http://dotnet.mvps.org/dotnet/articles/nullabledates/>

In VB.NET 'Nothing' referes to a value type's default value. Thus you can
specify 'Nothing' as default value for the parameter. Note that this
doesn't work with VB 2002/2003, but will be supported in VB 2005. In
general I don't recommend to rely on a certain value to be interpreted as a
null value.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

P: n/a
I have to supply a default value for the date - is there anything I can use
that obviously indicates that the parameter has not been supplied by the
caller?


No, you either have to pick one date value to magically represent the
missing state, or use method overloading.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #4

P: n/a
>
I have recently written an article in German about supporting nullable
date and time values. Maybe you'll find some of the code snippets useful:


The online translators don't do a very good job of turning this into english
:(
Nov 21 '05 #5

P: n/a
Yes MS have always had a blind spot with dates - a 'leaving date' in an
employee record needs to be blank until they leave, but even with VB6 dates
there was no equivalent of 'blank date' (which would map to NULL in SQL). I
wish they would see the light!
--
John Austin
"Herfried K. Wagner [MVP]" wrote:
"John Austin" <Jo*********@nospam.nospam> schrieb:
In the vb6 app a number of subs had optional date parameters:
Sub Fred ( ... ,optional FromDate as Date = 0...)

I need something like zero in there to see if the parameter has been used
or
not.

In vb.net the imported code fails with:
Value of type 'Integer' cannot be converted to 'Date'

I have to supply a default value for the date - is there anything I can
use
that obviously indicates that the parameter has not been supplied by the
caller?


I have recently written an article in German about supporting nullable date
and time values. Maybe you'll find some of the code snippets useful:

<URL:http://dotnet.mvps.org/dotnet/articles/nullabledates/>

In VB.NET 'Nothing' referes to a value type's default value. Thus you can
specify 'Nothing' as default value for the parameter. Note that this
doesn't work with VB 2002/2003, but will be supported in VB 2005. In
general I don't recommend to rely on a certain value to be interpreted as a
null value.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6

P: n/a
"John Austin" <Jo*********@nospam.nospam> schrieb:
Yes MS have always had a blind spot with dates - a 'leaving date' in an
employee record needs to be blank until they leave, but even with VB6
dates
there was no equivalent of 'blank date' (which would map to NULL in SQL).
I
wish they would see the light!


..NET's 'SqlDateTime' supports null values even in current versions of
..NET... Maybe it's suitable in your scenario.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7

P: n/a
"John Austin" <Jo*********@nospam.nospam> schrieb:
In the vb6 app a number of subs had optional date parameters:
Sub Fred ( ... ,optional FromDate as Date = 0...)

I need something like zero in there to see if the parameter has been used
or
not.

In vb.net the imported code fails with:
Value of type 'Integer' cannot be converted to 'Date'

I have to supply a default value for the date - is there anything I can
use
that obviously indicates that the parameter has not been supplied by the
caller?


I have recently written an article in German about supporting nullable date
and time values. Maybe you'll find some of the code snippets useful:

<URL:http://dotnet.mvps.org/dotnet/articles/nullabledates/>

In VB.NET 'Nothing' referes to a value type's default value. Thus you can
specify 'Nothing' as default value for the parameter. Note that this
doesn't work with VB 2002/2003, but will be supported in VB 2005. In
general I don't recommend to rely on a certain value to be interpreted as a
null value.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #8

P: n/a
>
I have recently written an article in German about supporting nullable
date and time values. Maybe you'll find some of the code snippets useful:


The online translators don't do a very good job of turning this into english
:(
Nov 21 '05 #9

P: n/a
Yes MS have always had a blind spot with dates - a 'leaving date' in an
employee record needs to be blank until they leave, but even with VB6 dates
there was no equivalent of 'blank date' (which would map to NULL in SQL). I
wish they would see the light!
--
John Austin
"Herfried K. Wagner [MVP]" wrote:
"John Austin" <Jo*********@nospam.nospam> schrieb:
In the vb6 app a number of subs had optional date parameters:
Sub Fred ( ... ,optional FromDate as Date = 0...)

I need something like zero in there to see if the parameter has been used
or
not.

In vb.net the imported code fails with:
Value of type 'Integer' cannot be converted to 'Date'

I have to supply a default value for the date - is there anything I can
use
that obviously indicates that the parameter has not been supplied by the
caller?


I have recently written an article in German about supporting nullable date
and time values. Maybe you'll find some of the code snippets useful:

<URL:http://dotnet.mvps.org/dotnet/articles/nullabledates/>

In VB.NET 'Nothing' referes to a value type's default value. Thus you can
specify 'Nothing' as default value for the parameter. Note that this
doesn't work with VB 2002/2003, but will be supported in VB 2005. In
general I don't recommend to rely on a certain value to be interpreted as a
null value.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #10

P: n/a
"John Austin" <Jo*********@nospam.nospam> schrieb:
Yes MS have always had a blind spot with dates - a 'leaving date' in an
employee record needs to be blank until they leave, but even with VB6
dates
there was no equivalent of 'blank date' (which would map to NULL in SQL).
I
wish they would see the light!


..NET's 'SqlDateTime' supports null values even in current versions of
..NET... Maybe it's suitable in your scenario.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.