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.

13.1 OLE<br />

OLE, which st<strong>and</strong>s for Object Linking <strong>and</strong> Embedding, is the evolving technology that allows<br />

programmers to use <strong>Visual</strong> <strong>Basic</strong> to glue together applications like spreadsheets <strong>and</strong> word<br />

processors. The three types of OLE are known as automation, linking, <strong>and</strong> embedding. With<br />

automation, you control an application from outside. With linking <strong>and</strong> embedding, you bring<br />

an application into your program. In this section, OLE is illustrated with Microsoft Excel <strong>and</strong><br />

Word. However, the programs <strong>and</strong> walkthroughs can be modified for other spreadsheet <strong>and</strong><br />

word processing software packages.<br />

■ OLE AUTOMATION<br />

The objects in the <strong>Visual</strong> <strong>Basic</strong> toolbox have both properties <strong>and</strong> methods, <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

controls them by manipulating their properties <strong>and</strong> methods. In general, anything that can be<br />

controlled by manipulating its properties <strong>and</strong> methods is called an object. In particular, an<br />

Excel spreadsheet or a Word document can be specified as an OLE Automation object.<br />

We have worked extensively with the data types String, Integer, <strong>and</strong> Single. There are<br />

eight other data types, including one called Object. A variable that has been declared as an<br />

Object variable can be assigned to refer to an OLE Automation object. The CreateObject<br />

function is used to create an OLE Automation object <strong>and</strong> the Set statement is used to assign<br />

the object to an object variable. For instance, the pair of statements<br />

Dim objExcel As Object<br />

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

creates an Excel spreadsheet object <strong>and</strong> assigns it to the Object variable objExcel. The pair of<br />

statements<br />

Dim objWord As Object<br />

Set objWord = CreateObject(“Word.<strong>Basic</strong>”)<br />

creates a Word document object <strong>and</strong> assigns it to the Object variable objWord. After the object<br />

is no longer needed, a statement of the form<br />

Set objVar = Nothing<br />

should be executed to discontinue association of objVar with the specific object <strong>and</strong> release<br />

all the resources associated with the previously referenced object.<br />

An object is controlled by manipulating its properties <strong>and</strong> methods. For instance, the<br />

statement<br />

385

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

Saved successfully!

Ooh no, something went wrong!