Section 3.4. Displaying a Single Line of Text with Multiple Statements


3.4. Displaying a Single Line of Text with Multiple Statements

The message Welcome to Visual Basic! can be displayed using multiple statements. Fig. 3.15 uses two method calls to produce the same output as the program in Fig. 3.1.

Figure 3.15. Displaying a line of text with multiple statements.

   1  ' Fig. 3.15: Welcome2.vb   2  ' Displaying a line of text with multiple statements.   3   4  Module SecondWelcome   5   6     Sub Main()   7   8        Console.Write("Welcome to  ")         9        Console.WriteLine("Visual  Basic!")  10  11     End Sub ' Main  12  13  End Module ' SecondWelcome 

Welcome to Visual Basic!



Lines 89 of Fig. 3.15 display only one line of text in the Console window. The first statement calls Console method Write to display a string. Unlike WriteLine, Write does not position the output cursor at the beginning of the next line in the Console window after displaying its string. Instead, the next character displayed in the Console window appears immediately to the right of the last character displayed with Write. Thus, when line 9 executes, the first character displayed ("V") appears immediately after the last character displayed with Write (i.e., the space character after the word "to" in line 8). Each Write or WriteLine outputs its characters at the exact location where the previous Write's or WriteLine's output ended.



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

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