Solved

VB.NET: Optional Date Parameter's Default Value

Posted on 2002-07-10
4
947 Views
Last Modified: 2012-06-21
Another default-value parameter problem that I can't get right.  I just want my second parameter to be an optional date array.  The most recent code I've tried is below, and the syntax error I get is "Conversion from 'Double' to 'Date' requires calling the Date.FromOADate() method".

How the heck do I supply a default value for this optional date array?

I'm working with VB.NET.  Thanks a bunch.

   Public Function ReadDate( _
      ByVal sName As String, _
      Optional ByVal dtDefault As Date = Nothing _
      ) _
      As Date
0
Comment
Question by:bryker
  • 3
4 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
ID: 7144555
This might be a good time to use an overloaded function (as I suggested in your previous question regarding the Byte array) since this has few parameters:

Public Function ReadDate(ByVal sName As String) As Date


Public Function ReadDate(ByVal sName As String, _
     ByVal dtDefault As Date = Nothing) As Date
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 7144561
Sorry, the " = Nothing" can obviously be removed.  You may want to include the "Overloads" keyword for clarity in your code as well.
0
 

Author Comment

by:bryker
ID: 7147327
AzraSound:

Well, for the time being, I've overloaded the function.  Maybe it's my VB6 soul still rattling its chains, but I HATE not knowing how to make a Date variable an Optional parameter.

If you happen to come upon that knowledge, please pass it along to me.

By the way, you refer above to your suggestion to another question of mine...one I never got to read before I awarded points.  I looked back at the time stamp on my posting awarding the points, and then at yours suggesting my using an overloaded Function, there are only 2 MINUTES DIFFERENCE between the two messages.  Had I only refreshed my browser, I would have seen it in time.  Oh, well.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 7147349
No problem regarding the other question.  As for this Date problem, I spent a couple of minutes trying to figure out how to actually give a Date data type a default value when passed as an Optional parameter but could not figure it out either.  Maybe with some more research and fiddling...

If you find out, please let me know as well.  For the time being, hopefully the use of the overloaded capabilities of VB.NET will suffice.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question