Sei sulla pagina 1di 2

Macro3.

WWB (page #1)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

Const pi As Double = 3.1415927


Const R As Double = 8.3144
Const nPipes As Integer = 8
Dim PipeSizes(1 To nPipes) As Double
Function SelectStream(simcase As Object) As Object
Set FS = simcase.Flowsheet
Set Strms = FS.MaterialStreams
Dim strmnames() As String
strmnames = Strms.Names
Begin Dialog UserDialog 390,210,"Streams In" + Right$(simcase.FullName, Len(simcase.FullName)-Len(s
imcase.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
Dim dlg As UserDialog
If Dialog(dlg) = 0 Then End
Set SelectStream = Strms(dlg.listsrc)
End Function
Sub Main
PipeSizes(1) = 2
PipeSizes(2) = 3
PipeSizes(3) = 4
PipeSizes(4) = 6
PipeSizes(5) = 8
PipeSizes(6) = 10
PipeSizes(7) = 12
PipeSizes(8) = 16
Dim simcase As Object
Set simcase = ActiveCase
If simcase Is Nothing Then
MsgBox "No HYSYS Case Is Open."
End
End If
Dim strm As Object
Set strm = SelectStream(simcase)
Set flow = strm.MassFlow
If flow.IsKnown Then
flowValue = flow.GetValue("lb/hr")
flowValue = flowValue / 3600
Else
GoTo NoFlow
End If
Set rho = strm.MassDensity
If rho.IsKnown Then
rhoValue = rho.GetValue("lb/ft3")
Else
GoTo NoRho
End If
flowValue = flowValue / rhoValue
On Error GoTo NoCv
Cv = strm.MolarHeatCapacityValue / strm.CpCvValue
On Error GoTo NoZ
Z = strm.CompressibilityValue
On Error GoTo NoTemp
T = strm.TemperatureValue + 273.15
On Error GoTo NoMolWt
MolWt = strm.MolecularWeightValue / 1000.0
soundVel = Sqr(Z*R*T/MolWt*(1.0+Z*R/Cv))
soundVel = soundVel / 0.3048
soundVelTxt = Format(soundVel, "###,###,###.###")
Dim DispText() As String
ReDim DispText(nPipes + 2)
DispText(0) = "Pipe Size (In) Mach Number "
DispText(1) = "---------------------------------------------------------------"
For num = 1 To nPipes
rSquared = PipeSizes(num) * PipeSizes(num)/144.0/4.0
Mach = flowValue / pi / rSquared / soundVel
sizetxt = Format(PipeSizes(num),"###,###,###.###")
Machtxt = Format(Mach, "###,###,###.#####")
DispText(num + 1) = Format$(sizetxt,"@@@@@@@@@@@@@@@") + " " + Format$(Machtxt, "@@@@@@@@@@@@@@@")
Next num

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

Macro3.WWB (page #2)


Begin Dialog UserDialog 360,217
ListBox 10,49,340,133,DispText(),.Field5
OKButton 250,189,90,21
Text 30,14,150,14,"Speed of Sound (ft/s):",.Field2
TextBox 190,14,90,21,.Field1
End Dialog
Dim dlg2 As UserDialog
dlg2.Field1 = soundVelTxt
Dialog dlg2
End
NoFlow:
MsgBox "Unknown mass flow in stream " + strm.name
End
NoRho:
MsgBox "Unknown density in stream " + strm.name
End
NoCv:
MsgBox "Unknown heat capacity in stream " + strm.name
End
NoZ:
MsgBox "Unknown compressibility in stream " + strm.name
End
NoTemp:
MsgBox "Unknown temperature in stream " + strm.name
End
NoMolWt:
MsgBox "Unknown molecular weight in stream " + strm.name
End
End Sub

Potrebbero piacerti anche