|
-
Oct 26th, 2004, 09:34 AM
#1
Thread Starter
Hyperactive Member
Passing a color value into a procedure
Pardon my stupidity.
How can I specify a color as an optional arg in a sub with a default, and then pass in a value?
e.g. I tried this and it failed miserably
Optional ByVal RayColor As Color = System.Drawing.Color.White
Color complains
"Optional parameters cannot have structure types"
System.Drawing.Color.White complains
"Constant expression is required"
Thanks, (a very confused) DaveBo
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
-
Oct 26th, 2004, 09:42 AM
#2
You are going to have to use the actual values for the colors and turn the optional args into string or seperate rgb values, depending on how you do it. Like it says, optional paramaters cannot use structures. Color is a struct.
-
Oct 26th, 2004, 09:53 AM
#3
Thread Starter
Hyperactive Member
Thanks,
I thought System.Drawing.Color.White equated to a color constant value - for white, e.g. like in VB6
? vbWhite
returns 16777215
In the .Net Command window I tried
? System.Drawing.Color.White
and it returned
Code:
{System.Drawing.Color}
A: 255
AliceBlue: {System.Drawing.Color}
:
MintCream: {System.Drawing.Color}
< More... (The first 100 of 151 items were displayed.) >.
I never knew "white" could be so complicated.
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
-
Oct 26th, 2004, 03:47 PM
#4
Hi.
Instead of "Optional" you could use overloaded subs.
VB Code:
Private Sub A()
A(Color.White)
End Sub
Private Sub A(ByVal C As Color)
'Do your stuff
End Sub
If you call A with a color the second sub will be called.
If you call A without a color the first sub will be called, which in turn just calls the second one with your default color.
Does this help?
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Oct 27th, 2004, 12:56 PM
#5
Thread Starter
Hyperactive Member
That's the most unheard of thing I ever heard of
But it does work!
Thanks Pax
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
-
Oct 27th, 2004, 01:00 PM
#6
Your welcome.
Actually, that's the way MS does it.
All functions that has several combinations of parameters are made like that.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
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
|