I’d like to create a method like this, where only two color parameters are necessary, and the third one voluntary:
Sub myMehod (col1 as color, col2 as color, col3 as color = Nil)
if col3 = Nil Then
...
end if
...
End Sub
But a color variable can not be Nil, so I’ve found two possibilities:
1: Use a Variant instead of color
Sub myMehod (col1 as color, col2 as color, col3 as Variant = Nil)
It works, but col3 is not a color, and I don’t know if I will have problems later on, when using this variable.
2: Use a very improbable color like &c01020304
Sub myMehod (col1 as color, col2 as color, col3 as color = &c01020304)
if col3 = &c01020304Then
...
end if
...
End Sub
Both solutions work.
Is there something better?
Which on would you use?
Sub MyMethod(ParamArray cols As Color)
If UBound(cols) < 1 Or UBound(cols) > 2 Then
// not the proper count of colors
Return // or raise an error (though runtime only!)
End
...
End Sub
Eli: In fact my method is more complicate (different type of parameters). I made the example very easy just for the forum.
Peter: That is the problem. Black color (&c00000000) is used very often as a parameter, so I don’t want it as default.