Board index » Visual Studio » How make Guid parameter optional in function?

How make Guid parameter optional in function?

Visual Studio336
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


-
 

Re:How make Guid parameter optional in function?

"Ronald S. Cook" <rcook@westinis.com>wrote in



Quote
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.

-

Re:How make Guid parameter optional in function?

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





"Ronald S. Cook" wrote:



Quote
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







-

Re:How make Guid parameter optional in function?

=?Utf-8?B?RGF2aWQgQW50b24=?= <DavidAnton@discussions.microsoft.com>

wrote in news:B7CF5AE5-EC3A-4336-8652-BC9528158FE1@microsoft.com:



Quote
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.

-