
2-68 Example 2: Automation in Visual
2-68
15. The first sub-routine should already be declared. The
Form_Load sub-routine is the first sub-routine called once
the program is run. It is usually used to initialize the
variables and objects used by the program. Enter the
following code in to the Form_Load sub-routine.
16. The next section of code to be added tells the program what
is to occur when an option is selected in the ddUnitSet
combo box.
Code Explanation
Private Sub Form_Load()
Signifies the Start of the form load sub-routine. You do
not have to add it as it should already be there.
ddUnitSet.Clear
ddFromUnit.Clear
ddToUnit.Clear
Clear the default text found inside the ddUnitSet,
ddFromUnit and ddToUnit combo boxes.
Set hyApp = CreateObject("HYSYS.Application")
Set UCSM = hyApp.UnitConversionSetManager
Connects to HYSYS and the HYSYS Unit Conversion Set
Manager.
For Each UCS In UCSM
ddUnitSet.AddItem UCS.Name
Next UCS
For each Unit Conversion Set found in the Unit
Conversion Set Manager add the Unit Set to
ddUnitSet combo box list.
ddUnitSet.ListIndex = -1
Indicates no item is currently selected in the ddUnitSet
combo box.
ebFromValue.Text = ""
lbToValue.Caption = ""
Clears the text that appears in the ebFromValue text
box and the lbToValue label.
End Sub
Signifies the end of the initialization sub-routine. This
line does not need to be added.
Code Explanation
Private Sub ddUnitSet_Click()
Signifies the Start of the sub-routine.
ddFromUnit.Clear
ddToUnit.Clear
Clears any list entries in the ddFromUnit and
ddToUnit combo boxes.
Set hyApp = CreateObject("HYSYS.Application")
Set UCSM = hyApp.UnitConversionSetManager
Connects to HYSYS and the HYSYS Unit Conversion Set
Manager.
UCSNumber = ddUnitSet.ListIndex
Once the selection is made in the ddUnitSet combo
box, the UCSNumber variable holds the internal
HYSYS index number of the selected Unit Set.
Set UCS = UCSM.Item(UCSNumber)
Find the selected Unit Conversion Set in Unit
Conversion Manager.
For Each UC In UCS
ddFromUnit.AddItem UC.Name
ddToUnit.AddItem UC.Name
Next UC
For each Unit Conversion type (UC) in the Unit
Conversion Set, add the Unit type to both the
ddFromUnit combo box (the unit type the program is
converting from) and the ddToUnit (the unit type the
program is converting to).
ddFromUnit.ListIndex = -1
ddToUnit.ListIndex = -1
Indicates no items are currently selected in the
ddFromUnit and ddToUnit combo box.
Komentáře k této Příručce