How to declare an optional color parameter in a vb.net procedure

Marc Menzel 121 Reputation points
2022-04-06T23:29:31.31+00:00

How do you declare an optional color parameter in a vb.net 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
Developer technologies | VB
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2022-04-07T01:47:05.56+00:00

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.