1

I get a "Constant Expression required" exception when running this Sub Procedure;

Public Sub SolidFill(Optional SolidColor As Color = Color.Black)
    ....
End Sub

However, this happens only when using ColorTypes. What do I need to do to prevent this exception from being thrown?

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
WashirePie
  • 75
  • 9

1 Answers1

2

You could do something like this:

Public Sub SolidFill(Optional SolidColor As Color = Nothing)
    If SolidColor = Nothing Then SolidColor = Color.Black
End Sub
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
  • Awesome! I'll mark this as an answer. Do you know why this is though? Is there no way to define `SolidFill` with a color in the Parameter brackets? – WashirePie May 21 '15 at 12:41
  • better to give credits to Steve, for this answer http://stackoverflow.com/questions/16045479/using-color-as-optional-parameter-in-a-function-within-a-class –  May 21 '15 at 12:42
  • 1
    @SimonSchödler: The reason you can't use Color.Black as the default value for your optional parameter is that it is not a constant value, Color.Black is a property of the Color Structure that itself returns a Color Structure. – Blackwood May 21 '15 at 13:56