S
Scott Hembrough
Hello. I have two snippets of code here that are very similar. One works,
but the other doesn't. Can someone explain why?
Snippet 1: Local "date" variable is set to nothing. Compiles fine, sets
date to 1/1/0001 12:00:00 AM.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As Date
x = Nothing
Debug.WriteLine(x)
End Sub
Snippet 2: Optional date parameter contains default value of nothing. .NET
2003 refuses to compile. Gives error of "Conversion from 'System.Object' to
'Date' cannot occur in a constant expression."
Private Sub ThisDoesntWork(Optional ByVal x As Date = Nothing)
Debug.WriteLine(x)
End Sub
Why am I getting this error? It doesn't make sense to me. If x is a
different type (such as Integer), .NET doesn't complain at all. So why is
Date treated differently?
Thanks in advance for any feedback!
Scott
but the other doesn't. Can someone explain why?
Snippet 1: Local "date" variable is set to nothing. Compiles fine, sets
date to 1/1/0001 12:00:00 AM.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As Date
x = Nothing
Debug.WriteLine(x)
End Sub
Snippet 2: Optional date parameter contains default value of nothing. .NET
2003 refuses to compile. Gives error of "Conversion from 'System.Object' to
'Date' cannot occur in a constant expression."
Private Sub ThisDoesntWork(Optional ByVal x As Date = Nothing)
Debug.WriteLine(x)
End Sub
Why am I getting this error? It doesn't make sense to me. If x is a
different type (such as Integer), .NET doesn't complain at all. So why is
Date treated differently?
Thanks in advance for any feedback!
Scott