Specifications
5-28 User Variable Examples
5-28
8. Select the PostExecute() checkbox found on the Macro
tab. Enter the following PostExecute macro in the Code
Editor.
Macro Code
' Automatically add and connect an energy stream once feed and product
' streams are connected.
' The process will not repeat unless this variable is reset to NotYetRun.
' Global constants matching the enumeration values of this user variable.
' Note that only constant values are useful here. Non-constant global
' variables will lose their values
' between invocations of this macro code. Create user variables when
' storing persistent 'information.
Const NotYetRun = 0
Const HasRun = 1
' The use of both late and early binding are demonstrated here.
' Late binding should be used during development and testing since it is
' more robust and produces more useful error messages.
' Early binding should be used where performance is an issue as it is
' slightly faster. Or when an explicit 'cast' to a certain interface of
' an object is required.
Sub PostExecute()
' Error handling minimized for clarity.
On Error GoTo UnknownError
'Early binding of PumpOp object.
Dim pump As PumpOp
'ActiveObject is the object that owns this user variable.
Set pump = ActiveObject
' Early binding of RealVariable object.
Dim thisvar As RealVariable
' ActiveVariableWrapper is the InternalVariableWrapper containing this
' user variable.
Set thisvar = ActiveVariableWrapper.Variable
' Only run once. If the user wants me to run again,
' change my value to "Not Yet Run'
If thisvar.Value = HasRun Then GoTo AlreadyAdded
If Pump.FeedStreamVar.IsKnown = False Then
Exit Sub
ElseIf Pump.ProductStreamVar.IsKnown = False Then
Exit Sub
ElseIf Pump.EnergyStreamVar.IsKnown = False Then