19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

picTable.Print “Female”; Tab(10); 364; Tab(20); 465; Tab(30); 560<br />

picTable.Print “Total”; Tab(10); 840; Tab(20); 935; Tab(30); 1050<br />

End Sub<br />

[Run <strong>and</strong> then click the comm<strong>and</strong> button. The resulting picture box is shown.]<br />

■ USING A MESSAGE BOX FOR OUTPUT<br />

Sometimes you want to grab the user’s attention with a brief message such as “Correct” or “Nice<br />

try, but no cigar.” You want this message only to appear on the screen until the user has read<br />

it. This mission is easily accomplished with a message box such as the one shown in Figure<br />

2-28. When a statement of the form<br />

MsgBox prompt, , title<br />

is executed, where prompt <strong>and</strong> title are strings, a message box with prompt displayed <strong>and</strong> the<br />

title bar caption title appears, <strong>and</strong> stays on the screen until the user presses Enter or clicks<br />

OK. For instance, the statement MsgBox “Nice try, but no cigar.”, , “Consolation” produces<br />

Figure 2-28. If you use double quotation marks (“”) for title, the title bar will be blank.<br />

FIGURE 2-28 Sample Message Box<br />

■ LINE CONTINUATION CHARACTER<br />

Up to 1023 characters can be typed in a line of code. If you use a line with more characters<br />

than can fit in the window, <strong>Visual</strong> <strong>Basic</strong> scrolls the window toward the right as needed.<br />

However, most programmers prefer having lines that are no longer than the width of the code<br />

window. This can be achieved with the underscore character (_) preceded by a space. Make sure<br />

the underscore doesn’t appear inside quotation marks though. For instance, the line<br />

msg = “640K ought to be enough for anybody. (Bill Gates, 1981)”<br />

can be written as<br />

msg = “640K ought to be enough for ” & _<br />

“anybody. (Bill Gates, 1981)”<br />

■ OUTPUT TO THE PRINTER<br />

You print text on a sheet of paper in the printer in much the same way you display text in a picture<br />

box. <strong>Visual</strong> <strong>Basic</strong> treats the printer as an object named Printer. If expr is a string or numeric<br />

expression, then the statement<br />

Printer.Print expr<br />

Input <strong>and</strong> Output 55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!