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.

Private Sub cmdQuit_Click()<br />

End<br />

End Sub<br />

Private Sub Form_Load()<br />

‘Set default number of rows <strong>and</strong> columns<br />

numRows = 8 ‘row 0 is for headings, last 2 rows are for totals<br />

numCols = 2 ‘column 0 is for category names<br />

Call SetUpGrid<br />

Call ShowValues<br />

Call ShowTotals<br />

End Sub<br />

Private Sub msgSprdSht_Click()<br />

Dim temp As String, message As String<br />

’Obtain new value for cell if it is not in the “total” row<br />

If messageSprdSht.Row < numRows - 2 Then<br />

message = “Enter new value for the row ”<br />

message = message & Str(msgSprdSht.Row + 1) & “ column ”<br />

message = message & Str(msgSprdSht.Col + 1) & “ cell:”<br />

temp = InputBox(message,,msgSprdSht.Text) ‘Propose old value as default<br />

If msgSprdSht.Col = 0 Then<br />

msgSprdSht.Text = temp<br />

ElseIf msgSprdsht.Row = 0 Then<br />

msgSprdSht.Text = temp<br />

Else<br />

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

Call ShowTotals<br />

End If<br />

End If<br />

End Sub<br />

Private Sub SetUpGrid()<br />

Dim colNum As Integer<br />

‘Set up grid msgSprdSht.Col = 0<br />

msgSprdSht.Row = msgSprdSht.Rows - 1<br />

msgSprdSht.Text = “” ‘erase “Total” in case increasing rows<br />

msgSprdSht.Rows = numRows<br />

msgSprdSht.Cols = numCols<br />

‘Set column widths; right-justify columns with numeric data<br />

msgSprdSht.ColWidth(0) = 2000 ‘space for category names<br />

msgSprdSht.ColAlignment(0) = 1 ‘show data left-justified<br />

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

msgSprdSht.ColWidth(colNum) = 1200 ‘space for dollar amounts<br />

msgSprdSht.ColAlignment(colNum) = 7 ‘show data right-justified<br />

Next colNum ‘Set overall grid size to minimum needed for the data<br />

msgSprdSht.Width = 2000 + (numCols - 1) * 1200 + 15 * (numCols + 1) + 8<br />

msgSprdSht.Height = numRows*msgSprdSht.RowHeight(0)+15*(numRows + 1)+8<br />

‘Adjust form to accommodate grid <strong>and</strong> other controls<br />

frmSprdSht.Width = msgSprdSht.Left + msgSprdSht.Width + 200<br />

frmSprdSht.Height = msgSprdSht.Top + msgSprdSht.Height + 500<br />

frmSprdSht.Top = 0 frmSprdSht.Left = 0<br />

End Sub<br />

Five Additional Objects 307

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

Saved successfully!

Ooh no, something went wrong!