364,112 Members | 2160 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Optional date parameter initialization

John Austin
P: n/a
John Austin
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


Mattias Sjögren
P: n/a
Mattias Sjögren
[color=blue]
>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?[/color]

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

Herfried K. Wagner [MVP]
P: n/a
Herfried K. Wagner [MVP]
"John Austin" <John.Austin@nospam.nospam> schrieb:[color=blue]
> 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?[/color]

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

Mattias Sjögren
P: n/a
Mattias Sjögren
[color=blue]
>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?[/color]

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

Terry Olsen
P: n/a
Terry Olsen
>[color=blue]
> 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:[/color]

The online translators don't do a very good job of turning this into english
:(


Nov 21 '05 #5

John Austin
P: n/a
John Austin
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:
[color=blue]
> "John Austin" <John.Austin@nospam.nospam> schrieb:[color=green]
> > 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?[/color]
>
> 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/>
>
>[/color]
Nov 21 '05 #6

Herfried K. Wagner [MVP]
P: n/a
Herfried K. Wagner [MVP]
"John Austin" <John.Austin@nospam.nospam> schrieb:[color=blue]
> 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![/color]

..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

Herfried K. Wagner [MVP]
P: n/a
Herfried K. Wagner [MVP]
"John Austin" <John.Austin@nospam.nospam> schrieb:[color=blue]
> 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?[/color]

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

Terry Olsen
P: n/a
Terry Olsen
>[color=blue]
> 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:[/color]

The online translators don't do a very good job of turning this into english
:(


Nov 21 '05 #9

John Austin
P: n/a
John Austin
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:
[color=blue]
> "John Austin" <John.Austin@nospam.nospam> schrieb:[color=green]
> > 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?[/color]
>
> 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/>
>
>[/color]
Nov 21 '05 #10

Herfried K. Wagner [MVP]
P: n/a
Herfried K. Wagner [MVP]
"John Austin" <John.Austin@nospam.nospam> schrieb:[color=blue]
> 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![/color]

..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

Post your reply

Help answer this question



Didn't find the answer to your Visual Basic .NET question?

You can also browse similar questions: Visual Basic .NET