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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

cedures that are available to all forms. To do so, select Add Module from the Project menu<br />

<strong>and</strong> then double-click on the Module icon. A code window will appear with Module1 in the<br />

title bar. Procedures created in this window with the Public keyword will be available to all<br />

forms. To declare a variable that is available to all forms, declare it in the Module1 window,<br />

but use the word Public instead of Dim. For instance, if the statement<br />

Public person As String<br />

appears in the Module1 code window, the variable person can be accessed anywhere in the program.<br />

The contents of this code window are said to form a (St<strong>and</strong>ard) code module. Project<br />

Explorer shows the names of all forms <strong>and</strong> code modules <strong>and</strong> gives you access to the code<br />

from any form or module. When a code module is selected, you can save it by choosing Save<br />

Module As from the File menu. You add an existing code module to a program by choosing<br />

Add File from the Project menu.<br />

■ THE COMMON DIALOG CONTROL<br />

The common dialog control does not initially appear in your Toolbox. To add the control, select<br />

Components from the Project menu, click the Controls tab, <strong>and</strong> click on the check box to<br />

the left of “Microsoft Common Dialog Control 6.0.” Then press the OK button. By convention,<br />

names of common dialog boxes have the prefix dlg.<br />

The common dialog control can produce each of the useful dialog boxes in Figures 10.13<br />

through 10.17, thereby saving the programmer the trouble of designing custom dialog boxes<br />

for these purposes. The common dialog control has no events, only methods <strong>and</strong> properties.<br />

Actually, like the Timer control, the common dialog box control is invisible. However, when<br />

you execute a statement of the form<br />

CommonDialog1.Show_________<br />

where the blank line is filled with Open, Save, Color, Font, or Printer, the specified dialog<br />

box is produced. Table 10.1 gives the purposes of the various dialog boxes.<br />

TABLE 10.1<br />

The Different Types of Dialog Boxes<br />

Type of Dialog box Purpose of Dialog Box<br />

Open Determine what file to open<br />

Save As Determine where <strong>and</strong> with what name to save a file<br />

Color Select any available color<br />

Font Select a font for the screen or printer<br />

Print Help control the printer<br />

FIGURE 10-13 An Open Common Dialog Box<br />

Five Additional Objects 313

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

Saved successfully!

Ooh no, something went wrong!