Solved

VB.NET: Optional Date Parameter's Default Value

Posted on 2002-07-10
4
925 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
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:…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now