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.

Dim maxCol As Integer ‘Number of columns in spreadsheet<br />

Dim maxRow As Integer ‘Number of rows in spreadsheet<br />

Dim incStartRow As Integer ‘Row where income categories begin<br />

Dim incStopRow As Integer ‘Row where income categories end<br />

Dim incTotRow As Integer ‘Row where income total is displayed<br />

Dim expStartRow As Integer ‘Row where expense categories begin<br />

Dim expStopRow As Integer ‘Row where expense categories end<br />

Dim expTotRow As Integer ‘Row where expense total is displayed<br />

Dim balRow As Integer ‘Row where balance is displayed<br />

Dim startCol As Integer ‘Column where numeric data begins<br />

Dim stopCol As Integer ‘Column where numeric data ends<br />

Dim totCol As Integer<br />

played<br />

‘Column where total for each row is dis-<br />

’Control Arrays’txtCell() Control array for data cells<br />

’lblRowLab() Control array for numeric row labels<br />

’lblColLab() Control array for alphabetic column labels<br />

Private Sub cmdNew_Click()<br />

Dim row As Integer, col As Integer<br />

‘Clear all data <strong>and</strong> total text boxes<br />

For col = 1 To maxCol<br />

For row = 1 To maxRow<br />

txtCell(Indx(row, col)).Text = “”<br />

Next row<br />

Next col<br />

Call SetStructure<br />

‘Place cursor in first data txtCell<br />

txtCell(Indx(1, 1)).SetFocus<br />

End Sub<br />

Private Sub cmdQuit_Click()<br />

End<br />

End Sub<br />

A Case Study: Calculating with a Spreadsheet 205<br />

Private Sub CreateSpreadsheet()<br />

Dim row As Integer, col As Integer, i As Integer<br />

Dim cellHeight As Single, cellWidth As Single<br />

Dim cellTop As Single, cellLeft As Single<br />

cellHeight = txtCell(1).Height<br />

cellWidth = txtCell(1).Width<br />

‘Create cells For row = 1 To maxRow<br />

For col = 1 To maxCol<br />

i = Indx(row, col)<br />

If Not (col = 1 And row = 1) Then<br />

Load txtCell(i)<br />

End If<br />

If row > 1 Then<br />

cellTop = txtCell(Indx(row - 1, col)).Top<br />

txtCell(i).Top = cellTop + cellHeight<br />

End If<br />

If col > 1 Then<br />

cellLeft = txtCell(Indx(row, col - 1)).Left<br />

txtCell(i).Left = cellLeft + cellWidth<br />

End If<br />

txtCell(i).Visible = True<br />

Next col

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

Saved successfully!

Ooh no, something went wrong!