Scripts For Stream Variables

Examples of VBA scripts used for accessing ingredient related variables:

Example 1: Get the mass flow of a stream

Function GetStreamMassFlow(streamName) As Double

Dim var1 As Variant

Dim str As String

Set SuperProDoc = DocumentObject()

str = CStr(streamName)

SuperProDoc.GetStreamVarVal str, VarID.massFlow_VID, var1, str

GetStreamMassFlow = CDbl(var1)

End Function

 

The above script is an example of a function used to retrieve the mass flow of a stream (with name streamName). The Pro-Designer COM function GetStreamVarVal is used. The arguments that it uses are the streamName string, the VarID for the variable we want to retrieve and the ingredient local name which is not required in this case and can be an empty ("") string or any other string.

 

Example 2: Setting the mass fraction of a component in a stream

Function SetAndGetIngredientMassFrac(streamName, componentName, compMassFrac) As Double

 

Dim var1 As Variant

Dim var2 As Variant

Dim str As String

Dim str2 As String

 

Set SuperProDoc = DocumentObject()

 

str = CStr(streamName)

str2 = CStr(componentName)

var1 = CDbl(compMassFrac)

SuperProDoc.SetStreamVarVal str, VarID.compMassFrac_VID, var1, str2

SuperProDoc.GetStreamVarVal str, VarID.compMassFrac_VID, var2, str2

 

SetAndGetIngredientMassFrac = CDbl(var2)

End Function

 

The above script is an example of a function used to set the mass fraction of a component (componentName) in a stream (streamName). The Pro-Designer COM function SetStreamVarVal (with arguments the streamName, compMassFrac_VID, and the componentName) is used. The function also retrieves the value of the component mass fraction using GetStreamVarVal for verification purposes.

 

Error Handling Scripts

Examples of VBA scripts used for error handling:

Example 1: Retrieving the COM Error Message

 

Sub GetErrorMsg()

Dim var1 As Variant

Set SuperProDoc = DocumentObject()

SuperProDoc.GetCOMErrorMsg var1

Dim errorMsg As String

errorMsg = var1

Worksheets("Sheet1").Range("B80") = errorMsg

End Sub

 

The above script is an example of a subroutine used to retrieve the latest error message that was generated during an unsuccessful (previous) use of another Pro-Designer GetCOMErrorMsg COM method. In this case the string with the error message is then displayed in worksheet "Sheet1" and cell B83. If for example you try to set / get a flowsheet variable and the function returns False you can use this VBA subroutine to find out why the data exchange failed.

 

Example 2: Retrieving the COM error Message after failing to retrieve a flowsheet variable.

 

Sub GetFlowsheetVar()

Dim var1 As Variant

Dim bReturn As Boolean

Set SuperProDoc = DocumentObject()

 

bReturn = SuperProDoc.GetFlowsheetVarVal(incorrect_VID, var1)

If bReturn Then

  Worksheets("Sheet1").Range("B81") = CDbl(var1)

Else

  SuperProDoc.GetCOMErrorMsg var1

  Worksheets("Sheet1").Range("B82") = CStr(var1)

End If

End Sub

 

The above script is an example of a subroutine used to retrieve a Flowsheet variable with an incorrect VarID. This results in the bReturn which is a Boolean data type to be false and in this case the script calls the GetCOMErrorMsg to retrieve the error message and display it in Worksheet "Sheet1" and cell B82. Note that var1 could be a double data type if the VarID was correct, but in this case it is a String and cast accordingly.

 

Example 3: Checking the consistency of data exchange

 

Sub IsCOMSimDataComplete()

Dim SimDataOK As Boolean

Set SuperProDoc = DocumentObject()

SimDataOK = SuperProDoc.IsCOMSimDataComplete

Range("B77") = SimDataOK

 

The above script is an example of a subroutine used to check whether the data exchange using the COM functions was consistent. The Pro-Designer COM method IsCOMSimDataComplete is used. Most Data Exchange methods (Variable Data Exchange Methods) check and therefore forbid these inconsistencies but there are some cases that all data exchange has to be completed before checking. For example you can independently set the mass fractions of components in a stream. When the IsCOMSimDataComplete is called it will verify that the sum of all mass fractions in the streams is equal to 1.0.

Report Creation Related Scripts

Examples of general-purpose application related scripts that use the Pro-Design report creation related COM methods:

 

Example 1:

Sub CreateReports()

   SpecifyReportOptions

   CreateIDReport

   CreateStreamReport

   CreateCashFlowReport

End Sub

 

