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 objExcel As Object ‘In (Declarations) section of (General)<br />

Private Sub cmdCalculate_Click()<br />

Set objExcel = CreateObject(“Excel.Sheet”)<br />

‘Make Excel visible objExcel.Application.Visible = True<br />

‘Fill in Rows Values<br />

objExcel.Application.Cells(1, 3).Value = txtTuitNFees.Text<br />

objExcel.Application.Cells(2, 3).Value = txtBooksNSuppl.Text<br />

objExcel.Application.Cells(3, 3).Value = txtBoard.Text<br />

objExcel.Application.Cells(4, 3).Value = txtTransportation.Text<br />

objExcel.Application.Cells(5, 3).Value = txtOther.Text<br />

‘Set up a cell to total the expenses<br />

objExcel.Application.Cells(6, 3).Formula = “=SUM(C1:C5)”<br />

objExcel.Application.Cells(6, 3).Font.Bold = True<br />

‘Set total as the contents of this cell<br />

lblHoldTotal = objExcel.Application.Cells(6, 3).Value<br />

‘Make Excel invisible<br />

objExcel.Application.Visible = False<br />

End Sub<br />

Private Sub cmdQuit_Click()<br />

‘Close Excel<br />

objExcel.Application.Quit<br />

‘Release the object variable<br />

Set objExcel = Nothing<br />

End<br />

End Sub<br />

[Run, place numbers into the text boxes, <strong>and</strong> click on the Calculate Total Expenses button. Note: If the<br />

form is not visible, click on the College icon in the Window’s task bar at the bottom of the screen.]<br />

EXAMPLE 2<br />

The following program creates a Word document, prints the contents of the document, <strong>and</strong> saves the document<br />

to a file.<br />

Object Property Setting<br />

frm14_1_2 Caption EXAMPLE 2<br />

cmdCreate Caption &Create Word<br />

Document<br />

OLE 387

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

Saved successfully!

Ooh no, something went wrong!