|
New PowerScript functions provide the ability to write scripts to automate OLE 2.0 server applications and OLE 2.0 controls.
A dynamic object type, OLEObject, is new in Version 4.0 to support OLE 2.0. For this object type, the compiler will accept attribute names, function names, and parameter lists which are not already defined for the object. These functions may or may not be present during execution. If they are not present during execution, you will get errors.
The following steps outline automation of an OLE 2.0 server application from PowerBuilder. For complete information, see the Building Applications manual.
- Declare a variable of type OLEObject
OLEObject MyOLEObject
- Create an OLEObject
MyOLEObject = Create OLEObject
- Connect to an OLE 2.0 server
MyOLEObject.ConnectToNewObject (string classname)
example: MyOLEObject.ConnectToNewObject("excel.application")
or Connect to an existing file
MyOLEObject.ConnectToObject (string filename)
example: MyOLEObject.ConnectToObject("c:\excel\expense.xls")
- Use server methods - (MS Excel example)
// The following line makes excel visible MyOLEObject.application.visible = true // Before you try to execute the following line, you must do a File/New in excel. MyOLEObject.application.cells(1, 1).value = 14
- Destroy OLEObject (This step is important.)
Destroy MyOLEObject
If you want to use automation for an OLE 2.0 control, you can simply call the servers methods prefacing it with the Object attribute of your OLE 2.0 control. Note, you do not need to do any of the steps listed above.
Use the server methods with your OLE 2.0 control - (MS Excel example)
OLE_1.object.application.cells(1, 1).value = 14
Note: OLE_1 is an OLE 2.0 control
|