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.

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

objExcel.Application.Cells(4, 3).Value = “49”<br />

places the number 49 into the cell in the fourth row <strong>and</strong> third column (that is, C4) of the<br />

spreadsheet. Some other Excel statements are<br />

objExcel.Application.Visible = True ‘Display spreadsheet<br />

objExcel.Application.Cells(4, 3).Font.Bold = True ‘Make cell bold<br />

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

‘cell C7 hold the sum of the numbers in cells C1 through C5<br />

objExcel.Application.Quit ‘Exit Excel<br />

With the Word object, the statement<br />

objWord.Insert = “We’ll always have Paris.”<br />

inserts the sentence into the document at the current insertion point. Some other Word statements<br />

are<br />

objWord.FileNewDefault ‘Create a new document based on<br />

‘the Normal template<br />

objWord.WordLeft ‘Move the insertion point left one word<br />

‘(Counts period as a word.)<br />

objWord.Bold ‘Change font to bold<br />

objWord.FileSaveAs filespec ‘Save document with specified name<br />

objWord.FilePrint ‘Print the current document<br />

objWord.FileClose ‘Close the current document<br />

OLE Automation involves the following four steps:<br />

1. Declare an Object variable with a Dim statement.<br />

2. Create an OLE Automation object with a CreateObject function <strong>and</strong> assign it to<br />

the variable with a Set statement.<br />

3. Transfer comm<strong>and</strong>s <strong>and</strong>/or data to the OLE Automation object to carry out the<br />

desired task.<br />

4. Close the object <strong>and</strong> assign the value Nothing to the Object variable.<br />

EXAMPLE 1<br />

The following program, which requires that Microsoft Excel be present in your computer, creates a<br />

spreadsheet for college expenses <strong>and</strong> uses the spreadsheet to add up the values for the different categories.<br />

The user should place numbers into the text boxes <strong>and</strong> then press the first comm<strong>and</strong> button to tabulate<br />

total college expenses. This process can be repeated as many times as desired.<br />

Object Property Setting<br />

frm14_1_1 Caption College Expenses<br />

lblTuitNFees Caption Tuition <strong>and</strong> Fees<br />

txtTuitNFees Text blank)<br />

lblBooksNSuppl Caption Books <strong>and</strong> Supplies<br />

txtBooksNSuppl Text (blank)<br />

lblBoard Caption Board<br />

txtBoard Text (blank)<br />

lblTransportation Caption Transportation<br />

txtTransportation Text (blank)<br />

lblOther Caption Other Expenses<br />

txtOther Text (blank)<br />

Line1<br />

LblTotal Caption TOTAL:<br />

LblHoldTotal Caption (blank)<br />

CmdCalculate Caption &Calculate Total Expenses<br />

CmdQuit Caption &Quit

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

Saved successfully!

Ooh no, something went wrong!