469,643 Members | 2,061 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

How make Guid parameter optional in function?

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
May 24 '07 #1
3 6953
"Ronald S. Cook" <rc***@westinis.comwrote in
news:e6**************@TK2MSFTNGP04.phx.gbl:
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.
May 24 '07 #2
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:
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
May 25 '07 #3
=?Utf-8?B?RGF2aWQgQW50b24=?= <Da********@discussions.microsoft.com>
wrote in news:B7**********************************@microsof t.com:
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.
May 25 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by PawelF | last post: by
10 posts views Thread by John Morgan | last post: by
1 post views Thread by Scott M. Lyon | last post: by
1 post views Thread by Scott M. Lyon | last post: by
3 posts views Thread by Wayne Wengert | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.