I found this link which indicates that Date is indeed a value type:
http://msdn.microsoft.com/library/de...uereftypes.asp
So, as Cor pointed out earlier, if you have a reference type you can set it
to nothing without any problems in an optional parameter. Since Date is a
value type, I guess this is why I'm having an issue. However, if that's the
case, then why is this allowed?
Private Sub Test(Optional ByVal x As Integer = Nothing)
Integer is also a value type, so I could think it should be throwing an
error as well (assuming behavior should be consistent across all value
types).
"Scott Hembrough" <(E-Mail Removed)> wrote in message
news:%236%23HF%(E-Mail Removed)...
> OK. I'd overlooked one thing that Cor wrote when he responded to me. The
> link that he provided said that "If the optional argument is a reference
> type such as a String, you can use Nothing as the default value, provided
> this is not an expected value for the argument."
>
> Is date considered to be a value type or a reference type? I didn't see
it
> in the list of value types I was looking at in the help file. So, if it's
> reference, then it seems like the MS article is saying that I *should* be
> able to set this to nothing.
>
> Also, integer *is* a value type and I can set an optional integer
parameter
> to nothing with no problems. So it seems like I should be able to do this
> with a date.
>
> Lots of questions, but I'm just trying to understand how all this works as
> we delve into .NET. Again, thanks for all the help.
>
> "Scott Hembrough" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Yes, that is correct. It's just sample code. I was posting a very
simple
> > example that didn't have any extra code that would detract from the
actual
> > question.
> >
> > As for ways to deal with this, I realize function overloading would be a
> > better solution (as suggested in another post). I just happened to run
> > across it as I was converting some old VB6 code. We have a very large
> > project, and right now we're trying to get it to run in .NET with
minimal
> > changes. Rearchitecting the code will come later.
> >
> > Our original function had an optional date parameter declared as a
> variant.
> > Within the function, we used IsMissing to determine if anything had been
> > passed in. Since IsMissing is no longer an option, I was defaulting the
> > parameter to nothing and checking for IsNothing within the function.
This
> > would get us by until we can go back and take advantage of features such
> as
> > function overloading (which would make this a moot point anyway).
> >
> > So, back to the original question: Does anyone know why this is
> happening?
> > Is this a bug? Or is there a more obvious explanation that I'm just
> > overlooking?
> >
> > "Chris Podmore" <(E-Mail Removed)> wrote in
message
> > news:3257E15C-6CE8-48D0-9303-(E-Mail Removed)...
> > > Cor,
> > >
> > > I assumed that Scott had posted some sample code rather than his
actual
> > code
> > > which he was having problems with.
> > >
> > > Chris.
> >
> >
>
>