Some examples of VBA scripts used for accessing flowsheet variables (either to set or get) using “Variable Data Exchange Methods” are given. In some cases additional tasks (using “Application Related Methods” or “Simulation Related Methods”) are performed.
Example 1: Obtaining a Flowsheet variable
Function GetTotalComponentInput(componentName) As Double
Dim var1 As Variant
Dim var2 As Variant
var2 = CStr(componentName)
Set superProDoc = DocumentObject()
superProDoc.GetFlowsheetVarVal2 VarID.totalComponentInput_VID, var1, var2
GetTotalComponentInput = CDbl(var1)
End Function
The above script is an example of a function that returns the value of the annual amount for a component that is input to the process. This VBA function GetTotalComponentInput() can be called directly from an Excel cell passing as an argument the component name either as a cell or as a string. The function DocumentObect() (, see Application Related Scripts ) is another VBA function that returns an active simulation (design) case object. The GetFlowsheetVarVal2 is the 3-argument Pro-Designer COM function that is used to obtain the input amount (var1) of a desired component (var2). Note that since we do not specify in the function statement the type of componentName we use the CStr() function in the script to do so. You do not have to worry about the type of var1, because it’s value and type is being set by the Pro-Designer function.