How to declare an optional color parameter in a procedure

Marc Menzel 61 Reputation points

How do you declare an optional color parameter in a procedure?

I tried the following, however; I got an error message saying that the color needs to be a constant. It seems like the color data type is a structure.
Private Sub DisplayStatisticResult(ByVal ResultLine As String, ByVal LabelText As String, ByVal ResultText As String, Optional ByVal HText1 As String = "**", Optional ByVal HColor1 As Color = Color.Black)

    End Sub
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,623 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 27,501 Reputation points Microsoft Vendor

    Hi @
    You can try the following code.

        Private Sub Test(a As Integer, Optional c As Color = Nothing)  
            If c = Nothing Then  
                c = Color.Black ' your default color'  
            End If  
        End Sub  

    Best Regards.
    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful