Error message when you use square brackets as a delimited identified in Visual Basic 2005 or in Visual Basic .NET: "Identifier expected" (316137)



The information in this article applies to:

  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)

This article was previously published under Q316137

SYMPTOMS

If you use square brackets ([]) as a delimited identifier in Microsoft Visual Basic 2005 or in Microsoft Visual Basic .NET, the wavy blue underline appears under the code in the IDE. If you move the pointer over the code, you receive the following text:

Identifier expected.

RESOLUTION

To resolve this behavior, use parentheses and double quotation marks instead of square brackets.

STATUS

This behavior is by design.

Square brackets are now used to allow keywords to be used as identifiers.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open Visual Studio 2005 or Visual Studio .NET.
  2. On the File menu, select a new Windows Application project.
  3. Double-click the default form, Form1.vb, to open the code window, and then copy the following code in the Form Load event:
    Dim dt As New System.Data.DataTable()
    Dim dr As System.Data.DataRow
    dt.Columns.Add("Field1", GetType(String))
    dt.Columns.Add("Mr.Smith", GetType(String))
    dt.Columns.Add("A space", GetType(String))
    
    dr = dt.NewRow()
    dr!field1 = "test1"
    dr![Mr.Smith] = "test2"
    dr![A space] = "test3"
    					

    The wavy blue underline appears under the last two lines of the code in Visual Basic .NET IDE.

  4. Change the last two lines to the following syntax:
    dr("Mr.Smith") = "test2"
    dr("A space") = "test3"
    					
    The wavy blue underline disappears.

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbprb KB316137 kbAudDeveloper