2

I have found this Sub delaration:

Private Sub ReceivedText(ByVal [text] As String) 'input from ReadExisting
        If Me.lblStatus.InvokeRequired Then
            Dim x As New SetTextCallback(AddressOf ReceivedText)
            Me.Invoke(x, New Object() {(text)})
        Else
            Me.lblStatus.Text &= [text] 'append text
        End If
    End Sub

I don't understand the [] in [text]. What does it mean ?

Thank you.

1 Answers1

1

The brackets are used to signify that the text is a variable or identifier and not a type or some other keyword.

For example, I can do something like this if I wanted to:

 Private Sub ReceivedText(ByVal [String] As String) 'input from ReadExisting
    If Me.lblStatus.InvokeRequired Then
        Dim x As New SetTextCallback(AddressOf ReceivedText)
        Me.Invoke(x, New Object() {([String])})
    Else
        Me.lblStatus.Text &= [String] 'append text
    End If
End Sub

Without the brackets Visual Studio (for example) will think that 'String' is a type and give you the error: "Keyword is not valid as in identifier". What to actually name identifiers or variables is a whole other question.

Barry Franklin
  • 1,781
  • 1
  • 27
  • 45