Specifications
2-56 Example 1: The Macro Language
2-56
2. Add a function that returns the Stream object that you
choose from a list. Creating separate functions allows for
easy re-use in other programs.
Code Explanation
Function SelectStream(simcase As Object) As Object
Signifies the beginning of the
SelectStream function. This
function takes a SimulationCase
object and prompts the user to
select a Stream from a list of
streams in the case, returning
an interface to the Stream.
Set FS = simcase.Flowsheet
Acquire the case flowsheet.
Set Strms = FS.MaterialStreams
Acquire the collection of Streams
from the flowsheet.
Dim strmnames()
strmnames = Strms.Names
Build a string array of the
Stream names.
Begin Dialog UserDialog 390,210,”Streams in “ +
Right$(simcase.FullName, Len(simcase.FullName)-
Len(simcase.Path))
ListBox 20,35,350,119,strmnames(),.listsrc
Text 20,14,360,14,”Select a Stream for Mach
number estimation:”
OKButton 140,175,90,21
CancelButton 270,175,90,21
End Dialog
Generate a user property view
containing a list of Streams
Please notice that the first
button created automatically
becomes the default.
Use the Language Help option
provided in the Help menu to
explore the use of UserDialogs.
Dim dlg As UserDialog
If Dialog(dlg) = 0 Then End
Finally, run the Dialog and
terminate the macro if the user
cancels (i.e., Dialog function
returns 0).
Set SelectStream = Strms(dlg.listsrc)
Set the function's return value to
the user selected stream
interface.
End Function
Signifies the end of the function.
This line does not need to be
added.
The “_” appears at the end of any line of code indicates that
the following line is a continuation of the present line.