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

Marc Menzel 61 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
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,668 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 29,261 Reputation points Microsoft Vendor
    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