Specifications
User Variables 5-15
5-15
The checkboxes in the Variable group on the right of the Macros
tab enables macros that are invoked when the value of the User
Variable is modified or accessed.
The sub-routines that are added to the User Variable when the
checkboxes, in the Variable group, are selected include:
The following code example demonstrates simple bounds
checking for a numeric User Variable using a Variable Changing
sub-routine:
The presence of code for a particular macro sub-routine is not
sufficient to have that code invoked - the macro's checkbox
must also be enabled. If you disable a macro, HYSYS requires
confirmation before it proceeds with this action. Pasting or
typing macro sub-routine code in to the Code Editor causes the
specific macro to be automatically enabled.
Sub-routine Initialization
Variable
Changing
Called when an attempt is made to specify a new value for
the User Variable from any source other than the variable’s
own macro code.The new value is available for inspection
using the ActiveVariableWrapper macro keyword. If the
Variable Changing code chooses to disallow the change, it
must set the AllowThisChange property to false.
Variable
Changed
Invoked immediately after a new value has been assigned
to the variable.
Variable
Query
Invoked whenever the value for a User Variable is about to
be read.
Code Example
Sub VariableChanging()
If ActiveVariableWrapper.NewRealValue > 100 Or
ActiveVariableWrapper.NewRealValue < 1 Then
AllowThisChange = False
MsgBox "Valid values are in the range 1-100", vbOkOnly,
"User Variable"
End If
End Sub
If you disable a macro with its code still present and then
type or paste in the Code Editor, the macro is automatically
re-enabled.