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.

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

Private Sub ShowTotals()<br />

Dim colNum As Integer, rowNum As Integer, total As Single<br />

‘Compute <strong>and</strong> display total of each numeric column<br />

msgSprdSht.Row = numRows - 1<br />

msgSprdSht.Col = 0<br />

msgSprdSht.Text = “Total”<br />

For colNum = 1 To numCols - 1<br />

total = 0<br />

For rowNum = 1 To numRows - 3<br />

msgSprdSht.Row = rowNum<br />

msgSprdSht.Col = colNum<br />

total = total + Val(msgSprdSht.Text)<br />

Next rowNum<br />

msgSprdSht.Row = numRows - 2<br />

msgSprdSht.Text = “————————”<br />

msgSprdSht.Row = numRows - 1<br />

msgSprdSht.Text = FormatCurrency(total)<br />

Next colNum<br />

End Sub<br />

Private Sub ShowValues()<br />

Dim rowNum As Integer, colNum As Integer<br />

‘Refresh values displayed in cells<br />

For rowNum = 1 To numRows - 1<br />

For colNum = 1 To numCols - 1<br />

msgSprdSht.Row = rowNum<br />

msgSprdSht.Col = colNum<br />

msgSprdSht.Text = FormatNumber(Val(msgSprdSht.Text)vbFalse)<br />

Next colNum<br />

Next rowNum<br />

End Sub<br />

[A possible run of the program is shown.]<br />

So far we have used the Text property of grids to place strings into cells. Grids also have<br />

a Picture property. A picture (such as a .BMP file created with Paint or an .ICO file from<br />

<strong>Visual</strong> <strong>Basic</strong>’s icon directory) is placed into the current cell with a statement of the form<br />

Set msgFlex.CellPicture = LoadPicture(“filespec”)<br />

If both text <strong>and</strong> a picture are assigned to a cell, then the picture appears in the upper left portion<br />

of the cell, <strong>and</strong> the text appears to the right of the picture.<br />

■ THE MENU CONTROL<br />

<strong>Visual</strong> <strong>Basic</strong> forms can have menu bars similar to those in most Windows applications.<br />

Figure 10-11 shows a typical menu, with the submenu for the Font menu item dropped down.

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

Saved successfully!

Ooh no, something went wrong!