Try OpenEdge Now
skip to main content
Programming Interfaces
External Program Interfaces : ActiveX Automation Support : Example Automation applications
 

Example Automation applications

ABL comes installed with a number of sample Automation applications that you can use to test and borrow code for your own application development. These reside in separate subdirectories under %DLC%\src\samples\ActiveX. Each subdirectory contains a set of files for one application. These files include a readme.txt file that describes the requirements for running the application and the capabilities that it demonstrates.
For example, the ExcelGraphs subdirectory provides oleauto.p. This application creates an Excel bar chart that graphs sales data from the sports2000 database.
The following procedure listing shows oleauto.p. The bolded code shows the five component handles and where they are used to instantiate and release Automation objects. Only the Excel Application object is instantiated with the CREATE Automation Object statement. The rest are instantiated from methods of the Application object and its subordinate objects.
As the comments indicate, this procedure starts Excel, generates the graph from the sports2000 database, and exits leaving Excel and the graph open on your Windows desktop. Thus, this application really functions as a startup file for Excel and releases all of its instantiated Automation objects just prior to terminating. The objects that Excel requires remain instantiated, as shown:
oleauto.p
/* This sample extracts data from an OpenEdge database and graphs the
   information using the Automation Objects from the Excel server in Microsoft
   Office. You must connect to a sports2000 database before running this. This
   sample program leaves Excel open. You should close it manually when the
   program completes. */
DEFINE VARIABLE chExcelApplication   AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chWorkbook           AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chWorksheet          AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chChart              AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chWorksheetRange     AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE iCount               AS INTEGER    NO-UNDO.
DEFINE VARIABLE iIndex               AS INTEGER    NO-UNDO.
DEFINE VARIABLE iTotalNumberOfOrders AS INTEGER    NO-UNDO.
DEFINE VARIABLE iMonth               AS INTEGER    NO-UNDO.
DEFINE VARIABLE dAnnualQuota         AS DECIMAL    NO-UNDO.
DEFINE VARIABLE dTotalSalesAmount    AS DECIMAL    NO-UNDO.
DEFINE VARIABLE iColumn              AS INTEGER    NO-UNDO INITIAL 1.
DEFINE VARIABLE cColumn              AS CHARACTER  NO-UNDO.
DEFINE VARIABLE cRange               AS CHARACTER  NO-UNDO.

/* create a new Excel Application object */
CREATE "Excel.Application" chExcelApplication.

/* launch Excel so it is visible to the user */
chExcelApplication:Visible = TRUE.

/* create a new Workbook */
chWorkbook = chExcelApplication:Workbooks:Add().

/* get the active Worksheet */
chWorkSheet = chExcelApplication:Sheets:Item(1).

/* set the column names for the Worksheet */
chWorkSheet:Columns("A"):ColumnWidth = 18.
chWorkSheet:Columns("B"):ColumnWidth = 12.
chWorkSheet:Columns("C"):ColumnWidth = 12.
chWorkSheet:Range("A1:C1"):Font:Bold = TRUE.
chWorkSheet:Range("A1"):Value        = "SalesRep".
chWorkSheet:Range("B1"):Value        = "Total Sales".
chWorkSheet:Range("C1"):Value        = "Annual Quota".

/* Iterate through the SalesRep table, populate the Worksheet appropriately */
FOR EACH SalesRep NO-LOCK:
  ASSIGN
dAnnualQuota         = 0
iTotalNumberOfOrders = 0
dTotalSalesAmount    = 0
iColumn              = iColumn + 1.

  FOR EACH Order OF SalesRep NO-LOCK:
    iTotalNumberOfOrders = iTotalNumberOfOrders + 1.
    FIND Invoice WHERE Invoice.OrderNum = Order.OrderNum NO-ERROR.
    IF AVAILABLE Invoice THEN
      dTotalSalesAmount = dTotalSalesAmount + Invoice.Amount.
  END.

  DO iMonth = 1 TO 12:
    dAnnualQuota = dAnnualQuota + Salesep.MonthQuota[iMonth].
  END.

  ASSIGN
cColumn                         = STRING(iColumn)
cRange                          = "A" + cColumn
chWorkSheet:Range(cRange):Value = SalesRep.RepName
cRange                          = "B" + cColumn
chWorkSheet:Range(cRange):Value = dTotalSalesAmount
cRange                          = "C" + cColumn
chWorkSheet:Range(cRange):Value = dAnnualQuota.
END.
chWorkSheet:Range("B2:C10"):Select().
chExcelApplication:Selection:Style = "Currency".

/* create embedded chart using the data in the Worksheet */
chWorksheetRange = chWorksheet:Range("A1:C10").
chWorksheet:ChartObjects:Add(10,150,425,300):Activate.
chExcelApplication:ActiveChart:ChartWizard(chWorksheetRange, 3, 1, 2, 1, 1,
TRUE, "1996 Sales Figures", "Sales Person", "Annual Sales").

/* create chart using the data in the Worksheet */
chChart=chExcelApplication:Charts:Add().
chChart:Name = "Test Chart".
chChart:Type = 11.

/* release com-handles */
RELEASE OBJECT chExcelApplication.
RELEASE OBJECT chWorkbook.
RELEASE OBJECT chWorksheet.
RELEASE OBJECT chChart.
RELEASE OBJECT chWorksheetRange.