Sub SpecifyReportOptions()

   Dim superProDoc As Designer.Document

   Dim footer  As Variant

   footer = CStr("COM generated report")

   Set superProDoc = DocumentObject()

   superProDoc.SetReportFormat rtF_EF

   superProDoc.SetReportGeneralOptions footer_VID, footer

End Sub

 

Sub CreateIDReport()

   Dim superProDoc As Designer.Document

 

   Set superProDoc = DocumentObject()

   superProDoc.GenerateReport inputDataReport_VID

End Sub

 

Sub CreateStreamReport()

   Dim superProDoc As Designer.Document

   Set superProDoc = DocumentObject()

   superProDoc.GenerateReport streamReport_VID

End Sub

 

Sub CreateCashFlowReport()

   Dim superProDoc As Designer.Document

   Set superProDoc = DocumentObject()

   superProDoc.GenerateReport cashFlowReport_VID

End Sub

 

In this VBA example the VBA Subroutine CreateReports() is used for calling 4 other subroutines to specify the reports options and then create certain reports, the Input Data, Stream and Cash Flow reports (with default file name & location) .

 

Example 2:

Sub CreateReportToFile()

   Dim superProDoc As Designer.Document

   Set superProDoc = DocumentObject()

   Dim fileName As String

   superProDoc.SetReportFormat htm_EF

fileName = "C:\Program Files\Intelligen\SuperPro Designer 6.0\Examples\COM\EconEvalReport.htm"

   superProDoc.GenerateReportToFile fileName, econEvalReport_VID

End

 

In this VBA example the VBA Subroutine CreateReportToFile() is used for creating the economic evaluation report, and saving it to the specified file name and location.

 

Excel Data Link Related Scripts

Examples of general-purpose application related scripts that use the Pro-Design report creation related COM methods:

 

Example 1:

Dim workbookName As Variant

Dim rangeName As Variant

Sub SetProcedureTableOptions()

workbookName = CStr("C:\Program Files\Intelligen\SuperPro Designer 6.0\Examples\COM\COMEx6.xls")

   rangeName = CStr("RangeProc")

   Dim procName As String

   procName = "P-20"

   Dim varBool As Variant

   varBool = CBool(True)

   spfFileOne = Worksheets("Charts Examples").range("B10")

spfFileOne = spfFileOne + "\" + Worksheets("Charts Examples").range("B11")

   Set superProDoc = DocumentObject(spfFileOne)

 

    superProDoc.SetXLSLinkDataForProcedureOperSeqTable procName, workbook_VID, workbookName

    superProDoc.SetXLSLinkDataForProcedureOperSeqTable procName, rangeName_VID, rangeName

    superProDoc.SetXLSLinkDataForProcedureOperSeqTable procName, bEraseExtraCellArea_VID, varBool

    superProDoc.SetXLSLinkDataForProcedureOperSeqTable procName, bExpandExtraCellArea_VID, varBool

    superProDoc.SetXLSLinkDataForProcedureOperSeqTable procName, bIncludeColumnHeaders_VID, varBool

 

    superProDoc.SetXLSLinkDataForProcedureOperSeqTable procName, bIncludeRowHeaders_VID, varBool

End Sub

 

In this VBA example the VBA Subroutine SetProcedureTableOptions() is used for setting the data link variables for the Activity Overview table of a procedure with the name “P-20”.

 

Object Export Scripts

Some examples of VBA scripts used for exporting objects such as Charts, Pictures, etc.

 

Example 1: Exporting the ingredient consumption chart to the clipboard

Sub ExportIngrConsumptionClipboard()

   Set SuperProDoc = DocumentObject("filename")

   Dim ingrName As String

   Dim noBatches As CLng

   ingrName = CStr("Water")

   noBatches = CLng(3)

 

   Dim consumptionType As Long

   consumptionType = cleaningAgent_ICT

    SuperProDoc.ExportIngredientConsObject ingrName, Clipboard_ED, "", noBatches, consumptionType, False, True

End Sub

 

The above script will export the consumption tracking chart of the ingredient "water" to the clipboard (no filename has been given, note the empty string of the third argument). The number of batches have been set to 3 and the consumption type is as a “cleaning agent”. Also we do not want to take in account the consumption of water in entities (False), but we do want to include the consumption of water in mixtures (True).

 

Scripts For Enumerators

Some examples of VBA scripts demonstrating how enumerators can be used:

      Enumerating All Input Streams in a Unit Procedure

      Enumerating All Unit Procedures in a Flowsheet

      Enumerating All Unit Procedures in All Sections in All Branches

      Enumerating All Unit Procedures in All Sections in All Branches