ChemCAD 5 services to visual basic applications: User Manual, страница 3






job name for which cases are seeked

Method             GetCaseAt

Returns                        a string of case name






job name for which cases are seeked



case index

Excel unit

The steps of specifying an Excel Unit are simple to follow. First, place an icon of Excel Unit on the current flowsheet, and make stream connections to or from other unit icons, feeds or products. Second, switch to simulation mode, double click the Excel Unit icon to open the build-in Excel Unit dialog box, and examine the paths of unit dialog files, the Excel workbook and the names of the macros to be executed during a simulation run. Third, program VBA macros in the specified Excel workbook. After finishing all previous steps, run simulations from CHEMCAD 5, debug through the Excel macros.

Four files are required to support an Excel Unit. They are screen layout (*.my), variable map (*.map), labels for report (*.lab), and an Excel workbook (*.xls). As default, these four files are created under the current job directory with current case name followed by respective extensions. For example, the current job directory is “\CC5Data\MyExcelJob” and a case “CaseA” is loaded. When user double-clicks the Excel Unit icon the first time, four files,, CaseA.lab and CaseA.xls are created under directory “\CC5Data\MyExcelJob”. These files can be renamed or modified to meet user’s needs. Dialog layout file, map file and label file need to have identical name. These files are necessary for entering parameters of the Excel Unit. The parameters can later be retrieved within the Excel macros during simulation runs. User can find more information on creating unit specification dialog files elsewhere [1]. The default version of Excel workbook copies the first inlet to the first outlet for its Excel Unit. The user can change Excel workbook path, and should modify or provide macros for their intended calculations.

The first interface ICHEMCADEntry for Excel Unit is one that will lead to all other interfaces. The only role of this interface is to allow user to reach other interfaces. Only after getting hold of other interfaces, can a user use any ChemCAD 5 calculations.

Description      ICHEMCADEntry interface is the entry point to all other interfaces. When calling an Excel workbook macro during a simulation run, CHEMCAD 5 always passes a handle of this interface to the VBA macro as shown in the following example.

Sub MyMacro (ByVal ChemCADEntry As Object)

On Error Resume Next

' Get ChemCAD objects

Dim curUnitOp As Object

Dim strInfo As Object

Dim uopInfo As Object

Set curUnitOp = ChemCADEntry.GetCurUnitOp

Set strInfo = ChemCADEntry.GetStreamInfo

Set uopInfo = ChemCADEntry.GetUnitOpInfo

End Sub

The writer of a macro should determine the selection of other interfaces to bring into his/her subroutine to meet the calculation needs. In this example, three interfaces are obtained through the methods of ICHEMCADEntry. They are ICurUnitOp, IStreamInfo and IUnitOpInfo. With the handles of these interfaces, a user can access the methods provided by these interfaces. The functionality of these interfaces and those of others will be explained in detail in the following sections.

Definition:       dispinterface ICHEMCADEntry



VARIANT GetFlash();

VARIANT GetStreamUnitConversion();

VARIANT GetCurUnitOp();

VARIANT GetEnthalpy();

VARIANT GetKValues();

VARIANT GetFlowsheet();

VARIANT GetStreamInfo();

VARIANT GetStreamProperty();

VARIANT GetUnitOpInfo();

VARIANT GetUnitOpSpecUnitConversion();

VARIANT GetEngUnitConversion();

VARIANT GetCompPPData();

boolean GetSaveWorkBookFlag();

boolean SetSaveWorkBookFlag(boolean bSaveAfterRun);


Methods          Each of the methods exposed by ICHEMCADEntry takes a void argument and returns an IDispatch pointer of another interface to the calling subroutine.