Solved

VB.NET: Optional Date Parameter's Default Value

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 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