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.

202 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

FIGURE 6-10 Template for Spreadsheet<br />

Because processing the totals for the spreadsheet involves adding columns <strong>and</strong> rows of<br />

cells, coding is simplified by using a control array of text boxes so that an index in a<br />

For...Next loop can step through a set of cells. A two-dimensional array of text boxes seems<br />

natural for the spreadsheet. Unfortunately, only a single index is available for control arrays<br />

in <strong>Visual</strong> <strong>Basic</strong>. However, a single dimensional array of text boxes can be used without much<br />

difficulty if we define a function Indx that connects a pair of row (1 to 16) <strong>and</strong> column (1 to<br />

6) values to a unique index (1 to 96) value. An example of such a rule would be Indx(row,column)=(row–1)*6+column.<br />

Successive values of this function are generated by going from<br />

left to right across row 1, then left to right across row 2, <strong>and</strong> so on.<br />

A solution to the spreadsheet problem that uses one control array of text boxes <strong>and</strong> two<br />

control arrays of labels follows. The text box control array txtCell( ) provides the 96 text boxes<br />

needed for the spreadsheet cells. Because the proposed Indx function advances by one as we<br />

move from left to right across a row of cells, the cells must be positioned in this order as they<br />

are loaded. The label control array lblRowLab( ) provides a label for each of the rows of cells,<br />

while label control array lblColLab( ) provides a label for each column of cells. Figure 6-11<br />

shows the layout of the form at design time. The properties for the controls are given in Table<br />

6.7. The Height <strong>and</strong> Width properties given for the text box will assure enough room on the<br />

screen for all 96 cells. These dimensions can be obtained by creating a normal size text box,<br />

then reducing its width by one set of grid marks <strong>and</strong> its height by two sets of grid marks.<br />

FIGURE 6-11 Controls at Design Time<br />

TABLE 6.7<br />

Objects <strong>and</strong> Their Properties<br />

Object Property Setting<br />

frmSpreadsheet Caption Spreadsheet<br />

cmdNew Caption New<br />

cmdQuit Caption Quit<br />

lblRowLab() Caption 1

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

Saved successfully!

Ooh no, something went wrong!