Section 5.5. Statements

   

5.5 Statements

In VB.NET, a complete program instruction is called a statement . Programs consist of sequences of VB.NET statements. Each statement should end with a newline:

 Dim myString As String = "Hello World" 

You can combine multiple statements on a single line if you divide them with a colon. The following sample shows two code lines on a single line, with a colon marking the end of the first:

 Dim myVariable As Integer = 5 : Dim myVar2 As Integer = 7 

Using the colon may allow you to squeeze more than one statement on a line. However, this is generally considered to be poor programming practice because it makes the code harder to read and thus harder to maintain.

Sometimes a single code statement simply won't fit on a single line in a file. If your code will not fit on a single line, you can use the line-continuation character, the underscore (_), as in this excerpt from Example 5-4:

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

Note that you must use a space before the underscore in order to continue the line. In the preceding snippet, all three lines are considered to be a single statement because you use two continuation characters , one at the end of each of the first two lines.

VB.NET statements are evaluated in order. The compiler starts at the beginning of a statement list and makes its way to the bottom. This would be entirely straightforward, and terribly limiting, were it not for branching. Branching allows you to change the order in which statements are evaluated. Chapter 7 describes branching in detail.

   


Learning Visual Basic. NET
Learning Visual Basic .Net
ISBN: 0596003862
EAN: 2147483647
Year: 2002
Pages: 153
Authors: Jesse Liberty

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net