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
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