Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.NET: Optional Date Parameter's Default Value

Posted on 2002-07-10
4
Medium Priority
?
991 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 400 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

609 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