|
-
Aug 2nd, 2006, 04:34 PM
#1
Thread Starter
Hyperactive Member
[2005] optional parameters cannot have structure types
That's the error I get for this sig:
VB Code:
Public Sub DrawSphere(ByVal e As System.Windows.Forms.PaintEventArgs, _
ByVal X As Integer, _
ByVal Y As Integer, _
ByVal Width As Integer, _
ByVal Height As Integer, _
Optional ByVal Outline As Color = Color.DimGray, _
Optional ByVal ColorA As Color = Color.Black, _
Optional ByVal ColorB As Color = Color.Gray)
It's pointing to Color (in As Color = whatever). The weird thing is that I have not created a structure called Color. Any help?
-
Aug 2nd, 2006, 04:53 PM
#2
Addicted Member
Re: [2005] optional parameters cannot have structure types
Color is defined in the System.Drawing namespace:
System.Drawing.Color
-
Aug 2nd, 2006, 04:59 PM
#3
Hyperactive Member
Re: [2005] optional parameters cannot have structure types
I don't know for sure, but it sounds like you cannot defined optional variables as anything (ie Optional ByVal Outline, as opposed to Optional ByVal Outline As Color). I don't know for sure, but try taking out the rest of the definition for the three Optional variables and see if that helps.
-
Aug 2nd, 2006, 05:13 PM
#4
Thread Starter
Hyperactive Member
Re: [2005] optional parameters cannot have structure types
supercharged, thanks but i knew that, that doesn't seem to be the problem.
zani, already tried that a while ago, they have to be defined that way.
something else is the problem... thanks for responses.
-
Aug 2nd, 2006, 05:50 PM
#5
Hyperactive Member
Re: [2005] optional parameters cannot have structure types
I just figured it out. An optional parameter can only be a standard type (integer, boolean, character etc). It cannot be a structure or class. I don't know why
-
Aug 2nd, 2006, 07:59 PM
#6
Re: [2005] optional parameters cannot have structure types
When you declare an optional parameter you have to specify a constant as the default value. You cannot do that with a structure unless it is one of the in-built types. Colours are properties of the Color type, i.e. NOT constants. You can declare an optional parameter that is a class type but for the same reason the only default value you can give it is Nothing. The one exception to this is String because it is also an in-built type, even though it's a class.
-
Aug 3rd, 2006, 08:36 AM
#7
Thread Starter
Hyperactive Member
Re: [2005] optional parameters cannot have structure types
dang. thanks for the info jmcilhinney. guess i'll have to figure it out another way.
-
Aug 3rd, 2006, 05:07 PM
#8
Re: [2005] optional parameters cannot have structure types
I'd suggest not using optional parameters at all and use overloading instead, which you have to do in this case. I guess the advantage of optional parameters is that the caller can provide none, any or all of the arguments with values, whereas with overloading you have to define the specific combinations. In this case I'd declare one overload with no colours and one with all three.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|