Hello,
"Fergus Cooney" <filter-(E-Mail Removed)> schrieb:
> Just to expand on your statement of the problem (which I consider
> to be a bug*).
>
> There is a problem setting an optional DateTime parameter to its
> default value as illustrated with the following:
>
> Sub Foo (ByRef Optional dtParam As DateTime = Nothing) 'Error
> Dim dtLocal As DateTime = Nothing 'This is fine.
> End Sub
>
> The pre-compiler reports an error by underlining the Nothin in the
> parameter list. The error given is:
> Conversion from 'System.Object' to 'Date' cannot occur in a
> constant expression.
>
> The Visual Basic Language Reference says a lot about Nothing: :-)
> The Nothing keyword represents the default value of any data
> type. Assigning Nothing to a variable sets it to the default value for
> its declared type. If that type contains variable members, they are
> all set to their default values.
Have a look at the code below:
\\\
Const d As DateTime = Nothing
///
This code will cause the same error as assigning Nothing as the default
value of an optional parameter. I think the reason is that the compiler
won't do the conversion for you when compiling the application.
> *You wait months for a bug and nothing and all of a sudden - two in
> one day!!
I am not sure if this is a bug.
HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet