Programa Hoja de Calculo Tubería

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Hoja1 - 1

Private Sub Worksheet_Change(ByVal Target As Range)

SNPD = "PressDrop" 'Sheets(1).Name


SNAcc = "PDropAcc" 'Sheets(2).Name

If Target.Row > 9 And Target.Column = 1 Then


If ActiveSheet.Cells(Target.Row, 1) <> "" Then
Sheets(SNAcc).Cells(Target.Row, 1) = "=Stream"
Sheets(SNAcc).Cells(Target.Row, 41) = "=Re"
Sheets(SNAcc).Cells(Target.Row, 42) = "=ID"
Sheets(SNAcc).Cells(Target.Row, 43) = "FALSE"
Sheets(SNAcc).Cells(Target.Row, 44) = "=SumK"
Sheets(SNAcc).Cells(Target.Row, 45) = "=Lacc"
Else
Sheets(SNAcc).Cells(Target.Row, 1) = ""
For i = 1 To 5
Sheets(SNAcc).Cells(Target.Row, 40 + i) = ""
Next i
End If
End If

IDcol = 11
If Target.Row = 8 And Target.Column = IDcol Then
If ActiveSheet.Cells(8, IDcol) = "[in]" And Sheets(SNAcc).Cells(8, 40) = "[mm]" Then
Sheets(SNAcc).Cells(8, 40) = "[in]"
For i = 1 To 2000
If ActiveSheet.Cells(i + 8, IDcol) <> "" Then ActiveSheet.Cells(i + 8, IDcol) = Round(Act
iveSheet.Cells(i + 8, IDcol) / 25.4, 3):
ActiveSheet.Cells(i + 8, IDcol).NumberFormat = "0.00"
Next i
ElseIf ActiveSheet.Cells(8, IDcol) = "[mm]" And Sheets(SNAcc).Cells(8, 40) = "[in]" Then
Sheets(SNAcc).Cells(8, 40) = "[mm]"
For i = 1 To 2000
If ActiveSheet.Cells(i + 8, IDcol) <> "" Then ActiveSheet.Cells(i + 8, IDcol) = Round(Act
iveSheet.Cells(i + 8, IDcol) * 25.4, 2):
ActiveSheet.Cells(i + 8, IDcol).NumberFormat = "0.0"
Next i
ElseIf ActiveSheet.Cells(8, IDcol) = "" Then ActiveSheet.Cells(8, IDcol) = Sheets(SNAcc).Cell
s(8, 40)
End If
End If

AccCol = 15
If Target.Row > 8 And Target.Column = AccCol Then
If Sheets(SNPD).Cells(Target.Row, AccCol) <> Sheets(SNAcc).Cells(Target.Row, 44) Then Sheets(SN
Acc).Cells(Target.Row, 43) = False
End If

If Target.Row = 5 And Target.Column = 1 Then


Cells.EntireColumn.Hidden = 0
Sheets(SNAcc).Visible = 1
Sheets("KData").Visible = 1
Select Case Sheets(SNPD).Cells(Target.Row, Target.Column)
Case Is = "ONE-PHASE LINE SIZING"
Sheets(SNAcc).Visible = 0
Sheets("KData").Visible = 0
Columns(9).EntireColumn.Hidden = 1
Columns(10).EntireColumn.Hidden = 1
Columns(13).EntireColumn.Hidden = 1
Columns(14).EntireColumn.Hidden = 1
Columns(15).EntireColumn.Hidden = 1
Columns(16).EntireColumn.Hidden = 1
Columns(17).EntireColumn.Hidden = 1
Columns(18).EntireColumn.Hidden = 1
Columns(19).EntireColumn.Hidden = 1
Columns(20).EntireColumn.Hidden = 1
Columns(25).EntireColumn.Hidden = 1
Case Is = "ONE-PHASE LINE PRESSURE DROP"
Sheets(SNAcc).Visible = 1
Sheets("KData").Visible = 1
Case Is = "FLARE LINE PRESSURE DROP"
Sheets(SNAcc).Visible = 1
Sheets("KData").Visible = 1
Cells.EntireColumn.Hidden = 0
Columns(19).EntireColumn.Hidden = 1
Hoja1 - 2

Columns(20).EntireColumn.Hidden = 1
Columns(21).EntireColumn.Hidden = 1
End Select
End If

End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

IDcol = 11
If Target.Column = IDcol And Target.Row > 8 Then
If Target.Value <> "" Then Call FormDiamGen
Target.Offset(1).Select
End If

RugCol = 12
If Target.Column = RugCol And Target.Row > 8 Then
If Target.Value <> "" Then FormRugos.Show
End If

AccCol = 15
If Target.Column = AccCol And Target.Row > 8 Then
If Target.Value <> "" Then Call FormAccGen
Target.Offset(1).Select
End If

MachCol = 25
If Target.Column = MachCol And Target.Row > 8 And ActiveSheet.Cells(Target.Row, 2) > 0.999 Then
If Target.Value <> "" Then Call FormChokeGen
FormChoke.Show
Target.Offset(1).Select
End If

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

SNPD = "PressDrop" 'Sheets(1).Name


SNAcc = "PDropAcc" 'Sheets(2).Name

IDcol = 11
If Target.Row = 8 And Target.Column = IDcol Then Sheets(SNAcc).Cells(8, 40) = Sheets(SNPD).Cells(
8, IDcol) Else Sheets(SNAcc).Cells(8, 40) = "[mm]"

End Sub
Hoja2 - 1

Private Sub Worksheet_Change(ByVal Target As Range)

SNPD = "PressDrop" 'Sheets(1).Name


SNAcc = "PDropAcc" 'Sheets(2).Name

AccCol = 15
If Target.Row > 8 And Sheets(SNAcc).Cells(Target.Row, 43) Then Sheets(SNPD).Cells(Target.Row, Acc
Col) = Sheets(SNAcc).Cells(Target.Row, 44)

FormAcc.TextBoxSumK.Value = Round(Sheets(SNAcc).Cells(10 + FormAcc.ComboBoxStream.ListIndex, 44),


2)
FormAcc.TextBoxLeq.Value = Round(Sheets(SNAcc).Cells(10 + FormAcc.ComboBoxStream.ListIndex, 45),
1)

If Sheets(SNAcc).Cells(8, 40) = "" Then Sheets(SNAcc).Cells(8, 40) = Sheets(SNPD).Cells(8, 11)

End Sub
ThisWorkbook - 1

Private Sub Workbook_Open()

'PressDrop
'Sheets(1).Cells(9, 16).FormulaArray = "=PTD(B9,C9,D9,E9,F9,fanning(Re,L9/ID),H9,I9,J9,ID,M9,N9,O9)
"
'Sheets(1).Cells(9, 17).FormulaArray = "=PTD(B9,C9,D9,E9,F9,fanning(Re,L9/ID),H9,I9,J9,ID,M9,N9,O9)
"
'Sheets(1).Cells(9, 18).FormulaArray = "=PTD(B9,C9,D9,E9,F9,fanning(Re,L9/ID),H9,I9,J9,ID,M9,N9,O9)
"
'Sheets(1).Cells(9, 20) = "=-SI(B9=0,(P9-D9)/F9/9.81,((D9+1.013)/F9/9.81)*SI(I9=""Isothrm"",LN((P9+
1.013)/(D9+1.013)),(((P9+1.013)/(D9+1.013))^(1-1/k)-1)/(1-1/k)))*100000"
'Sheets(1).Cells(9, 22) = "=(C9/3600/(PI()*(ID/1000)^2/4))/MIN(F9,R9)"
'Sheets(1).Cells(9, 25) = "=SI(B9<0.999,""na"",(C9/3600/(PI()*(ID/1000)^2/4))/(SI(I9=""Isothrm"",1,
k)*MIN(F9*(D9+1.013),R9*(P9+1.013))*100000)^0.5)"

'PDropAcc
'Sheets(2).Cells(9, 1) = "=Stream"
'Sheets(2).Cells(9, 41) = "=Re"
'Sheets(2).Cells(9, 42) = "=ID"
''Sheets(2).Cells(9, 44).FormulaArray = "=SUMA(B9:AG9*TRANSPONER(KData!$G$9:$G$40))/AO9+SUMA(B9:AG9
*TRANSPONER(KData!$H$9:$H$40))*(1+1/(AP9/25,4))+SUMA(AH9:AM9*TRANSPONER(KData!$G$41:$G$46))/AO9+SUM
A(AH9:AM9*TRANSPONER(KData!$H$41:$H$46))+AN9"
''Sheets(2).Cells(9, 44) = "=KCalc(FILA(A9),AO9,AP9,B9:AN9)"
'Worksheets(2).Range("AR9").FormulaArray = "=SUM(RC[-42]:RC[-11]*TRANSPOSE(KData!R9C8:R40C8))/RC[-3
]+SUM(RC[-42]:RC[-11]*TRANSPOSE(KData!R9C9:R40C9))*(1+1/(RC[-2]/25.4))+SUM(RC[-10]:RC[-5]*TRANSPOSE
(KData!R41C8:R46C8))/RC[-3]+SUM(RC[-10]:RC[-5]*TRANSPOSE(KData!R41C9:R46C9))+RC[-4]"
'Sheets(2).Cells(9, 45) = "=Lacc"

End Sub
FormAcc - 1

Private Sub ComboBoxStream_Change()

Call UpDate(10 + FormAcc.ComboBoxStream.ListIndex)

End Sub
Private Sub ButtonByOther_Click()

Call FormAccByOtherGen

End Sub
Private Sub ButtonReset_Click()

Call Reset(10 + FormAcc.ComboBoxStream.ListIndex)

End Sub
Private Sub ButtonExit_Click()

FormAcc.Hide

End Sub
Private Sub LabelZP_Click()

ZP = MsgBox("What's this? ZP 2003", vbExclamation)

End Sub
FormAccByOther - 1

Private Sub ButtonCopy_Click()

SNAcc = "PDropAcc" 'Sheets(2).Name

Forig = 10 + FormAccByOther.ComboBoxStream.ListIndex
Fcopy = 10 + FormAcc.ComboBoxStream.ListIndex

For Col = 2 To 40
Sheets(SNAcc).Cells(Fcopy, Col) = Sheets(SNAcc).Cells(Forig, Col)
Next Col

FormAccByOther.Hide

End Sub
Private Sub ButtonExit_Click()

FormAccByOther.Hide

End Sub
FormChoke - 1

Private Sub OptionActual_Click()

' FormChoke.LabelFlow.Visible = 0
' FormChoke.TextBoxFlow.Visible = 0
' FormChoke.LabelDZ1.Visible = 0
' FormChoke.LabelDiam.Visible = 0
' FormChoke.TextBoxDiam.Visible = 0
' FormChoke.LabelDZ2.Visible = 0
Call FormChokeGen

End Sub

Private Sub OptionAdiab_Click()

' FormChoke.LabelFlow.Visible = 1
' FormChoke.TextBoxFlow.Visible = 1
' FormChoke.LabelDZ1.Visible = 1
' FormChoke.LabelDiam.Visible = 1
' FormChoke.TextBoxDiam.Visible = 1
' FormChoke.LabelDZ2.Visible = 1
Call FormChokeGen

End Sub

Private Sub OptionIsot_Click()

' FormChoke.LabelFlow.Visible = 1
' FormChoke.TextBoxFlow.Visible = 1
' FormChoke.LabelDZ1.Visible = 1
' FormChoke.LabelDiam.Visible = 1
' FormChoke.TextBoxDiam.Visible = 1
' FormChoke.LabelDZ2.Visible = 1
Call FormChokeGen

End Sub
FormDiam - 1

Private Sub ButtonAdopt_Click()

If FormDiam.MultiPage1.SelectedItem.Index = 1 Then
ID = FormDiam.TextBoxIDO.Value
Else
ID = FormDiam.TextBoxIDN.Value
End If
If ID <> "" Then ActiveSheet.Cells(ActiveCell.Row, ActiveCell.Column) = Str(ID)

If ActiveSheet.Cells(8, ActiveCell.Column) = "[in]" Then


ActiveSheet.Cells(ActiveCell.Row, ActiveCell.Column).NumberFormat = "0.00"
Else
ActiveSheet.Cells(ActiveCell.Row, ActiveCell.Column).NumberFormat = "0.0"
End If

End Sub

Private Sub ButtonExit_Click()

FormDiam.Hide

End Sub

Private Sub CheckBoxNPS_Click()

Call NPSGen

End Sub

Private Sub ComboBoxNPS_Change()

Call SCHGen

End Sub

Private Sub ComboBoxSCH_Change()

Call IDNCalc

End Sub

Private Sub ComboBoxOD_Change()

Call BWGGen

End Sub

Private Sub ComboBoxBWG_Change()

Call IDOCalc

End Sub
FormRugos - 1

Private Sub LabelRugV1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


ActiveSheet.Cells(ActiveCell.Row, ActiveCell.Column) = 0.259
End Sub

Private Sub LabelRugV1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single
, ByVal Y As Single)
LabelRugV1.Font.Italic = 1
LabelRugV2.Font.Italic = 0
LabelRugV3.Font.Italic = 0
LabelRugV4.Font.Italic = 0
LabelRugV5.Font.Italic = 0
LabelRugV6.Font.Italic = 0
LabelRugV7.Font.Italic = 0
LabelRugV8.Font.Italic = 0
LabelRugV9.Font.Italic = 0
End Sub

Private Sub LabelRugV2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


ActiveSheet.Cells(ActiveCell.Row, ActiveCell.Column) = 0.152
End Sub

Private Sub LabelRugV2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single
, ByVal Y As Single)
LabelRugV1.Font.Italic = 0
LabelRugV2.Font.Italic = 1
LabelRugV3.Font.Italic = 0
LabelRugV4.Font.Italic = 0
LabelRugV5.Font.Italic = 0
LabelRugV6.Font.Italic = 0
LabelRugV7.Font.Italic = 0
LabelRugV8.Font.Italic = 0
LabelRugV9.Font.Italic = 0
End Sub

Private Sub LabelRugV3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


ActiveSheet.Cells(ActiveCell.Row, ActiveCell.Column) = 0.122
End Sub

Private Sub LabelRugV3_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single
, ByVal Y As Single)
LabelRugV1.Font.Italic = 0
LabelRugV2.Font.Italic = 0
LabelRugV3.Font.Italic = 1
LabelRugV4.Font.Italic = 0
LabelRugV5.Font.Italic = 0
LabelRugV6.Font.Italic = 0
LabelRugV7.Font.Italic = 0
LabelRugV8.Font.Italic = 0
LabelRugV9.Font.Italic = 0
End Sub

Private Sub LabelRugV4_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


ActiveSheet.Cells(ActiveCell.Row, ActiveCell.Column) = 0.0457
End Sub

Private Sub LabelRugV4_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single
, ByVal Y As Single)
LabelRugV1.Font.Italic = 0
LabelRugV2.Font.Italic = 0
LabelRugV3.Font.Italic = 0
LabelRugV4.Font.Italic = 1
LabelRugV5.Font.Italic = 0
LabelRugV6.Font.Italic = 0
LabelRugV7.Font.Italic = 0
LabelRugV8.Font.Italic = 0
LabelRugV9.Font.Italic = 0
End Sub

Private Sub LabelRugV5_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


ActiveSheet.Cells(ActiveCell.Row, ActiveCell.Column) = 0.00152
End Sub

Private Sub LabelRugV5_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single
, ByVal Y As Single)
LabelRugV1.Font.Italic = 0
LabelRugV2.Font.Italic = 0
FormRugos - 2

LabelRugV3.Font.Italic = 0
LabelRugV4.Font.Italic = 0
LabelRugV5.Font.Italic = 1
LabelRugV6.Font.Italic = 0
LabelRugV7.Font.Italic = 0
LabelRugV8.Font.Italic = 0
LabelRugV9.Font.Italic = 0
End Sub

Private Sub LabelRugV6_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


ActiveSheet.Cells(ActiveCell.Row, ActiveCell.Column) = 0
End Sub

Private Sub LabelRugV6_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single
, ByVal Y As Single)
LabelRugV1.Font.Italic = 0
LabelRugV2.Font.Italic = 0
LabelRugV3.Font.Italic = 0
LabelRugV4.Font.Italic = 0
LabelRugV5.Font.Italic = 0
LabelRugV6.Font.Italic = 1
LabelRugV7.Font.Italic = 0
LabelRugV8.Font.Italic = 0
LabelRugV9.Font.Italic = 0
End Sub

Private Sub LabelRugV7_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


ActiveSheet.Cells(ActiveCell.Row, ActiveCell.Column) = 3.05
End Sub

Private Sub LabelRugV7_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single
, ByVal Y As Single)
LabelRugV1.Font.Italic = 0
LabelRugV2.Font.Italic = 0
LabelRugV3.Font.Italic = 0
LabelRugV4.Font.Italic = 0
LabelRugV5.Font.Italic = 0
LabelRugV6.Font.Italic = 0
LabelRugV7.Font.Italic = 1
LabelRugV8.Font.Italic = 0
LabelRugV9.Font.Italic = 0
End Sub

Private Sub LabelRugV8_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


ActiveSheet.Cells(ActiveCell.Row, ActiveCell.Column) = 9.14
End Sub

Private Sub LabelRugV8_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single
, ByVal Y As Single)
LabelRugV1.Font.Italic = 0
LabelRugV2.Font.Italic = 0
LabelRugV3.Font.Italic = 0
LabelRugV4.Font.Italic = 0
LabelRugV5.Font.Italic = 0
LabelRugV6.Font.Italic = 0
LabelRugV7.Font.Italic = 0
LabelRugV8.Font.Italic = 1
LabelRugV9.Font.Italic = 0
End Sub

Private Sub LabelRugV9_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


ActiveSheet.Cells(ActiveCell.Row, ActiveCell.Column) = 0.914
End Sub

Private Sub LabelRugV9_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single
, ByVal Y As Single)
LabelRugV1.Font.Italic = 0
LabelRugV2.Font.Italic = 0
LabelRugV3.Font.Italic = 0
LabelRugV4.Font.Italic = 0
LabelRugV5.Font.Italic = 0
LabelRugV6.Font.Italic = 0
LabelRugV7.Font.Italic = 0
LabelRugV8.Font.Italic = 0
LabelRugV9.Font.Italic = 1
End Sub
FormRugos - 3

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)


ActiveCell.Offset(1).Select
End Sub

Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single,
ByVal Y As Single)

If Button = 0 Then
LabelRugV1.Font.Italic = 0
LabelRugV2.Font.Italic = 0
LabelRugV3.Font.Italic = 0
LabelRugV4.Font.Italic = 0
LabelRugV5.Font.Italic = 0
LabelRugV6.Font.Italic = 0
LabelRugV7.Font.Italic = 0
LabelRugV8.Font.Italic = 0
LabelRugV9.Font.Italic = 0
End If

End Sub
FormAccMod - 1

Sub FormAccGen()

FormAcc.ComboBoxStream.Clear

For Fil = 10 To 2010


If ActiveSheet.Cells(Fil, 1) <> "" Then FormAcc.ComboBoxStream.AddItem ActiveSheet.Cells(Fil, 1
)
Next Fil

FormAcc.ComboBoxStream.Value = ActiveSheet.Cells(ActiveCell.Row, 1)

Call UpDate(ActiveCell.Row)
FormAcc.Show

End Sub

Sub FormAccByOtherGen()

FormAccByOther.ComboBoxStream.Clear

For Fil = 10 To 2000


If ActiveSheet.Cells(Fil, 1) <> "" Then FormAccByOther.ComboBoxStream.AddItem ActiveSheet.Cells
(Fil, 1)
Next Fil

FormAccByOther.ComboBoxStream.Value = ActiveSheet.Cells(ActiveCell.Row, 1)

FormAccByOther.Show

End Sub

Sub UpDate(fAcc)

SNAcc = "PDropAcc" 'Sheets(2).Name

'Codos 90
'FormAcc.TextBoxCodo90_1.ControlSource = Worksheets("PDropAcc").Range(.Cells(fAcc, 2))
FormAcc.TextBoxCodo90_1.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 2) + format(fAcc)
FormAcc.TextBoxCodo90_2.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 3) + format(fAcc)
FormAcc.TextBoxCodo90_3.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 4) + format(fAcc)
FormAcc.TextBoxCodo90_4.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 5) + format(fAcc)
FormAcc.TextBoxCodo90_5.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 6) + format(fAcc)
FormAcc.TextBoxCodo90_6.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 7) + format(fAcc)
FormAcc.TextBoxCodo90_7.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 8) + format(fAcc)
FormAcc.TextBoxCodo90_8.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 9) + format(fAcc)
'Codos 45
FormAcc.TextBoxCodo45_1.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 10) + format(fAcc)
FormAcc.TextBoxCodo45_2.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 11) + format(fAcc)
FormAcc.TextBoxCodo45_3.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 12) + format(fAcc)
FormAcc.TextBoxCodo45_4.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 13) + format(fAcc)
'Codos 180
FormAcc.TextBoxCodo180_1.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 14) + format(fAcc)
FormAcc.TextBoxCodo180_2.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 15) + format(fAcc)
FormAcc.TextBoxCodo180_3.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 16) + format(fAcc)
'Tees
FormAcc.TextBoxTee_1.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 17) + format(fAcc)
FormAcc.TextBoxTee_2.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 18) + format(fAcc)
FormAcc.TextBoxTee_3.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 19) + format(fAcc)
FormAcc.TextBoxTee_4.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 20) + format(fAcc)
FormAcc.TextBoxTee_5.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 21) + format(fAcc)
FormAcc.TextBoxTee_6.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 22) + format(fAcc)
FormAcc.TextBoxTee_7.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 23) + format(fAcc)
'Valvulas
FormAcc.TextBoxValve_1.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 24) + format(fAcc)
FormAcc.TextBoxValve_2.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 25) + format(fAcc)
FormAcc.TextBoxValve_3.ControlSource = "'" + SNAcc + "'!" + Chr(64 + 26) + format(fAcc)
FormAcc.TextBoxValve_4.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 1) + format(fAcc)
FormAcc.TextBoxValve_5.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 2) + format(fAcc)
FormAcc.TextBoxValve_6.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 3) + format(fAcc)
FormAcc.TextBoxValve_7.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 4) + format(fAcc)
FormAcc.TextBoxValve_8.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 5) + format(fAcc)
FormAcc.TextBoxValve_9.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 6) + format(fAcc)
FormAcc.TextBoxValve_10.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 7) + format(fAcc)
'Varios
FormAcc.TextBoxVarios_1.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 8) + format(fAcc)
FormAcc.TextBoxVarios_2.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 9) + format(fAcc)
FormAccMod - 2

FormAcc.TextBoxVarios_3.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 10) + format(fAcc)


FormAcc.TextBoxVarios_4.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 11) + format(fAcc)
FormAcc.TextBoxVarios_5.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 12) + format(fAcc)
FormAcc.TextBoxVarios_6.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 13) + format(fAcc)
FormAcc.TextBoxVarios_7.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 14) + format(fAcc)
'Adopt
FormAcc.CheckBoxK.ControlSource = "'" + SNAcc + "'!A" + Chr(64 + 17) + format(fAcc)
FormAcc.TextBoxSumK.Value = Round(Sheets(SNAcc).Cells(fAcc, 44), 2)
FormAcc.TextBoxLeq.Value = Round(Sheets(SNAcc).Cells(fAcc, 45), 1)

End Sub

Sub Reset(fAcc)

SNAcc = "PDropAcc" 'Sheets(2).Name

RtaReset = MsgBox("This action will DELETE charged accesories. Do you wish to continue?", vbYesNo
, "Delete Accesories")
If RtaReset = 6 Then
For C = 2 To 40
Sheets(SNAcc).Cells(fAcc, C) = ""
Next
End If

End Sub
FormChokeMod - 1

Sub FormChokeGen()

w = ActiveSheet.Cells(ActiveCell.Row, 3)
Pc = (ActiveSheet.Cells(ActiveCell.Row, 4) + 1.013) * 100000
Tc = ActiveSheet.Cells(ActiveCell.Row, 5) + 273
d = ActiveSheet.Cells(ActiveCell.Row, 6)
visc = ActiveSheet.Cells(ActiveCell.Row, 7) / 1000
Cp = ActiveSheet.Cells(ActiveCell.Row, 8)
U = ActiveSheet.Cells(ActiveCell.Row, 9)
Tamb = ActiveSheet.Cells(ActiveCell.Row, 10) + 273
If ActiveSheet.Cells(8, 11) = "[in]" Then
Dint = ActiveSheet.Cells(ActiveCell.Row, 11) * 0.0254
Else
Dint = ActiveSheet.Cells(ActiveCell.Row, 11) / 1000
End If
e = ActiveSheet.Cells(ActiveCell.Row, 12) / 1000
L = ActiveSheet.Cells(ActiveCell.Row, 13)
s = ActiveSheet.Cells(ActiveCell.Row, 14) * (3.1416 / 180)
SumK = ActiveSheet.Cells(ActiveCell.Row, 15)

R = 8314
M = d * R * Tc / Pc
Gw = (w / 3600) / (3.1416 * Dint ^ 2 / 4)
f = fanning(Gw * Dint / visc, e / Dint)
Lacc = Sgn(L) * SumK / (4 * f / Dint)
Ltot = L + Lacc

evol = -(1 * FormChoke.OptionActual.Value + 2 * FormChoke.OptionIsot.Value + 3 * FormChoke.Option


Adiab.Value)
If U = "Isothrm" And evol = 1 Then evol = 2
If U = 0 And evol = 1 Then evol = 3

Call Chwmax(Pc, Tc, M, visc, Cp, Dint, e, Ltot, evol)


Call ChIDmin(w, Pc, Tc, M, visc, Cp, e, Ltot, evol)
Call ChLPT(Gw, Pc, Tc, M, f, Cp, U, Tamb, Dint, s, evol)

End Sub

Sub ChLPT(Gw, P, T, M, f, Cp, U, Tamb, Dint, s, evol)

g = 9.8
R = 8314
L = 0

Select Case evol

Case Is = 1 'actual
If U = "Isothrm" Then
Do
d = P * M / (R * T)
v = Gw / d
vc = (P / d) ^ 0.5
If L > 10000 Then dL = 1 Else dL = 0.1
If L > 1000000 Then L = "high": Exit Do
dPdL = -(d * g * Sin(s) + d * v ^ 2 / 2 * (4 * f / Dint)) / (1 - d * v ^ 2 / P)
dTdL = 0
L = L + dL
P = P + dPdL * dL
T = T + dTdL * dL
Loop Until v >= vc
Else
Do
d = P * M / (R * T)
v = Gw / d
vc = (P / d) ^ 0.5
If L > 10000 Then dL = 1 Else dL = 0.1
If L > 1000000 Then L = "high": Exit Do
dPdL = (-Cp * (d * g * Sin(s) + d * v ^ 2 / 2 * (4 * f / Dint)) + 4 * U * v / Dint * (1 - T
amb / T)) / (Cp * (1 - d * v ^ 2 / P) + v ^ 2 / T)
dTdL = -(g * Sin(s) + v ^ 2 / 2 * (4 * f / Dint) + (1 - d * v ^ 2 / P) * (4 * U / (d * v *
Dint)) * (T - Tamb)) / (Cp * (1 - d * v ^ 2 / P) + v ^ 2 / T)
L = L + dL
P = P + dPdL * dL
T = T + dTdL * dL
Loop Until v >= vc
FormChokeMod - 2

End If

Case Is = 2 'isotermico
k = 1
If s = 0 Then
d = P * M / (R * T)
rc = (Gw ^ 2 / (k * d * P)) ^ (k / (k + 1))
L = (Log(rc ^ (2 / k)) + P / (Gw ^ 2 / (2 * d)) * (1 - rc ^ (1 + 1 / k)) / (1 + 1 / k)) / (4
* f / Dint)
P = rc * P
T = T * rc ^ (1 - 1 / k)
Else
Do
d = P * M / (R * T)
v = Gw / d
vc = (P / d) ^ 0.5
If L > 10000 Then dL = 1 Else dL = 0.1
If L > 1000000 Then L = "high": Exit Do
dPdL = -(d * g * Sin(s) + d * v ^ 2 / 2 * (4 * f / Dint)) / (1 - d * v ^ 2 / P)
dTdL = 0
L = L + dL
P = P + dPdL * dL
T = T + dTdL * dL
Loop Until v >= vc
End If

Case Is = 3 'adiabatico
k = Cp / (Cp - R / M)
If s = 0 Then
d = P * M / (R * T)
rc = (Gw ^ 2 / (k * d * P)) ^ (k / (k + 1))
L = (Log(rc ^ (2 / k)) + P / (Gw ^ 2 / (2 * d)) * (1 - rc ^ (1 + 1 / k)) / (1 + 1 / k)) / (4
* f / Dint)
P = rc * P
T = T * rc ^ (1 - 1 / k)
Else
Do
d = P * M / (R * T)
v = Gw / d
vc = (P / d) ^ 0.5
If L > 10000 Then dL = 1 Else dL = 0.1
If L > 1000000 Then L = "high": Exit Do
dPdL = (-Cp * (d * g * Sin(s) + d * v ^ 2 / 2 * (4 * f / Dint))) / (Cp * (1 - d * v ^ 2 / P)
+ v ^ 2 / T)
dTdL = -(g * Sin(s) + v ^ 2 / 2 * (4 * f / Dint)) / (Cp * (1 - d * v ^ 2 / P) + v ^ 2 / T)
L = L + dL
P = P + dPdL * dL
T = T + dTdL * dL
Loop Until v >= vc
End If

End Select

If L = "high" Then
FormChoke.TextBoxLength.Value = ">10E+6"
FormChoke.TextBoxPress.Value = "? " + format(Round(P / 100000 - 1.013, 2))
FormChoke.TextBoxTemp.Value = "? " + format(Round(T - 273, 1))
Else
FormChoke.TextBoxLength.Value = Round(L, 0)
FormChoke.TextBoxPress.Value = Round(P / 100000 - 1.013, 2)
FormChoke.TextBoxTemp.Value = Round(T - 273, 1)
End If

End Sub

Sub Chwmax(P, T, M, visc, Cp, Dint, e, Ltot, evol)

R = 8314
d = P * M / (R * T)
If Ltot < 0 Then
FormChoke.TextBoxFlow.Value = "L<0"
Else
Select Case evol
Case Is = 1 'actual
Gwmax = ""
Case Is = 2 'isotermico + Dz=0
FormChokeMod - 3

k = 1
rc = 1
For i = 1 To 9
For j = 1 To 10
Gwmax = ((k * d * P) * rc ^ (1 + 1 / k)) ^ 0.5
f1 = fanning(Gwmax * Dint / visc, e / Dint)
M1 = Log(rc ^ (2 / k)) + P / (Gwmax ^ 2 / (2 * d)) * (1 - rc ^ (1 + 1 / k)) / (1 + 1 / k)
M2 = 4 * f1 * Ltot / Dint
If M1 < M2 Then rc = rc - 10 ^ (-i) Else Exit For
Next j
rc = rc + 10 ^ (-i)
Next i
Case Is = 3 'adiabatico + Dz=0
k = Cp / (Cp - R / M)
rc = 1
For i = 1 To 9
For j = 1 To 10
Gwmax = ((k * d * P) * rc ^ (1 + 1 / k)) ^ 0.5
f1 = fanning(Gwmax * Dint / visc, e / Dint)
M1 = Log(rc ^ (2 / k)) + P / (Gwmax ^ 2 / (2 * d)) * (1 - rc ^ (1 + 1 / k)) / (1 + 1 / k)
M2 = 4 * f1 * Ltot / Dint
If M1 < M2 Then rc = rc - 10 ^ (-i) Else Exit For
Next j
rc = rc + 10 ^ (-i)
Next i
End Select
If Gwmax = "" Then
FormChoke.TextBoxFlow.Value = "?"
Else
wmax = Gwmax * (3.1416 * Dint ^ 2 / 4) * 3600
FormChoke.TextBoxFlow.Value = Round(wmax, 0)
End If
End If

End Sub

Sub ChIDmin(w, P, T, M, visc, Cp, e, Ltot, evol)

R = 8314
d = P * M / (R * T)

If Ltot < 0 Then


FormChoke.TextBoxDiam.Value = "L<0"
Else
Select Case evol
Case Is = 1 'actual
IDmin = ""
Case Is = 2 'isotermico + Dz=0
k = 1
IDmin = 1
For i = 1 To 7
For j = 1 To 10
Gwd = (w / 3600) / (3.1416 * IDmin ^ 2 / 4)
rc = (Gwd ^ 2 / (k * d * P)) ^ (k / (k + 1))
f1 = fanning(Gwd * IDmin / visc, e / IDmin)
M1 = Log(rc ^ (2 / k)) + P / (Gwd ^ 2 / (2 * d)) * (1 - rc ^ (1 + 1 / k)) / (1 + 1 / k)
M2 = 4 * f1 * Ltot / IDmin
If M1 > M2 Then IDmin = IDmin - 10 ^ (-i) Else Exit For
Next j
IDmin = IDmin + 10 ^ (-i)
Next i
Case Is = 3 'adiabatico + Dz=0
k = Cp / (Cp - R / M)
IDmin = 1
For i = 1 To 7
For j = 1 To 10
Gwd = (w / 3600) / (3.1416 * IDmin ^ 2 / 4)
rc = (Gwd ^ 2 / (k * d * P)) ^ (k / (k + 1))
f1 = fanning(Gwd * IDmin / visc, e / IDmin)
M1 = Log(rc ^ (2 / k)) + P / (Gwd ^ 2 / (2 * d)) * (1 - rc ^ (1 + 1 / k)) / (1 + 1 / k)
M2 = 4 * f1 * Ltot / IDmin
If M1 > M2 Then IDmin = IDmin - 10 ^ (-i) Else Exit For
Next j
IDmin = IDmin + 10 ^ (-i)
Next i
End Select
FormChokeMod - 4

If IDmin = "" Then


FormChoke.TextBoxDiam.Value = "?"
Else
FormChoke.TextBoxDiam.Value = Round(IDmin * 1000, 1)
End If
End If

End Sub
FormDiamMod - 1

Sub FormDiamGen()

Call NPSGen
Call ODGen
FormDiam.Show

End Sub

Sub NPSGen()

SNDiam = "DiamData" 'Sheets(5).Name

Dim PipeData(1 To 31, 1 To 21)


For i = 1 To 31
For j = 1 To 21
PipeData(i, j) = Sheets(SNDiam).Cells(i + 2, j)
Next j
Next i

PrevNPS = FormDiam.ComboBoxNPS.Value
FormDiam.ComboBoxNPS.Clear

For i = 2 To 31
If FormDiam.CheckBoxNPS.Value Then
FormDiam.ComboBoxNPS.AddItem PipeData(i, 1)
Else
If PipeData(i, 21) <> "" Then FormDiam.ComboBoxNPS.AddItem PipeData(i, 1)
End If
Next i

FormDiam.ComboBoxNPS.Value = PrevNPS
If FormDiam.ComboBoxNPS.MatchFound = 0 Then FormDiam.ComboBoxNPS.Value = ""

End Sub

Sub SCHGen()

SNDiam = "DiamData" 'Sheets(5).Name

Dim PipeData(1 To 31, 1 To 21)


For i = 1 To 31
For j = 1 To 21
PipeData(i, j) = Sheets(SNDiam).Cells(i + 2, j)
Next j
Next i

PrevSCH = FormDiam.ComboBoxSCH.Value
FormDiam.ComboBoxSCH.Clear

For i = 2 To 31
If format(PipeData(i, 1)) = FormDiam.ComboBoxNPS.Value Then
For j = 3 To 20
SCHP = PipeData(i, j)
If SCHP <> "" Then FormDiam.ComboBoxSCH.AddItem PipeData(1, j)
Next j
End If
Next i

FormDiam.ComboBoxSCH.Value = PrevSCH
If FormDiam.ComboBoxSCH.MatchFound = 0 Then
If FormDiam.ComboBoxNPS.Value <> "" Then FormDiam.ComboBoxSCH.Value = "STD" Else FormDiam.Combo
BoxSCH.Value = ""
End If

End Sub

Sub IDNCalc()

SNDiam = "DiamData" 'Sheets(5).Name

Dim PipeData(1 To 31, 1 To 21)


For i = 1 To 31
For j = 1 To 21
PipeData(i, j) = Sheets(SNDiam).Cells(i + 2, j)
Next j
Next i
FormDiamMod - 2

For i = 2 To 31
If format(PipeData(i, 1)) = FormDiam.ComboBoxNPS.Value Then
OD = PipeData(i, 2)
For j = 3 To 20
If format(PipeData(1, j)) = FormDiam.ComboBoxSCH.Value Then esp = PipeData(i, j)
Next j
End If
Next i

If esp <> "" Then


IDcol = ActiveCell.Column
IDN = OD - 2 * esp
If ActiveSheet.Cells(8, IDcol) = "[in]" Then FormDiam.TextBoxIDN.Value = CStr(Round(IDN / 25.4,
3)) Else FormDiam.TextBoxIDN.Value = CStr(Round(IDN, 2))
Else
FormDiam.TextBoxIDN.Value = ""
End If

End Sub

Sub ODGen()

SNDiam = "DiamData" 'Sheets(5).Name

Dim TubeData(1 To 12, 1 To 20)


For i = 1 To 12
For j = 1 To 20
TubeData(i, j) = Sheets(SNDiam).Cells(i + 37, j)
Next j
Next i

PrevOD = FormDiam.ComboBoxOD.Value
FormDiam.ComboBoxOD.Clear

For i = 2 To 12
FormDiam.ComboBoxOD.AddItem TubeData(i, 1)
Next i

FormDiam.ComboBoxOD.Value = PrevOD
If FormDiam.ComboBoxOD.MatchFound = 0 Then FormDiam.ComboBoxOD.Value = ""

End Sub

Sub BWGGen()

SNDiam = "DiamData" 'Sheets(5).Name

Dim TubeData(1 To 12, 1 To 20)


For i = 1 To 12
For j = 1 To 20
TubeData(i, j) = Sheets(SNDiam).Cells(i + 37, j)
Next j
Next i

PrevBWG = FormDiam.ComboBoxBWG.Value
FormDiam.ComboBoxBWG.Clear

For i = 2 To 12
If format(TubeData(i, 1)) = FormDiam.ComboBoxOD.Value Then
For j = 3 To 20
BWGP = TubeData(i, j)
If BWGP <> "" Then FormDiam.ComboBoxBWG.AddItem TubeData(1, j)
Next j
End If
Next i

FormDiam.ComboBoxBWG.Value = PrevBWG
If FormDiam.ComboBoxBWG.MatchFound = 0 Then FormDiam.ComboBoxBWG.Value = ""

End Sub

Sub IDOCalc()

SNDiam = "DiamData" 'Sheets(5).Name


FormDiamMod - 3

Dim TubeData(1 To 12, 1 To 20)


For i = 1 To 12
For j = 1 To 20
TubeData(i, j) = Sheets(SNDiam).Cells(i + 37, j)
Next j
Next i

For i = 2 To 12
If format(TubeData(i, 1)) = FormDiam.ComboBoxOD.Value Then
OD = TubeData(i, 2)
For j = 3 To 20
If format(TubeData(1, j)) = FormDiam.ComboBoxBWG.Value Then esp = TubeData(i, j)
Next j
End If
Next i

If esp <> "" Then


IDcol = ActiveCell.Column
IDO = OD - 2 * esp
If ActiveSheet.Cells(8, IDcol) = "[in]" Then FormDiam.TextBoxIDO.Value = CStr(Round(IDO / 25.4,
3)) Else FormDiam.TextBoxIDO.Value = CStr(Round(IDO, 2))
Else
FormDiam.TextBoxIDO.Value = ""
End If

End Sub
Friction - 1

Function fanning(Re, eD)

a = (2.457 * Log((7 / Re) ^ 0.9 + 0.27 * eD)) ^ 16


B = (37530 / Re) ^ 16
fanning = ((16 / Re) ^ 12 + (256 / (a + B)) ^ 1.5) ^ (1 / 12)

End Function
Function Rugosidad(material)

'Rugosidad (mm)

Select Case material


Case Is = "Cast Iron": Rugosidad = 0.259
Case Is = "Galvan Iron": Rugosidad = 0.152
Case Is = "Comm Steel": Rugosidad = 0.0457
Case Is = "Drawn Tubing": Rugosidad = 0.00152
Case Is = "Smooth": Rugosidad = 0
'concrete: 0.305 - 3.05
Case Else: Rugosidad = 0.05
End Select

End Function
PressDrop - 1

Function PTD(Xm, w, P0, T0, d0, f, Cp, U, Tamb, Dint, L, Slp, SumK)

'Xm: Fraccion vapor masica


'w: Caudal masico (kg/h)
'P0: presion inicial (barg)
'T0: Temperatura inicial (ºC)
'd0: densidad inicial (kg/m3)
'f: factor de friccion
'Cp: Capacidad calorifica (J/KgK)
'U: Coeficiente global (W/m2)
'Tamb: Temperatura ambiente (ºC)
'Dint: Diametro interno (mm)
'L: Diferencia de Longitud(m)
'Slp: Pendiente (grados)
'SumK: Sumatoria de K accesorios
'Gw: Caudal de flujo masico (kg/m2s)
'Ltot: Diferencia de Longitud incluye K (m)
'N: numero de incrementos

'If (w*Press0*dens0*Dint*f*k)<=0 then Err=1

Dim PTDm(1 To 3)
g = 9.81
P = (P0 + 1.013) * 100000
T = T0 + 273
d = d0
R = 8314
M = d * R * T / P
k = Cp / (Cp - R / M)
Tamb = Tamb + 273
Dint = Dint / 1000
Gw = (w / 3600) / (3.1416 * Dint ^ 2 / 4)
Lacc = Sgn(L) * SumK / (4 * f / Dint)
Ltot = L + Lacc
Ztot = L * Sin(Slp * 3.1416 / 180)

Select Case Xm

Case 0 To 0.001 'INCOMPRESIBLE


v = Gw / d
dP = -(d * g * Ztot + d * v ^ 2 / 2 * (4 * f * Ltot / Dint))
Select Case U
Case Is = "Isothrm"
dT = 0
Case Is = 0
dT = -(g * Sin(Slp * 3.1416 / 180) + v ^ 2 / 2 * (4 * f / Dint)) * L / Cp
Case Else
AB = (Gw * Dint / (4 * U)) * (g * Sin(Slp * 3.1416 / 180) + v ^ 2 / 2 * (4 * f / Dint))
dT = -(T - Tamb + AB) * (1 - Exp(-(4 * U * L) / (Gw * Dint * Cp)))
End Select
P = P + dP
T = T + dT

Case 0.001 To 0.999


PTD = "MIX FLOW"

Case 0.999 To 1 'COMPRESIBLE


int1 = 2000: int2 = 1000000
If L < 0 Then Li = -Ltot: n1 = int2: n2 = int1 Else Li = 0: n1 = int1: n2 = int2
n = Round(1 + 2 / (1 / n1 + 1 / n2)) '1999
i = 0
If U = "Isothrm" Then
Do
i = i + 1
dL = Ltot * (1 / n1 + (1 / n2 - 1 / n1) * ((i - 1) / (n - 1)))
Li = Li + dL
If Li > L Then s = 0 Else s = Slp * (3.1416 / 180)

d = P * M / (R * T)
v = Gw / d
vc = (P / d) ^ 0.5
If v >= vc Then Pc = "CHOKE": Exit Do
dP1dL = -(d * g * Sin(s) + d * v ^ 2 / 2 * (4 * f / Dint)) / (1 - d * v ^ 2 / P)
dT1dL = 0
PressDrop - 2

P1 = P + dP1dL * dL
T1 = T + dT1dL * dL

d1 = P1 * M / (R * T1)
v1 = Gw / d1
vc = (P1 / d1) ^ 0.5
If v1 >= vc Then Pc = "CHOKE": Exit Do
dP2dL = -(d1 * g * Sin(s) + d1 * v1 ^ 2 / 2 * (4 * f / Dint)) / (1 - d1 * v1 ^ 2 / P1)
dT2dL = 0
P2 = P + dP2dL * dL
T2 = T + dT2dL * dL

P = (P1 + P2) / 2
T = (T1 + T2) / 2

Loop Until i = n
Else
Do
i = i + 1
dL = Ltot * (1 / n1 + (1 / n2 - 1 / n1) * ((i - 1) / (n - 1)))
Li = Li + dL
If Li > L Then s = 0 Else s = Slp * (3.1416 / 180)

d = P * M / (R * T)
v = Gw / d
vc = (k * P / d) ^ 0.5
If v >= vc Then Pc = "CHOKE": Exit Do
dP1dL = (-Cp * (d * g * Sin(s) + d * v ^ 2 / 2 * (4 * f / Dint)) + 4 * U * v / Dint * (1
- Tamb / T)) / (Cp * (1 - d * v ^ 2 / P) + v ^ 2 / T)
dT1dL = -(g * Sin(s) + v ^ 2 / 2 * (4 * f / Dint) + (1 - d * v ^ 2 / P) * (4 * U / (d * v
* Dint)) * (T - Tamb)) / (Cp * (1 - d * v ^ 2 / P) + v ^ 2 / T)
P1 = P + dP1dL * dL
T1 = T + dT1dL * dL

d1 = P1 * M / (R * T1)
v1 = Gw / d1
vc = (k * P1 / d1) ^ 0.5
If v1 >= vc Then Pc = "CHOKE": Exit Do
dP2dL = (-Cp * (d1 * g * Sin(s) + d1 * v1 ^ 2 / 2 * (4 * f / Dint)) + 4 * U * v1 / Dint *
(1 - Tamb / T1)) / (Cp * (1 - d1 * v1 ^ 2 / P1) + v1 ^ 2 / T1)
dT2dL = -(g * Sin(s) + v1 ^ 2 / 2 * (4 * f / Dint) + (1 - d1 * v1 ^ 2 / P1) * (4 * U / (d
1 * v1 * Dint)) * (T1 - Tamb)) / (Cp * (1 - d1 * v1 ^ 2 / P1) + v1 ^ 2 / T1)
P2 = P + dP2dL * dL
T2 = T + dT2dL * dL

P = (P1 + P2) / 2
T = (T1 + T2) / 2

Loop Until i = n
End If

Case Else
PTD = "ERROR"

End Select

PTDm(1) = P / 100000 - 1.013


PTDm(2) = T - 273
PTDm(3) = d
PTD = PTDm
If Pc = "CHOKE" Then PTD = "CHOKE"
If PTDm(1) < -1.013 Then PTD = "EXHAUST"

End Function

You might also like