PreviousNextIndex

CREATE automation object statement


(Windows only)

Creates (instantiates) an ActiveX Automation object based on a specified Automation Server connection.

Syntax

CREATE expression1 COM-hdl-var  
  [ CONNECT [ TO expression2 ] ] 
  [ NO-ERROR ] 

expression1
COM-hdl-var
[CONNECT [ TO expression2 ] ]
NO-ERROR
Example

The following procedure demonstrates several Automation object instantiations using the four basic connection options. It tries all of the options with the Microsoft® Excel Automation Server. Note that not all Automation Servers support all options. For example in Office 95, there is no Automation object for PowerPoint presentations. Thus, the file connection option (Option 3 in Table 19) does not work.

r-crea.p
/* Demonstration of connecting to an Automation Object in Excel using the 
   different connection options. */ 
DEFINE VARIABLE curDir   AS CHARACTER  NO-UNDO. 
DEFINE VARIABLE cEditor  AS CHARACTER  NO-UNDO 
  VIEW-AS EDITOR SIZE 63 BY 1 LABEL "Result:" FONT 2. 
DEFINE VARIABLE wordAppl AS COM-HANDLE NO-UNDO. 
DEFINE BUTTON bExit  
  LABEL "Exit" SIZE 16 BY 1.25 AUTO-GO. 
DEFINE BUTTON bStart  
  LABEL "Option 1 - Start Excel" SIZE 32 BY 1.25 . 
DEFINE BUTTON bConnect  
  LABEL "Option 2 - Connect to Active" SIZE 32 BY 1.25. 
DEFINE BUTTON bConPerFile  
  LABEL "Option 3 - Connect per File" SIZE 32 BY 1.25. 
DEFINE BUTTON bConnectMon  
  LABEL "Option 4 - Connect by Extension" SIZE 32 BY 1.25. 
ASSIGN 
  FILE-INFO:FILE-NAME = "." 
  curDir              = FILE-INFO:FULL-PATHNAME. 
FORM cEditor SKIP(0.5) bStart SPACE bConnect SPACE bConPerFile SPACE 
  bConnectMon SKIP(0.5) bExit  
  WITH FRAME a VIEW-AS DIALOG-BOX THREE-D FONT 6. 
FRAME a:TITLE = "Testing CREATE Automation Object Statement". 
ENABLE ALL WITH FRAME a. 
ON CHOOSE OF bStart IN FRAME a DO: 
  /* Option 1: CREATE expression1 Com-Handle-Var. */ 
  DEFINE VARIABLE excelAppl AS COM-HANDLE NO-UNDO. 
  CREATE "Excel.Application" excelAppl.  
  excelAppl:Visible = TRUE. 
  excelAppl:Workbooks:Add. 
  excelAppl:Range("A1"):Value = "testing CREATE". 
  ASSIGN cEditor:SCREEN-VALUE = STRING(excelAppl:Range("A1"):Value). 
  RELEASE OBJECT excelAppl. 
END. 
ON CHOOSE OF bConnect IN FRAME a DO: 
/* Option 2: CREATE expression1 Com-Handle-Var CONNECT. */ 
  DEFINE VARIABLE excelAppl AS COM-HANDLE NO-UNDO. 
  CREATE "Excel.Application" excelAppl CONNECT. 
  excelAppl:Range("A2"):Value = "testing CONNECT". 
  MESSAGE "Click me to continue!" VIEW-AS ALERT-BOX. 
  ASSIGN cEditor:SCREEN-VALUE = STRING(excelAppl:Range("A2"):Value). 
  excelAppl:Workbooks:Item(1):SaveAs(curDir + "\yyy.xls"). 
  excelAppl:Quit(). 
  RELEASE OBJECT excelAppl. 
END. 
ON CHOOSE OF bConPerFile IN FRAME a DO: 
/* Option 3: CREATE expression1 Com-Handle-Var CONNECT TO expression2. */ 
  DEFINE VARIABLE excelAppl AS COM-HANDLE NO-UNDO. 
  DEFINE VARIABLE cFileName AS CHARACTER  NO-UNDO  
    INITIAL "\WorkSheets\Xplan.xls". 
  CREATE "Excel.Sheet" excelAppl CONNECT TO cFileName.  
  excelAppl:Visible = TRUE. 
  excelAppl:Workbooks:Add. 
  excelAppl:Range("A3"):Value = "testing CONNECT TO". 
  ASSIGN cEditor:SCREEN-VALUE = STRING(excelAppl:Range("A3"):Value). 
  RELEASE OBJECT excelAppl. 
END. 
ON CHOOSE OF bConnectMon IN FRAME a DO: 
/* Option 4: CREATE "" Com-Handle-Var CONNECT TO expression2. */ 
  DEFINE VARIABLE excelAppl AS COM-HANDLE NO-UNDO. 
  DEFINE VARIABLE cFileName AS CHARACTER  NO-UNDO  
    INITIAL "\WorkSheets\Xplan.xls". 
  CREATE "" excelAppl CONNECT TO cFileName. 
  excelAppl:Range("A4"):Value = "testing CONNECT TO where expression1 = ’’". 
  MESSAGE "Click me to continue!" VIEW-AS ALERT-BOX. 
  ASSIGN cEditor:SCREEN-VALUE = STRING(excelAppl:Range("A4"):Value). 
  excelAppl:Workbooks:Item(1):SaveAs(curDir + "\zzz.xls"). 
  excelAppl:Quit(). 
  RELEASE OBJECT excelAppl. 
END. 

Notes
See also

RELEASE OBJECT statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex