Progress
External Program
Interfaces


Example Automation Applications

Progress 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 sports 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 sports 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:

oleauto.p
/* 
 * This sample extracts data from a Progress database
 * and graphs the information using the Automation Objects
 * from the Excel server in Microsoft Office.
 * You must connect to a sports 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.
DEFINE VARIABLE chWorkbook              AS COM-HANDLE.
DEFINE VARIABLE chWorksheet             AS COM-HANDLE.
DEFINE VARIABLE chChart                 AS COM-HANDLE.
DEFINE VARIABLE chWorksheetRange        AS COM-HANDLE.
DEFINE VARIABLE iCount                  AS INTEGER.
DEFINE VARIABLE iIndex                  AS INTEGER.
DEFINE VARIABLE iTotalNumberOfOrders    AS INTEGER.
DEFINE VARIABLE iMonth                  AS INTEGER.
DEFINE VARIABLE dAnnualQuota            AS DECIMAL.
DEFINE VARIABLE dTotalSalesAmount       AS DECIMAL.
DEFINE VARIABLE iColumn                 AS INTEGER INITIAL 1.
DEFINE VARIABLE cColumn                 AS CHARACTER.
DEFINE VARIABLE cRange                  AS CHARACTER.

/* 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 and populate
   the Worksheet appropriately */ 
FOR EACH salesrep:
    dAnnualQuota = 0.
    iTotalNumberOfOrders = 0.
    dTotalSalesAmount = 0.
    iColumn = iColumn + 1.
    FOR EACH order OF salesrep:
        iTotalNumberOfOrders = iTotalNumberOfOrders + 1.
        FIND invoice WHERE invoice.order-num = Order.order-num NO-ERROR.
        IF AVAILABLE invoice THEN 
            dTotalSalesAmount = dTotalSalesAmount + invoice.amount.
    END.
    
    DO iMonth = 1 TO 12:
        dAnnualQuota = dAnnualQuota + salesrep.month-quota[iMonth].
    END.
    
    cColumn = STRING(iColumn).
    cRange = "A" + cColumn.
    chWorkSheet:Range(cRange):Value = salesrep.rep-name.
    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. 


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095