Visual Basic .NET is a line-oriented language, in which line breaks generally indicate the ends of statements. However, there are times when a programmer may wish to extend a statement over several lines or have more than one statement on a single line.

To extend a statement over several lines, use the line-continuation character, an underscore (_). It must be the last character on its line, and it must be immediately preceded by a space character. Lines connected in this way become a single logical line. Here is an example:

Dim strSql As String = "SELECT Customers.CompanyName," _
   & " COUNT(Orders.OrderID) AS OrderCount" _
   & " FROM Customers INNER JOIN Orders" _
   & " ON Customers.CustomerID = Orders.CustomerID" _
   & " GROUP BY Customers.CompanyName" _
   & " ORDER BY OrderCount DESC"

A line break can occur only where whitespace is allowed.

To place two or more statements on a single line, use the colon (:) between the statements, like this:

i = 5 : j = 10

The remainder of this section discusses the statements in Visual Basic .NET.

Option Statements

There are three Option statements, which affect the behavior of the compiler. If used, they must appear before any declarations in the same source file. They control the compilation of the source code in the file in which they appear. They are:

Option Compare

The Option Compare statement controls the manner in which strings are compared to each other. The syntax is:

Option Compare [ Binary | Text ]

If Binary is specified, strings ...

Get Programming Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.