Statements

In Visual Basic 2005, a complete program instruction is called a statement. Programs consist of sequences of Visual Basic 2005 statements . Each statement ends with a new line or a colon.

Dim myString As String = "Hello World"
Dim myVariable As Integer = 5 : Dim myVar2 As Integer = 7

Tip

The colon allows you to squeeze more than one statement on a single line, but is generally considered poor programming practice because it makes for code that is harder to read and thus harder to maintain.

If your code will not fit on a single line, you may use the line continuation character, the underscore: (_) to continue a single statement on more than one line, as shown here:

System.Console.WriteLine( _
    "Freezing point of water: {0}", _
    CInt(Temperatures.FreezingPoint))

All three lines are considered a single statement, because of the use of the line continuation character.

Tip

Be sure to add a space between any other code and the line continuation character.

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.