473,396 Members | 1,805 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,396 software developers and data experts.

Optional date parameter initialization

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
10 6826
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
"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
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
>
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
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
"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
"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
>
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: lakshmi | last post by:
include the following lines of code: using System.Runtime.InteropServices; prefix the optional argument with This takes care if an optional parameter is not supplied by a VB script client....
21
by: Marc DVer | last post by:
I am trying to create a query that can be loaded as a querydef object but not having to assign values to the parameters if I don't want to. Normally when using a parameter query in VBA my code...
1
by: Learning SQL Server | last post by:
What should the default value for an optional Date parameter be in a function if I want it to default to Nothing? Setting the optional value to "" fails, so does setting it to Nothing. ...
10
by: John Morgan | last post by:
Does anyone know what parameter should be used instead of Date = 0 for the optional parameter in the following function? Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As Date...
0
by: John Austin | last post by:
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...
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
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...
12
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.