Single Statement in Multiple Lines in VB.NET

Sometimes some statements are too long to fit on the screen in Visual Studio editor in a single line and it becomes a necessity to break-down syntax in multiple lines.
  • 10289

Combining a Single Statement in Multiple Lines

Sometimes some statements are too long to fit on the screen in Visual Studio editor in a single line and it becomes a necessity to break-down syntax in multiple lines.

In VB.NET, combination of an underscore and an ampersand is used to continue a single statement in multiple lines. The underscore is used at the end of the statement and next line starts with (&) sign. Code snippet in Listing 3 demonstrates how to build a long string in multiple lines.

        Function SingleStatementInMultipleLines(ByVal TableName As String)

 

        Dim sql As String

        sql = "SELECT * FROM Titles, Publishers" _

            "WHERE Publishers.PubId = Titles.PubID" _

            "AND Publishers.State = 'NY' " _

            " AND Publisher.State = 'PA' "

 

        Return sql

    End Function 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.