How make Guid parameter optional in function?

  • Thread starter Thread starter Ronald S. Cook
  • Start date Start date
R

Ronald S. Cook

I have a function in which I'm trying to make the parameter optional.
However, when I put Optional in front of ByVal below I get the error
"optional parameters cannot have structure types".

Public Function SelectPenType(ByVal PenTypeID As Guid) As DataSet Implements
IPen.SelectPenType

Any idea how I should be doing this?

Thanks,
Ron
 
I have a function in which I'm trying to make the parameter optional.
However, when I put Optional in front of ByVal below I get the error
"optional parameters cannot have structure types".

Public Function SelectPenType(ByVal PenTypeID As Guid) As DataSet
Implements IPen.SelectPenType

Any idea how I should be doing this?


I would create an overloaded version of the function. i.e.

Public Function SelectPenType() As DataSet Implements IPen.SelectPenType
SelectPenType(Nothing)
End Fucntion

Also take a look at the Nullable types or you can njust pass in a fixed
value, i.e. GUID.empty to represent no parameter.
 
That's a very confusing error message. There is no problem having optional
parameter types for most structure types, so the message should have
indicated why "Guid" was treated differently than other structure types such
as double, DateTime, decimal, etc.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
 
so the message should have
indicated why "Guid" was treated differently than other structure
types such as double, DateTime, decimal, etc.

I think it's because those are called "Base Types". I don't think GUID is a
base type.
 
Back
Top