Solved

VB.NET: Optional Date Parameter's Default Value

Posted on 2002-07-10
4
952 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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