Anda di halaman 1dari 57

Appendix D

Visual Basic Code Additions

D1: 2-D Vertical Piping Span Calculation Module Sub-Set Code D2: Piping Span Choose Form D2a: Piping Span Choose Form Code D3: Valve Connection Form D3a: Valve Connection Form Code D4: 2-D Vertical Analysis Form D4a: 2-D Analysis Form Code D5: Bookmark Code D6: Copy Image Code D7: Call Macro Computer Code

179

2-D Vertical Piping Span Calculation Module Sub-Set

Private Sub CalculateM_Vertical() Dim C1 As Single ' Compression values on vertical pipe Dim C2 As Single Dim C3 As Single Dim fi As Single ' Used to find start of elbow on pipe spans Dim fo As Single Dim Vefi As Single ' used to get shear value before elbow Dim Vefo As Single ' gets shear after elbow Dim Mefi As Single ' Moment before elbow starts Dim Mefo As Single ' Moment after before elbow starts ' In this analysis section four stresses will be calculated: '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ' Sbend = M/Znom 'M is the moment for each case: M1, M2, M3 etc. ' Slong = Pressure*(Dod-2*t)/(4*t) ' ShoopVert = Pressure*(Dod-2*t)/(2*t) ' SComp = 4*C/(Pi*(Dod^2-(Dod-2*t)^2)) , C is the compression pressure '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ' In all cases, t is Tmin, and will be found through summation of stresses ' all involving a root solver, or by simple algebra. '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ fi = L1 - SIFRadius / 12 ' used for SIF calculations fo = L3 - SIFRadius / 12 WElbow_Bottom = 2 * (L1 - fi) 'get the length of the elbow for calculations WElbow_Top = 2 * (L3 - fo) 'get the length of the elbow for calculations ' Solve for the reaction forces at the ends of all pipe spans R2 = (WPLtot * L1 * L1 / 2 + F1 * (DistF1) + WPLtot * L2 * L1 _ + F2 * L1 + L1 * (((2 * WElbow_Top) + (2 * WElbow_Bottom)) * WPLtot) _ + (WPLtot * L3) * (L3 + L3 / 2) + F3 * (L1 + L3 - DistF3)) / (L1 + L3) R2 = -R2 R1 = (R2 + F1 + F2 + F3 + (((2 * WElbow_Top) + (2 * WElbow_Bottom)) * WPLtot)) + (WPLtot * (L1 + L2 + L3)) ' Create the shear diagram, algebraically, not visually. V1 = R1 If F1 > 0 Then V2 = (-WPLtot * DistF1) + V1 V3 = V2 - F1 180

V4 = (-WPLtot * (L1 - DistF1)) + V3 Vefi = fi / WPLtot + V4 ' Used to get shear before the elbow calc. Else V2 = V1 - L1 * WPLtot V3 = V2 V4 = V3 Vefi = fi / WPLtot + V4 ' Used to get shear before the elbow calc. End If V5 = V4 - F2 - (((2 * WElbow_Top) + (2 * WElbow_Bottom)) * WPLtot) - (WPLtot * L2) Vefo = V5 - fo / WPLtot If F3 > 0 Then V6 = (-WPLtot * (L3 - DistF3)) + V5 V7 = V6 - F3 V8 = (-WPLtot * DistF3) + V7 Else V6 = V5 - L3 * WPLtot V7 = V6 V8 = V7 End If ' C1, C2 and C3 are compression values on the vertical span C1 = V5 If F2 > 0 Then C2 = (L2 - DistF2) * WPLtot + F2 + C1 Else C2 = L2 / 2 * WPLtot + F2 + C1 End If C3 = V4 ' Use for elbows and SIF of each Ibend = 1 Intrados = (4 * (SIFRadius / Dod) - 1) / (4 * (SIFRadius / Dod) - 2) Extrados = (4 * (SIFRadius / Dod) + 1) / (4 * (SIFRadius / Dod) + 2) If Intrados > Extrados Then Ibend = Intrados Else Ibend = Extrados ' Now will obtain the SIF of the elbows chosen by the user ' that will be used in later calculations. First SIF check is for bottom elbow. ' Second SIF is for the top elbow If frmInput.lblSpan1(6).Caption = " Standard Long Radius Bend" Then SIF1 = 1.5 * SIFRadius ElseIf frmInput.lblSpan1(6).Caption = " Short Radius Bend" Then SIF1 = 1 * SIFRadius ElseIf frmInput.lblSpan1(6).Caption = " 3D Bend" Then SIF1 = 3 * SIFRadius ElseIf frmInput.lblSpan1(6).Caption = " 5D Bend" Then SIF1 = 5 * SIFRadius ElseIf frmInput.lblSpan1(6).Caption = " Do Not Know" Then SIF1 = 1 * SIFRadius ' short radius bend is assumed 181

End If ' reset's the SIF so no corruption between either elbows is seen. If NPS > 0 Then SIFRadius = NPS Else SIFRadius = Dod ' Second elbow, top of vertical pipe span If frmInput.lblSpan1(7).Caption = " Standard Long Radius Bend" Then SIF2 = 1.5 * SIFRadius ElseIf frmInput.lblSpan1(7).Caption = " Short Radius Bend" Then SIF2 = 1 * SIFRadius ElseIf frmInput.lblSpan1(7).Caption = " 3D Bend" Then SIF2 = 3 * SIFRadius ElseIf frmInput.lblSpan1(7).Caption = " 5D Bend" Then SIF2 = 5 * SIFRadius ElseIf frmInput.lblSpan1(7).Caption = " Do Not Know" Then SIF2 = 1 * SIFRadius ' short radius bend is assumed End If ' SIF Value for valve one SIF_V1 = 1 'reset the SIF value for the valve If SIFV1 = "" Then ' if its blank then, no valve, so make SIF=1 SIF_V1 = 1 Else If SIFV1 = "Butt" Then SIF_V1 = 1 ElseIf SIFV1 = "DblWeld" Then SIF_V1 = 1.2 ElseIf SIFV1 = "FilletWeld" Then SIF_V1 = 2.1 ElseIf SIFV1 = "LapJoint" Then SIF_V1 = 1.6 ElseIf SIFV1 = "Threaded" Then SIF_V1 = 2.3 ElseIf SIFV1 = "DoNotKnow" Then SIF_V1 = 2.3 End If End If SIF_V2 = 1 'reset the SIF value for the valve If SIFV2 = "" Then ' if its blank then, no valve, so make SIF=1 SIF_V2 = 1 Else If SIFV2 = "Butt" Then SIF_V2 = 1 ElseIf SIFV2 = "DblWeld" Then SIF_V2 = 1.2 ElseIf SIFV2 = "FilletWeld" Then SIF_V2 = 2.1 ElseIf SIFV2 = "LapJoint" Then 182

SIF_V2 = 1.6 ElseIf SIFV2 = "Threaded" Then SIF_V2 = 2.3 ElseIf SIFV2 = "DoNotKnow" Then SIF_V2 = 2.3 End If End If SIF_V3 = 1 'reset the SIF value for the valve If SIFV3 = "" Then ' if its blank then, no valve, so make SIF=1 SIF_V3 = 1 Else If SIFV3 = "Butt" Then SIF_V3 = 1 ElseIf SIFV3 = "DblWeld" Then SIF_V3 = 1.2 ElseIf SIFV3 = "FilletWeld" Then SIF_V3 = 2.1 ElseIf SIFV3 = "LapJoint" Then SIF_V3 = 1.6 ElseIf SIFV3 = "Threaded" Then SIF_V3 = 2.3 ElseIf SIFV3 = "DoNotKnow" Then SIF_V3 = 2.3 End If End If ' Clear all variables for preparation of possible printing Tmin1 = 0 Tmin6 = 0 Tmin2_1 = 0 Tmin2_2 = 0 Tmin3 = 0 Tmin3_1 = 0 Tmin3_2 = 0 Tmin4 = 0 Tmin44 = 0 Tmin4_1 = 0 Tmin4_2 = 0 Tmin5 = 0 Tmin5_1 = 0 Tmin5_2 = 0 TminV1 = 0 TminV2 = 0 Tminefo = 0 Tminefi = 0 Mefi = 0 Mefo = 0

183

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ' Check using If statements to see where max moment occurs, ' several individual cases are evaluated: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ' max moment occurs between left end of L1 and valve 1 If V1 >= 0 Then If V2 <= 0 Then XCross = V1 / WPLtot ' location where shear is zero on x-axis M1 = V1 * XCross / 2 If F1 = 0 And F3 = 0 Then If fi >= XCross Then ' these calcs get the moment right before elbow on L1 Mefi = Vefi / 2 * (fi - XCross) + M1 M2 = (V4 + Vefi) / 2 * (L1 - fi) + Mefi ElseIf XCross >= fi Then XCross = Vefi / WPLtot Mefi = (V1 + Vefi) / 2 * fi M1 = Vefi / 2 * XCross + Mefi M2 = V4 / 2 * (L3 - XCross) + M1 End If Mefo = (V5 + Vefo) / 2 * (L3 - fo) + M2 M1 = M1 * 12 Mefi = Mefi * 12 M2 = M2 * 12 Mefo = Mefo * 12 ' location 1 calculations, Maximum Moment Tmin1_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin1_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) ' Location 2, vertical pipe span. Constant moment occurs here (M2). TminV1 = CalculateBottomVert(SIF1, C3, M2, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M2, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M2, 0) ' top of pipe ElseIf F1 > 0 And F3 = 0 Then M2 = V2 / 2 * XCross + M1 Mefi = ((Vefi + V3) / 20 * (fi - DistF1) + M2) M3 = (Mefi + (V4 + Vefi) / 2 * (L1 - fi)) Mefo = (M3 + (V5 + Vefo) / 20 * (L3 - fo)) M1 = M1 * 12 M2 = M2 * 12 M3 = M3 * 12 Mefi = Mefi * 12 Mefo = Mefo * 12 ' location 1 calculations, Maximum Moment 184

Tmin1_1 = CalculateTmin(1, 0, M1, 0, 3, 0.1) Tmin1_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) ' location 2. Valve F1. Tmin2_1 = CalculateTmin(SIF_V1, 0, M2, 0, 3, 0.1) Tmin2_2 = SIFV1 * Pressure * Dod / (2 * SIF_V1 * Y * Pressure + 2 * (SE / Ibend)) ' Location 3, vertical pipe span. Constant moment occurs here (M3). TminV1 = CalculateBottomVert(SIF1, C3, M3, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M3, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M3, 0) ' top of pipe ElseIf F1 = 0 And F3 > 0 Then If fi >= XCross Then Mefi = (Vefi / 2 * (fi - XCross)) + M1 M2 = (V4 + Vefi) / 2 * (L1 - fi) + Mefi Mefo = ((V5 + Vefo) / 200 * (L3 - fi)) + M2 M3 = (Vefo + V5) / 200 * (DistF3 - (L3 - fo)) + Mefo ElseIf XCross > fi Then XCross = Vefi / WPLtot Mefi = (V1 + Vefi) / 2 * fi M1 = Vefi / 2 * XCross + Mefi M2 = V4 / 2 * (L3 - XCross) + M1 Mefo = (V5 + Vefo) / 2 * (L3 - fi) + M2 M3 = (Vefo + V5) / 2 * (DistF3 - (L3 - fo)) + Mefo End If M1 = M1 * 12 Mefi = Mefi * 12 M2 = M2 * 12 Mefo = Mefo * 12 M3 = M3 * 12 ' location 1 calculations, Maximum Moment Tmin1_1 = CalculateTmin(1, 0, M1, 0, 3, 0.1) Tmin1_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) ' Location 2, vertical pipe span. Constant moment occurs here (M3). TminV1 = CalculateBottomVert(SIF1, C3, M2, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M2, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M2, 0) ' top of pipe ' location 3. Valve F3. Tmin4_1 = CalculateTmin(SIF_V3, 0, M3, 0, 3, 0.1) Tmin4_2 = Pressure * SIF_V3 * Dod / (2 * SIF_V3 * Y * Pressure + 2 * (SE / Ibend)) ElseIf F1 > 0 And F3 > 0 Then M2 = V2 / 2 * XCross + M1 M3 = (V3 + V4) / 2 * (L1 - DistF1) + M2 Mefi = (-Vefi / 2 * (fi - XCross)) Mefo = (((V5 + Vefo) / 2 * (L3 - fo)) + M2) M1 = M1 * 12 M2 = M2 * 12 185

M3 = M3 * 12 Mefi = Mefi * 12 Mefo = Mefo * 12 ' location 1 calculations, Maximum Moment Tmin1_1 = CalculateTmin(1, 0, M1, 0, 3, 0.1) Tmin1_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) ' valve 1 location Tmin2_1 = CalculateTmin(SIF_V1, 0, M2, 0, 3, 0.1) Tmin2_2 = Pressure * SIF_V1 * Dod / (2 * SIF_V1 * Y * Pressure + 2 * (SE / Ibend)) ' Location 2, vertical pipe span. Constant moment occurs here (M3). TminV1 = CalculateBottomVert(SIF1, C3, M3, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M3, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M3, 0) ' top of pipe ' valve 3 location Tmin4_1 = CalculateTmin(SIF_V3, 0, M3, 0, 3, 0.1) Tmin4_2 = Pressure * SIF_V3 * Dod / (2 * SIF_V3 * Y * Pressure + 2 * (SE / Ibend)) End If ' Left side of L1 calcluations Tmin1 = CalculateTmin(1, 0, 0, V1, 0, 0.1) ' Location 6, end of pipe span L3. Tmin6 = CalculateTmin(1, 0, 0, V8, 0, 0.1) Tminefi = CalculateElbowfi(SIF1, Mefi, Vefi) Tminefo = CalculateElbowfo(SIF2, Mefo, Vefo) Tstr = LargestTmin(Tmin1, Tmin1_1, Tmin1_2, Tmin2_1, Tmin2_2, Tmin3_1, Tmin3_2, Tmin4_1, _ Tmin4_2, Tmin5_1, Tmin5_2, TminV1, TminV2, Tmin6, Tminefi, Tminefo, TminV3) If Tstr = Tmin1 Then frmOutput.TminCircle1(0).Visible = True ElseIf Tstr = Tmin1_1 Or Tstr = Tmin1_2 Then frmOutput.Section1(0).Visible = True ElseIf Tstr = Tmin2_1 Or Tstr = Tmin2_2 Then frmOutput.Section1(1).Visible = True ElseIf Tstr = Tmin4_1 Or Tstr = Tmin4_2 Then frmOutput.TminCircle1(2).Visible = True ElseIf Tstr = Tmin6 Then frmOutput.TminCircle1(3).Visible = True ElseIf Tstr = TminV1 Then frmOutput.VertSection(1).Visible = True ElseIf Tstr = TminV2 Or Tstr = TminV3 Then frmOutput.VertSection(0).Visible = True ElseIf Tstr = Tminefo Then frmOutput.Section1(2).Visible = True ElseIf Tstr = Tminefi Then frmOutput.Section1(1).Visible = True End If 186

End If End If If V2 >= 0 Then ' max moment occurs at F1 location If V3 <= 0 Then If F1 > 0 And F3 = 0 Then M1 = (V1 + V2) / 2 * (DistF1) Mefi = (V3 + Vefi) / 2 * (fi - DistF1) + M1 M2 = (Vefi + V4) / 2 * (L1 - fi) + Mefi Mefo = (V5 + Vefo) / 2 * (L3 - fo) + M2 M1 = M1 * 12 M2 = M2 * 12 Mefi = Mefi * 12 Mefo = Mefo * 12 ElseIf F1 > 0 And F3 > 0 Then M1 = (V1 + V2) / 2 * (DistF1) Mefi = (V3 + Vefi) / 2 * (fi - DistF1) + M1 M2 = (Vefi + V4) / 2 * (L1 - fi) + Mefi Mefo = (V5 + Vefo) / 2 * (L3 - fo) + M2 M3 = (Vefo + V6) / 2 * (DistF3 - (L3 - fo)) + Mefo M1 = M1 * 12 Mefi = Mefi * 12 M2 = M2 * 12 Mefo = Mefo * 12 M3 = M3 * 12 Else M1 = ((V2 - V1) / DistF1 * DistF1 ^ 2 / 2 + V1 * DistF1) M2 = (-(V4 - V3) / (L1 - DistF1) * (L1 ^ 2 / 2 - DistF1 ^ 2 / 2) - V3 * (L1 - DistF1)) + M1 M3 = (-(V6 - V5) / (L1 + DistF3 - L1) * ((L1 + DistF3) ^ 2 / 2 - L1 ^ 2 / 2) - V5 * (L1 + DistF3 - L1)) + M2 Mefi = (-(V4 + Vefi) / 2 * (L1 - fi) + M1) Mefo = (((V5 + Vefo) / 2 * (L3 - fo)) + M1) M1 = M1 * 12 M2 = M2 * 12 M3 = M3 * 12 Mefi = Mefi * 12 Mefo = Mefo * 12 End If ' location 2. Valve F1, maximum moment occurs here If F1 > 0 Then Tmin2_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * SIF_V1 * Dod / (2 * SIF_V1 * Y * Pressure + 2 * (SE / Ibend)) 187

Else Tmin2_1 = CalculateTmin(1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) End If ' Location 3, vertical pipe span. Constant moment occurs here (M2) TminV1 = CalculateBottomVert(SIF1, C3, M2, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M2, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M2, 0) ' top of pipe If F3 > 0 Then Tmin4_1 = CalculateTmin(SIF_V3, 0, M3, 0, 3, 0.1) Tmin4_2 = Pressure * SIF_V3 * Dod / (2 * SIF_V3 * Y * Pressure + 2 * (SE / Ibend)) Else Tmin4_1 = CalculateTmin(1, 0, M3, 0, 3, 0.1) Tmin4_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) End If ' Left side of L1 calcluations Tmin1 = CalculateTmin(1, 0, 0, V1, 0, 0.1) ' Location 6, end of pipe span L3. Tmin6 = CalculateTmin(1, 0, 0, V8, 0, 0.1) Tminefi = CalculateElbowfi(SIF1, Mefi, Vefi) Tminefo = CalculateElbowfo(SIF2, Mefo, Vefo) _ Tmin4_2, Tmin5_1, Tmin5_2, TminV1, TminV2, Tmin6, Tminefi, Tminefo, TminV3) If Tstr = Tmin1 Then frmOutput.TminCircle1(0).Visible = True ElseIf Tstr = Tmin2_1 Or Tstr = Tmin2_2 Then frmOutput.TminCircle1(1).Visible = True ElseIf Tstr = Tmin4_1 Or Tstr = Tmin4_2 Then frmOutput.TminCircle1(2).Visible = True ElseIf Tstr = Tmin6 Then frmOutput.TminCircle1(3).Visible = True ElseIf Tstr = TminV1 Then frmOutput.VertSection(1).Visible = True ElseIf Tstr = TminV2 Or Tstr = TminV3 Then frmOutput.VertSection(0).Visible = True ElseIf Tstr = Tminefo Then frmOutput.Section1(2).Visible = True ElseIf Tstr = Tminefi Then frmOutput.Section1(1).Visible = True End If End If End If Tstr = LargestTmin(Tmin1, Tmin1_1, Tmin1_2, Tmin2_1, Tmin2_2, Tmin3_1, Tmin3_2, Tmin4_1,

188

' max moment occurs between valve 1 and center vertical pipe If V3 >= 0 Then If V4 <= 0 Then XCross = V3 / WPLtot ' Find the x value where V=0 If F1 > 0 And F3 = 0 Then M1 = (V1 + V2) / 2 * DistF1 M2 = V3 / 2 * (XCross) + M1 If fi >= XCross Then ' these calcs get the moment right before elbow on L1 Mefi = M2 + ((Vefi / 2) * (fi - XCross)) M3 = Mefi + (V4 + Vefi) / 2 * (L1 - fi) Mefo = M3 + ((V5 + Vefo) / 20 * (L3 - fo)) ElseIf XCross >= fi Then Mefi = (-Vefi / 2 * (XCross - fi)) Mefi = (Mefi + M3) Mefo = ((V5 + Vefo) / 2 * (L3 - fo)) Mefo = (M3 + Mefo) End If M1 = M1 * 12 M2 = M2 * 12 Mefi = Mefi * 12 M3 = M3 * 12 Mefo = Mefo * 12 ' location 1 calculations, Valve F1 Tmin2_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * SIF_V1 * Dod / (2 * SIF_V1 * Y * Pressure + 2 * (SE / Ibend)) If (XCross + DistF1) >= fi Then Tmin3_1 = CalculateTmin(SIF1, 0, M2, 0, 3, 0.1) Tmin3_2 = Pressure * SIF1 * Dod / (2 * SIF1 * Y * Pressure + 2 * (SE / Ibend)) Else Tmin3_1 = CalculateTmin(1, 0, M2, 0, 3, 0.1) Tmin3_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) End If ' Location 3, vertical pipe span. Constant moment occurs here (M3) TminV1 = CalculateBottomVert(SIF1, C3, M3, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M3, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M3, 0) ' top of pipe ElseIf F1 > 0 And F3 > 0 Then If fi >= XCross Then ' these calcs get the moment right before elbow on L1 M1 = (V1 + V2) / 2 * DistF1 M2 = V3 / 2 * (XCross) + M1 Mefi = Vefi / 2 * (L1 - XCross) + M2 M3 = (Vefi + V4) / 2 * (L1 - fi) + Mefi ElseIf XCross >= fi Then M1 = (V1 + V2) / 2 * DistF1 Mefi = (Vefi + V3) / 2 * (XCross - DistF1) + M1 189

M2 = Vefi / 2 * XCross + Mefi M3 = V4 / 2 * (L1 - XCross) End If Mefo = (V5 + Vefo) / 2 * (L3 - fo) + M3 M4 = Mefo + ((V6 + Vefo) / 20 * (DistF3 - (L3 - fo))) M4 = Mefo - M4 M1 = M1 * 12 Mefi = Mefi * 12 M2 = M2 * 12 Mefo = Mefo * 12 M3 = M3 * 12 M4 = M4 * 12 ' location 2 calculations, Valve F1 Tmin2_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * SIF_V1 * Dod / (2 * SIF_V1 * Y * Pressure + 2 * (SE / Ibend)) If (XCross + DistF1) >= fi And (XCross + DistF1) <= L1 Then Tmin3_1 = CalculateTmin(SIF1, 0, M2, 0, 3, 0.1) Tmin3_2 = Pressure * SIF1 * Dod / (2 * SIF1 * Y * Pressure + 2 * (SE / Ibend)) Else Tmin3_1 = CalculateTmin(1, 0, M2, 0, 3, 0.1) Tmin3_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) End If ' Location 4, vertical pipe span. Constant moment occurs here (M3) TminV1 = CalculateBottomVert(SIF1, C3, M3, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M3, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M3, 0) ' top of pipe ' Location 5, Valve 3 location Tmin5_1 = CalculateTmin(SIF_V3, 0, M4, 0, 3, 0.1) Tmin5_2 = Pressure * SIF_V3 * Dod / (2 * SIF_V3 * Y * Pressure + 2 * (SE / Ibend)) Else M1 = ((V2 - V1) / L1 * (L1 ^ 2 / 2) + V1 * L1) M2 = (V3 / (XCross) * (XCross ^ 2 / 2) + V3 * (XCross)) + M1 M3 = (V4 / (L1 - (XCross)) * (L1 ^ 2 / 2 - (XCross) ^ 2 / 2)) + M2 M4 = ((V6 - V5) / (L3 - DistF3) * (DistF3 ^ 2 / 2) + V5 * (DistF3)) + M3 If fi >= XCross Then ' these calcs get the moment right before elbow on L1 Mefi = -(Vefi / 2 * (fi - XCross)) + M2 ElseIf XCross >= fi Then Mefi = -Vefi / 2 * (XCross - fi) + M2 End If Mefi = Mefi * 12 Mefo = ((V5 + Vefo) / 2 * (L3 - fo)) * 12 + M3 M1 = M1 * 12 M2 = M2 * 12 M3 = M3 * 12 M4 = M4 * 12 190

' location 2 calculations, Valve F1 Tmin2_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) If (XCross + DistF1) >= fi And (XCross + DistF1) <= L1 Then Tmin3_1 = CalculateTmin(SIF1, 0, M2, 0, 3, 0.1) Tmin3_2 = Pressure * SIF1 * Dod / (2 * SIF1 * Y * Pressure + 2 * (SE / Ibend)) Else Tmin3_1 = CalculateTmin(1, 0, M2, 0, 3, 0.1) Tmin3_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) End If ' Location 4, vertical pipe span. Constant moment occurs here (M3) TminV1 = CalculateBottomVert(SIF1, C3, M3, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M3, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M3, 0) ' top of pipe ' Location 5, Valve 3 location Tmin5_1 = CalculateTmin(SIF_V3, 0, M4, 0, 3, 0.1) Tmin5_2 = SIF_V3 * Pressure * Dod / (2 * SIF_V3 * Y * Pressure + 2 * (SE / Ibend)) End If ' Left side of L1 calcluations Tmin1 = CalculateTmin(1, 0, 0, V1, 0, 0.1) ' Location 6, end of pipe span L3. Tmin6 = CalculateTmin(1, 0, 0, V8, 0, 0.1) Tminefi = CalculateElbowfi(SIF1, Mefi, Vefi) Tminefo = CalculateElbowfo(SIF2, Mefo, Vefo) _ Tmin4_2, Tmin5_1, Tmin5_2, TminV1, TminV2, Tmin6, Tminefi, Tminefo, TminV3) If Tstr = Tmin1 Then frmOutput.TminCircle1(0).Visible = True ElseIf Tstr = Tmin2_1 Or Tstr = Tmin2_2 Then frmOutput.TminCircle1(1).Visible = True ElseIf Tstr = Tmin4_1 Or Tstr = Tmin4_2 Then frmOutput.TminCircle1(2).Visible = True ElseIf Tstr = Tmin6 Then frmOutput.TminCircle1(3).Visible = True ElseIf Tstr = TminV1 Then frmOutput.VertSection(1).Visible = True ElseIf Tstr = TminV2 Or Tstr = TminV3 Then frmOutput.VertSection(0).Visible = True ElseIf Tstr = Tminefo Then frmOutput.Section1(2).Visible = True ElseIf Tstr = Tminefi Then frmOutput.Section1(1).Visible = True End If End If 191 Tstr = LargestTmin(Tmin1, Tmin1_1, Tmin1_2, Tmin2_1, Tmin2_2, Tmin3_1, Tmin3_2, Tmin4_1,

End If If V4 >= 0 Then ' center span, max moment If V5 <= 0 Then If F1 = 0 And F3 = 0 Then M1 = V1 / 2 * L1 Mefi = -(V2 + Vefi) / 2 * (L1 - fi) + M1 Mefo = ((V5 + Vefo) / 2 * (L3 - fo)) + M1 M2 = 0 M3 = 0 M1 = M1 * 12 Mefi = Mefi * 12 Mefo = Mefo * 12 TminV1 = CalculateBottomVert(SIF1, C3, M1, 0) TminV2 = CalculateMiddleVert(SIF_V2, C2, M1, 0) TminV3 = CalculateTopVert(SIF2, C1, M1, 0) ' top of pipe ElseIf F1 > 0 And F3 = 0 Then M1 = (V1 + V2) / 2 * DistF1 M2 = (V3 + V4) / 2 * (L1 - DistF1) + M1 Mefi = -((V4 + Vefi) / 2 * (L1 - fi)) + M2 Mefo = ((V5 + Vefo) / 2 * (L3 - fo)) + M2 M1 = M1 * 12 M2 = M2 * 12 M3 = 0 Mefi = Mefi * 12 Mefo = Mefo * 12 ' Section 1 calculations, valve 1 find which stress: hoop or bending + long is larger Tmin2_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * SIF_V1 * Dod / (2 * SIF_V1 * Y * Pressure + 2 * (SE / Ibend)) TminV1 = CalculateBottomVert(SIF1, C3, M2, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M2, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M2, 0) ' top of pipe ElseIf F1 = 0 And F3 > 0 Then Mefi = (V1 + Vefi) / 2 * fi M1 = (Vefi + V4) / 2 * (L1 - fi) + Mefi Mefo = M1 + ((V5 + Vefo) / 2 * (L3 - fo)) M2 = Mefo + ((V6 + Vefo) / 2 * (DistF3 - (L3 - fo))) M1 = M1 * 12 M2 = M2 * 12 Mefi = Mefi * 12 Mefo = Mefo * 12

192

' MMaxVert is used at Location 1, vertical pipe span TminV1 = CalculateBottomVert(SIF1, C3, M2, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M2, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M2, 0) ' top of pipe ' Location 4, Valve 3 location Tmin4_1 = CalculateTmin(SIF_V3, 0, M2, 0, 3, 0.1) Tmin4_2 = Pressure * SIF_V3 * Dod / (2 * SIF_V3 * Y * Pressure + 2 * (SE / Ibend)) ElseIf F1 > 0 And F3 > 0 Then M1 = (V1 + V2) / 2 * DistF1 Mefi = (V3 + Vefi) / 2 * (fi - DistF1) + M1 M2 = (Vefi + V4) / 2 * (L1 - fi) + Mefi Mefo = (Vefo + V5) / 2 * (L3 - fo) + M2 M3 = (Vefo + V6) / 200 * (DistF3 - (L3 - fo)) + Mefo M1 = M1 * 12 Mefi = Mefi * 12 M2 = M2 * 12 Mefo = Mefo * 12 M3 = M3 * 12 ' Section 1 calculations, valve 1 find which stress: hoop or bending + long is larger Tmin2_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * SIF_V1 * Dod / (2 * SIF_V1 * Y * Pressure + 2 * (SE / Ibend)) ' MMaxVert is used at Location 2, vertical pipe span TminV1 = CalculateBottomVert(SIF1, C3, M2, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M2, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M2, 0) ' top of pipe ' Location 4, Valve 3 location Tmin4_1 = CalculateTmin(SIF_V3, 0, M2, 0, 3, 0.1) Tmin4_2 = Pressure * SIF_V3 * Dod / (2 * SIF_V3 * Y * Pressure + 2 * (SE / Ibend)) End If ' Left side of L1 calcluations Tmin1 = CalculateTmin(1, 0, 0, V1, 0, 0.1) ' Location 6, end of pipe span L3. Tmin6 = CalculateTmin(1, 0, 0, V8, 0, 0.1) Tminefi = CalculateElbowfi(SIF1, Mefi, Vefi) Tminefo = CalculateElbowfo(SIF2, Mefo, Vefo) Tstr = LargestTmin(Tmin1, Tmin1_1, Tmin1_2, Tmin2_1, Tmin2_2, Tmin3_1, Tmin3_2, Tmin4_1, _ Tmin4_2, Tmin5_1, Tmin5_2, TminV1, TminV2, Tmin6, Tminefi, Tminefo, TminV3) If Tstr = Tmin1 Then frmOutput.TminCircle1(0).Visible = True ElseIf Tstr = Tmin2_1 Or Tstr = Tmin2_2 Then frmOutput.TminCircle1(1).Visible = True 193

ElseIf Tstr = Tmin4_1 Or Tstr = Tmin4_2 Then frmOutput.TminCircle1(2).Visible = True ElseIf Tstr = Tmin6 Then frmOutput.TminCircle1(3).Visible = True ElseIf Tstr = TminV1 Then frmOutput.VertSection(1).Visible = True ElseIf Tstr = TminV2 Or Tstr = TminV3 Then frmOutput.VertSection(0).Visible = True ElseIf Tstr = Tminefo Then frmOutput.Section1(2).Visible = True ElseIf Tstr = Tminefi Then frmOutput.Section1(1).Visible = True End If End If End If If V5 >= 0 Then ' max moment occurs between vertical span and valve 3 If V6 <= 0 Then XCross = V5 / WPLtot ' finds where x crosses the zero shear If F1 > 0 And F3 > 0 Then M1 = (V1 + V2) / 2 * DistF1 Mefi = (V3 + Vefi) / 2 * (fi - DistF1) + M1 M2 = (V4 + Vefi) / 2 * (L1 - fi) + Mefi If fo >= XCross Then ' these calcs get the moment right after elbow on L3 Mefo = (Vefo + V5) / 2 * (L3 - fo) + M2 ElseIf XCross >= fo Then Mefo = -Vefo / 2 * (XCross - fo) + M3 End If M3 = Vefo / 2 * XCross + Mefo M4 = -V6 / 2 * (DistF3 - XCross) + M3 M1 = M1 * 12 M2 = M2 * 12 M3 = M3 * 12 M4 = M4 * 12 Mefo = Mefo * 12 Mefi = Mefi * 12 ' Section 1, valve 1 calculations Tmin2_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * SIF_V1 * Dod / (2 * SIF_V1 * Y * Pressure + 2 * (SE / Ibend)) 'Section 2, vertical span, will use M2 TminV1 = CalculateBottomVert(SIF1, C3, M2, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M2, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M2, 0) ' top of pipe 'Section 3, maximum moment occurs here If (XCross + DistF3) >= fo And (XCross + DistF3) <= L3 Then Tmin4_1 = CalculateTmin(SIF2, 0, M3, 0, 3, 0.1) 194

Tmin4_2 = Pressure * SIF2 * Dod / (2 * Y * Pressure * SIF2 + 2 * (SE / Ibend)) Else Tmin4_1 = CalculateTmin(1, 0, M3, 0, 3, 0.1) Tmin4_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) End If 'Section 5 Valve location F3 Tmin5_1 = CalculateTmin(SIF_V3, 0, M3, 0, 3, 0.1) Tmin5_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) ElseIf F1 = 0 And F3 > 0 Then Mefi = (V1 + Vefi) / 2 * (L3 - fi) M1 = (V1 + Vefi) / 2 * fi + Mefi If fo >= XCross Then ' these calcs get the moment right after elbow on L3 Mefo = (Vefo + V5) / 2 * (L3 - fo) + M1 M2 = V5 / 2 * XCross + Mefo ElseIf XCross >= fo Then Mefo = -Vefo / 2 * (XCross - fo) + M2 M2 = V5 / 2 * XCross + M1 End If M3 = -V6 / 2 * (DistF3 - XCross) M1 = M1 * 12 M2 = M2 * 12 M3 = M3 * 12 Mefo = Mefo * 12 Mefi = Mefi * 12 'Section 3, vertical span, will use M1 TminV1 = CalculateBottomVert(SIF1, C3, M1, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M1, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M1, 0) ' top of pipe 'Section 4, maximum moment occurs here If (XCross + DistF3) >= fo And (XCross + DistF3) <= L3 Then Tmin4_1 = CalculateTmin(SIF2, 0, M2, 0, 3, 0.1) Tmin4_2 = Pressure * SIF2 * Dod / (2 * Y * Pressure * SIF2 + 2 * (SE / Ibend)) Else Tmin4_1 = CalculateTmin(1, 0, M2, 0, 3, 0.1) Tmin4_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) End If 'Section 5 Valve location F3 Tmin5_1 = CalculateTmin(SIF_V3, 0, M3, 0, 3, 0.1) Tmin5_2 = Pressure * SIF_V3 * Dod / (2 * SIF_V3 * Y * Pressure + 2 * (SE / Ibend)) ElseIf F1 > 0 And F3 = 0 Then M1 = (V1 + V2) / 2 * DistF1 Mefi = (V3 + Vefi) / 2 * (fi - DistF1) + M1 M2 = (V4 + Vefi) / 2 * (L1 - F1) + Mefi If fo >= XCross Then ' these calcs get the moment right after elbow on L3 Mefo = (V5 + Vefo) / 2 * (L3 - fo) + M2 M3 = Vefo / 2 * XCross + Mefo 195

ElseIf XCross >= fo Then Mefo = -Vefo / 2 * (XCross - fo) + M2 M3 = V5 / 2 * XCross + M2 End If M1 = M1 * 12 M2 = M2 * 12 M3 = M3 * 12 M4 = M4 * 12 Mefo = Mefo * 12 Mefi = Mefi * 12 ' Section 2 calculations, valve 1 Tmin2_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * SIF_V1 * Dod / (2 * SIF_V1 * Y * Pressure + 2 * (SE / Ibend)) 'Section 3, vertical span, will use M2 TminV1 = CalculateBottomVert(SIF1, C3, M2, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M2, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M2, 0) ' top of pipe 'Section 4, maximum moment occurs here If (XCross + DistF3) >= fo And (XCross + DistF3) <= L3 Then Tmin4_1 = CalculateTmin(SIF2, 0, M3, 0, 3, 0.1) Tmin4_2 = Pressure * SIF2 * Dod / (2 * Y * Pressure * SIF2 + 2 * (SE / Ibend)) Else Tmin4_1 = CalculateTmin(1, 0, M3, 0, 3, 0.1) Tmin4_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) End If 'Section 5 Valve location F3 Tmin4_1 = CalculateTmin(SIF_V3, 0, M4, 0, 3, 0.1) Tmin5_2 = Pressure * SIF_V3 * Dod / (2 * SIF_V3 * Y * Pressure + 2 * (SE / Ibend)) End If ' Left side of L1 calcluations Tmin1 = CalculateTmin(1, 0, 0, V1, 0, 0.1) ' Location 6, end of pipe span L3. Tmin6 = CalculateTmin(1, 0, 0, V8, 0, 0.1) Tminefi = CalculateElbowfi(SIF1, Mefi, Vefi) Tminefo = CalculateElbowfo(SIF2, Mefo, Vefo) Tstr = LargestTmin(Tmin1, Tmin1_1, Tmin1_2, Tmin2_1, Tmin2_2, Tmin3_1, Tmin3_2, Tmin4_1, _ Tmin4_2, Tmin5_1, Tmin5_2, TminV1, TminV2, Tmin6, Tminefi, Tminefo, TminV3) If Tstr = Tmin1 Then frmOutput.TminCircle1(0).Visible = True ElseIf Tstr = Tmin2_1 Or Tstr = Tmin2_2 Then frmOutput.TminCircle1(1).Visible = True ElseIf Tstr = Tmin4_1 Or Tstr = Tmin4_2 Then frmOutput.TminCircle1(2).Visible = True ElseIf Tstr = Tmin6 Then 196

frmOutput.TminCircle1(3).Visible = True ElseIf Tstr = TminV1 Then frmOutput.VertSection(1).Visible = True ElseIf Tstr = TminV2 Or Tstr = TminV3 Then frmOutput.VertSection(0).Visible = True ElseIf Tstr = Tminefo Then frmOutput.Section1(2).Visible = True ElseIf Tstr = Tminefi Then frmOutput.Section1(1).Visible = True End If End If End If If V6 >= 0 Then ' max moment occurs at Valve 3 If V7 <= 0 Then If F1 > 0 And F3 > 0 Then M1 = (V1 + V2) / 2 * DistF1 Mefi = (V3 + Vefi) / 2 * (fi - DistF1) + M1 M2 = (V4 + Vefi) / 2 * (fi - fi) + Mefi Mefo = (V5 + Vefo) / 2 * (L3 - fo) + M2 M3 = (Vefo + V6) / 2 * (DistF3 - (L3 - fo)) + Mefo M1 = M1 * 12 M2 = M2 * 12 M3 = M3 * 12 Mefi = Mefi * 12 Mefo = Mefo * 12 ' location 2. Valve F1. Tmin2_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * SIF_V1 * Dod / (2 * SIF_V1 * Y * Pressure + 2 * (SE / Ibend)) ' Location 3, vertical pipe span. Constant moment occurs here (M2). TminV1 = CalculateBottomVert(SIF1, C3, M2, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M2, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M2, 0) ' top of pipe ' Location 4, Valve 3 location. Maximum moment occurs here Tmin4_1 = CalculateTmin(SIF_V3, 0, M3, 0, 3, 0.1) Tmin4_2 = Pressure * SIF_V3 * Dod / (2 * SIF_V3 * Y * Pressure + 2 * (SE / Ibend)) ElseIf F1 = 0 And F3 > 0 Then Mefi = (V1 + Vefi) / 2 * DistF1 M1 = (V2 + Vefi) / 2 * (L1 - fi) + Mefi Mefo = (V5 + Vefo) / 2 * (L3 - fo) + M1 M2 = (Vefo + V6) / 2 * (DistF3 - (L3 - fo)) + Mefo M3 = 0 M1 = M1 * 12 M2 = M2 * 12 M3 = M3 * 12 Mefi = Mefi * 12 Mefo = Mefo * 12 197

' Location 3, vertical pipe span. Constant moment occurs here (M1). TminV1 = CalculateBottomVert(SIF1, C3, M1, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M1, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M1, 0) ' top of pipe ' Location 4, Valve 3 location. Maximum moment occurs here Tmin4_1 = CalculateTmin(SIF_V3, 0, M2, 0, 3, 0.1) Tmin4_2 = Pressure * SIF_V3 * Dod / (2 * SIF_V3 * Y * Pressure + 2 * (SE / Ibend)) Else M1 = ((V2 - V1) / DistF1 + V2 * DistF1) M2 = ((V4 - V3) / (L1 - DistF1) * (L1 ^ 2 / 2 - DistF1 ^ 2 / 2) + V4 * (L1 - DistF1)) + M1 M3 = ((V6 - V5) / (L3 - DistF3 - L1) * ((L3 - DistF3) ^ 2 / 2 - L1 ^ 2 / 2) + V6 * (L3 - DistF3 L1)) + M2 Mefi = -((V4 + Vefi) / 2 * (L1 - fi)) + M1 Mefo = ((V5 + Vefo) / 2 * (L3 - fo)) + M1 M1 = M1 * 12 M2 = M2 * 12 M3 = M3 * 12 Mefi = Mefi * 12 Mefo = Mefo * 12 ' location 2. Valve F1. Tmin2_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) ' Location 3, vertical pipe span. Constant moment occurs here (M2). TminV1 = CalculateBottomVert(SIF1, C3, M2, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M2, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M2, 0) ' top of pipe ' Location 4, Valve 3 location. Maximum moment occurs here Tmin4_1 = CalculateTmin(SIF_V3, 0, M3, 0, 3, 0.1) Tmin4_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) End If ' Left side of L1 calcluations Tmin1 = CalculateTmin(1, 0, 0, V1, 0, 0.1) ' Location 6, end of pipe span L3. Tmin6 = CalculateTmin(1, 0, 0, V8, 0, 0.1) Tminefi = CalculateElbowfi(SIF1, Mefi, Vefi) Tminefo = CalculateElbowfo(SIF2, Mefo, Vefo) Tstr = LargestTmin(Tmin1, Tmin1_1, Tmin1_2, Tmin2_1, Tmin2_2, Tmin3_1, Tmin3_2, Tmin4_1, _ Tmin4_2, Tmin5_1, Tmin5_2, TminV1, TminV2, Tmin6, Tminefi, Tminefo, TminV3) If Tstr = Tmin1 Then frmOutput.TminCircle1(0).Visible = True ElseIf Tstr = Tmin2_1 Or Tstr = Tmin2_2 Then frmOutput.TminCircle1(1).Visible = True ElseIf Tstr = Tmin4_1 Or Tstr = Tmin4_2 Then frmOutput.TminCircle1(2).Visible = True ElseIf Tstr = Tmin6 Then 198

frmOutput.TminCircle1(3).Visible = True ElseIf Tstr = TminV1 Then frmOutput.VertSection(0).Visible = True ElseIf Tstr = TminV2 Or Tstr = TminV3 Then frmOutput.VertSection(1).Visible = True ElseIf Tstr = Tminefo Then frmOutput.Section1(2).Visible = True ElseIf Tstr = Tminefi Then frmOutput.Section1(1).Visible = True End If End If End If If V7 >= 0 Then ' max moment occurs between valve 3 and right end of span L3 If V8 <= 0 Then XCross = V7 / WPLtot If F1 > 0 And F3 > 0 Then M1 = (V1 + V2) / 2 * DistF1 Mefi = (V2 + Vefi) / 2 * (fi - DistF1) + M1 M2 = (V3 + Vefi) / 2 * (L1 - fi) + Mefi Mefo = (V5 + Vefo) / 2 * (L3 - fo) + M2 M3 = (Vefo + V6) / 2 * (DistF3 - (L3 - fo)) + Mefo M4 = V7 / 2 * (XCross) + M3 Mefi = Mefi * 12 Mefo = Mefo * 12 M1 = M1 * 12 M2 = M2 * 12 M3 = M3 * 12 M4 = M4 * 12 ' location 1. Valve F1. Tmin2_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * SIF_V1 * Dod / (2 * SIF_V1 * Y * Pressure + 2 * (SE / Ibend)) ' Location 2, vertical pipe span. Constant moment occurs here (M2). TminV1 = CalculateBottomVert(SIF1, C3, M2, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M2, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M2, 0) ' top of pipe ' Location 2, Valve 3 Tmin4_1 = CalculateTmin(SIF_V3, 0, M3, 0, 3, 0.1) Tmin4_2 = Pressure * SIF_V3 * Dod / (2 * SIF_V3 * Y * Pressure + 2 * (SE / Ibend)) ' Location 4, max moment occurs Tmin5_1 = CalculateTmin(1, 0, M4, 0, 3, 0.1) Tmin5_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) ElseIf F1 = 0 And F3 > 0 Then Mefi = (V1 + Vefi) / 2 * fi M1 = (V2 + Vefi) / 2 * (L1 - fi) + M1 Mefo = (V5 + Vefo) / 2 * (L3 - fo) + M1 M2 = (V6 + Vefo) / 2 * (DistF3 - (L3 - fo)) + Mefo 199

M3 = V7 / 2 * (XCross) + M2 M1 = M1 * 12 M2 = M2 * 12 M3 = M3 * 12 Mefi = Mefi * 12 Mefo = Mefo * 12 ' Location 3, vertical pipe span. Constant moment occurs here (M2). TminV1 = CalculateBottomVert(SIF1, C3, M1, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M1, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M1, 0) ' top of pipe ' Location 4, Valve 3 Tmin4_1 = CalculateTmin(SIF_V1, 0, M2, 0, 3, 0.1) Tmin4_2 = Pressure * SIF_V1 * Dod / (2 * SIF_V1 * Y * Pressure + 2 * (SE / Ibend)) ' Location 5, max moment occurs Tmin5_1 = CalculateTmin(1, 0, M3, 0, 3, 0.1) Tmin5_2 = Pressure * Dod / (2 * Pressure * Y + 2 * (SE / Ibend)) Else M1 = ((V2 - V1) / DistF1 * DistF1 ^ 2 / 2 + V1 * DistF1) M2 = ((V4 - V3) / (L1 - DistF1) * (L1 ^ 2 / 2 - DistF1 ^ 2 / 2) + V3 * (L1 - DistF1)) + M1 M3 = ((V6 - V5) / (L3 - DistF3 - L1) * ((L3 - DistF3) ^ 2 / 2 - L1 ^ 2 / 2) + V5 * (L3 - DistF3 L1)) + M2 M4 = (-V6 / (XCross - L3 - DistF3) * (XCross ^ 2 / 2 - (L3 - DistF3) ^ 2 / 2) - V6 * (XCross - L3 - DistF3)) + M3 Mefi = -((V4 + Vefi) / 2 * (L1 - fi)) + M2 Mefo = ((V5 + Vefo) / 2 * (L3 - fo)) + M2 Mefi = Mefi * 12 Mefo = Mefo * 12 M1 = M1 * 12 M2 = M2 * 12 M3 = M3 * 12 M4 = M4 * 12 ' location 2. Valve F1. Tmin2_1 = CalculateTmin(SIF_V1, 0, M1, 0, 3, 0.1) Tmin2_2 = Pressure * Dod / (2 * Y * Pressure + 2 * (SE / Ibend)) ' Location 3, vertical pipe span. Constant moment occurs here (M2). TminV1 = CalculateBottomVert(SIF1, C3, M2, 0) ' bottom of pipe TminV2 = CalculateMiddleVert(SIF_V2, C2, M2, 0) ' center of pipe TminV3 = CalculateTopVert(SIF2, C1, M2, 0) ' top of pipe ' Location 4, Valve 3 Tmin4_1 = CalculateTmin(SIF2, 0, M3, 0, 3, 0.1) Tmin4_2 = Pressure * Dod / (2 * Pressure * Y + 2 * (SE / Ibend)) ' Location 5, max moment occurs between F3 and end of pipe span L3 Tmin5_1 = CalculateTmin(SIF_V3, 0, M4, 0, 3, 0.1) Tmin5_2 = Pressure * Dod / (2 * Pressure * Y + 2 * (SE / Ibend)) End If ' Left side of L1 calcluations Tmin1 = CalculateTmin(1, 0, 0, V1, 0, 0.1) ' Location 6, end of pipe span L3. 200

Tmin6 = CalculateTmin(1, 0, 0, V8, 0, 0.1) Tminefi = CalculateElbowfi(SIF1, Mefi, Vefi) Tminefo = CalculateElbowfo(SIF2, Mefo, Vefo) Tstr = LargestTmin(Tmin1, Tmin1_1, Tmin1_2, Tmin2_1, Tmin2_2, Tmin3_1, Tmin3_2, Tmin4_1, _ Tmin4_2, Tmin5_1, Tmin5_2, TminV1, TminV2, Tmin6, Tminefi, Tminefo, TminV3) If Tstr = Tmin1 Then frmOutput.TminCircle1(0).Visible = True ElseIf Tstr = Tmin2_1 Or Tstr = Tmin2_2 Then frmOutput.TminCircle1(1).Visible = True ElseIf Tstr = Tmin4_1 Or Tstr = Tmin4_2 Then frmOutput.TminCircle1(2).Visible = True ElseIf Tstr = Tmin6 Then frmOutput.TminCircle1(3).Visible = True ElseIf Tstr = TminV1 Then frmOutput.VertSection(1).Visible = True ElseIf Tstr = TminV2 Or Tstr = TminV3 Then frmOutput.VertSection(0).Visible = True ElseIf Tstr = Tminefo Then frmOutput.Section1(2).Visible = True ElseIf Tstr = Tminefi Then frmOutput.Section1(1).Visible = True End If End If End If '++++++++++++++++++++++++++++++++++++ ' ----------End of Shear and moment checks----------------------'++++++++++++++++++++++++++++++++++++ If Tstr >= Tnom Then MsgBox "The calculated value for structural thickness is " & Tstr & ThkUnit & vbCrLf & "The input value for nominal wall thickness is " & Tnom & ThkUnit & vbCrLf & "The required structural thickness must be less than the nominal wall", vbExclamation frmOutput.MousePointer = vbArrow ' restore mouse to pointer frmInput.Show ResetPSTableNum 'negates the PSTable number change errorflag = True Exit Sub End If ' Calc Sl Source = Accession report 17959 eq 4 SL = Pressure * Dod / (4 * Tstr) + M * Tnom / (Znom * Tstr) frmOutput.MousePointer = vbArrow ' restore mouse to pinter after cals are done ++++++++++++++++++++++++++++++++++++++++++++++++++ 201

' ++++++++ Print variables for data dump ++++++++++++++++++++++++ '++++++++++++++++++++++++++++++++++++++++++++++++++ If DataDump = True Then Printer.Print Printer.Print "Values from CalculateVerticalM" Printer.Print Printer.Print "Left End Reaction"; R1 Printer.Print "Right End Reaction"; R2 Printer.Print "Left End Shear"; V1 Printer.Print "Upper Shear at F1"; V2 Printer.Print "Lower Shear at F1"; V3 Printer.Print "Upper Shear at Center of pipe"; V4 Printer.Print "Lower Shear at Center of pipe"; V5 Printer.Print "Upper Shear at F3"; V6 Printer.Print "Lower Shear at F3"; V7 Printer.Print "Shear at V8"; V8 Printer.Print "Moment M1"; M1 Printer.Print "Moment M2"; M2 Printer.Print "Moment M3"; M3 Printer.Print "Moment M4"; M4 Printer.Print "Tstr"; Tstr End If End Sub Function LargestTmin(T1 As Single, T1_1 As Single, T1_2 As Single, T2_1 As Single, T2_2 As Single, T3_1 As Single, T3_2 As Single, T4_1 As Single, _ T4_2 As Single, T5_1 As Single, T5_2 As Single, TV1 As Single, TV2 As Single, T6 As Single, _ Tefi As Single, Tefo As Single, TV3) ' This function gets the largest Tmin from all differential stress elements Tmin's Dim Largest As Single Dim TempT(16) Largest = 0 TempT(0) = T1 TempT(1) = T2_1 TempT(2) = T2_2 TempT(3) = T3_1 TempT(4) = T3_2 TempT(5) = T4_1 TempT(6) = T4_2 TempT(7) = T5_1 TempT(8) = T5_2 202

TempT(9) = T6 TempT(10) = TV1 TempT(11) = TV2 TempT(12) = Tefi TempT(13) = Tefo TempT(14) = T1_1 TempT(15) = T1_2 TempT(16) = TV3 For i = 0 To 16 If Largest < TempT(i) Then Largest = TempT(i) End If Next i LargestTmin = Largest Tstr = LargestTmin End Function Function CalculateElbowfi(SIF As Single, M As Single, V As Single) Tminefi_1 = CalculateTmin(SIF, 0, M, 0, 3, 0) Tminefi_2 = Pressure * Dod / (2 * SIF1 * Y * Pressure + 2 * (SE / Ibend)) ' call the function that gets the stress formula and input these 2 Tmins CalculateElbowfi = LargestTmin(Tminefi_1, Tminefi_2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) End Function Function CalculateElbowfo(SIF As Single, M As Single, V As Single) Tminefo_1 = CalculateTmin(SIF, 0, M, 0, 3, 0) Tminefo_2 = Pressure * Dod / (2 * SIF2 * Y * Pressure + 2 * (SE / Ibend)) ' call the function that gets the stress formula and input these 2 Tmins CalculateElbowfo = LargestTmin(Tminefo_1, Tminefo_2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) End Function Function CalculateBottomVert(SIF As Single, P As Single, M As Single, V As Single) If P > 0 Then ' only do these calcs when in compression TminBottomV1 = CalculateTmin(SIF, P, M, 0, 1, 0) TminBottomV2 = CalculateTmin(SIF, P, M, 0, 2, 0) End If TminBottomV3 = CalculateTmin(SIF, 0, M, 0, 3, 0) TminBottomV4 = CalculateTmin(SIF, P, M, 0, 4, 0) TminBottomV5 = CalculateTmin(SIF, P, M, 0, 5, 0) TminBottomV6 = Pressure * Dod / (2 * SIF * Y * Pressure + 2 * (SE / Ibend))

203

CalculateBottomVert = LargestTmin(TminBottomV1, TminBottomV2, TminBottomV3, TminBottomV4, TminBottomV5, TminBottomV6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) End Function Function CalculateMiddleVert(SIF As Single, P As Single, M As Single, V As Single) If P > 0 Then ' only do these calcs when in compression TminMiddleV1 = CalculateTmin(SIF, P, M, 0, 1, 0) TminMiddleV2 = CalculateTmin(SIF, P, M, 0, 2, 0) End If TminMiddleV3 = CalculateTmin(SIF, 0, M, 0, 3, 0) If P < 0 Then ' only do these calcs if in tension TminMiddleV4 = CalculateTmin(SIF, P, M, 0, 4, 0) TminMiddleV5 = CalculateTmin(SIF, P, M, 0, 5, 0) End If TminMiddleV6 = Pressure * Dod / (2 * SIF * Y * Pressure + 2 * (SE / Ibend)) CalculateMiddleVert = LargestTmin(TminMiddleV1, TminMiddleV2, TminMiddleV3, TminMiddleV4, TminMiddleV5, TminMiddleV6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) End Function Function CalculateTopVert(SIF As Single, P As Single, M As Single, V As Single) If P > 0 Then ' only do these calcs if in compression TminTopV1 = CalculateTmin(SIF, P, M, 0, 1, 0) TminTopV2 = CalculateTmin(SIF, P, M, 0, 2, 0) End If TminTopV3 = CalculateTmin(SIF, 0, M, 0, 3, 0) TminTopV4 = CalculateTmin(SIF, P, M, 0, 4, 0) TminTopV5 = CalculateTmin(SIF, P, M, 0, 5, 0) TminTopV6 = Pressure * Dod / (2 * SIF * Y * Pressure + 2 * (SE / Ibend)) CalculateTopVert = LargestTmin(TminTopV1, TminTopV2, TminTopV3, TminTopV4, TminTopV5, TminTopV6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) End Function Function CalculateT(SIF As Single, P As Single, M As Single, V As Single, check_case As Single, O As Single) As Single ' CalculateT (SIF Value, P Compression value, M is moment, V is Shear, check_Case is what case is called, O is initial guess or variable passed)

204

If check_case = 0 Then ' Calculate end Tmin values ' The following equation was derived from use of Mohrs circle for a finite stress element ' with shear present. See Appendix A of Chris Comeau's thesis for full derivation CalculateT = -Sh + SIF * 2 * (((Pressure * (Dod - 2 * O) / (2 * O)) + (Pressure * (Dod - 2 * O) / (4 * O))) / 2 _ + Sqr((((Pressure * (Dod - 2 * O) / (2 * O)) - (Pressure * (Dod - 2 * O) / (4 * O))) / 2) ^ 2 _ + (2 * Abs(V) / ((PI / 4) * (Dod ^ 2 - (Dod - 2 * O) ^ 2))) ^ 2)) ElseIf check_case = 1 Then ' Calculates vertical tension Tmin (Slong+Sbend-Scomp) CalculateT = -Sh _ + 32 * M * SIF / (PI * (Dod ^ 4 - (Dod - 2 * O) ^ 4)) _ + Pressure * (Dod - 2 * O) * SIF / (4 * O) _ - 8 * Abs(P) * SIF / (PI * (Dod ^ 2 - (Dod - 2 * O) ^ 2)) ElseIf check_case = 2 Then ' Calculates vertical compression Tmin (Slong-Sbend-Scomp) CalculateT = -Sh _ - 32 * M * SIF / (PI * (Dod ^ 4 - (Dod - 2 * O) ^ 4)) _ + Pressure * (Dod - 2 * O) * SIF / (4 * O) _ - 8 * Abs(P) * SIF / (PI * (Dod ^ 2 - (Dod - 2 * O) ^ 2)) ElseIf check_case = 3 Then ' bending and longitudinal stresses CalculateT = -Sh _ + SIF * Pressure * (Dod - 2 * O) / (4 * O) _ + (Dod * M * SIF) / (PI / 32 * (Dod ^ 4 - (Dod - 2 - O) ^ 4)) ElseIf check_case = 4 Then ' Calculates vertical tension case Tmin (Slong-Sbend+Scomp) CalculateT = -Sh _ + 32 * M * SIF / (PI * (Dod ^ 4 - (Dod - 2 * O) ^ 4)) _ + Pressure * (Dod - 2 * O) * SIF / (4 * O) _ + 8 * Abs(P) * SIF / (PI * (Dod ^ 2 - (Dod - 2 * O) ^ 2)) ElseIf check_case = 5 Then ' Calculates vertical tension case Tmin (Slong-Sbend+Scomp) CalculateT = -Sh _ - 32 * M * SIF / (PI * (Dod ^ 4 - (Dod - 2 * O) ^ 4)) _ + Pressure * (Dod - 2 * O) * SIF / (4 * O) _ + 8 * Abs(P) * SIF / (PI * (Dod ^ 2 - (Dod - 2 * O) ^ 2)) End If End Function Function CalculateTmin(SIF As Single, P As Single, M As Single, V As Single, check_case As Single, O As Single) 205

On Error GoTo Errhandler Dim g As Single Dim BB As Single Dim n As Single Dim Max As Single Dim delta As Single Dim epsilon As Single Dim satisfied As String Dim Ya_1 As Single Dim Yb_1 As Single If check_case = 0 Then 'mohr's circle derivation (see appendix A of thesis) Ya = CalculateT(SIF, P, M, V, 0, Tnom * 0.1) Yb = CalculateT(SIF, P, M, V, 0, 4 * Tnom) BB = Tnom n = Tnom * 0.05 If Sgn(Ya) = Sgn(-1) Then For n = Tnom * 0.005 To 4 * Tnom Step 0.01 Ya = CalculateT(SIF, P, M, V, 0, n) BB = Tnom If Ya > 0 Then GoTo 8 Next n check_case = 0 End If 8 If Sgn(Yb) = Sgn(1) Then For g = 10 * Tnom To Tnom Step 0.01 Yb = CalculateT(SIF, P, M, V, 0, g) BB = g If Yb < 0 Then GoTo 10 Next g ElseIf Yb > 0 Then For g = 10 * Tnom To Tnom Step 0.01 Yb = CalculateT(SIF, P, M, V, 0, g) BB = g If Yb < 0 Then GoTo 10 Next g check_case = 0 End If ElseIf check_case = 1 Then '(Slong+Sbend-Scomp) Ya = 0 Ya = CalculateT(SIF, P, M, V, 1, 0.065 * Tnom) Yb = CalculateT(SIF, P, M, V, 1, Tnom) n = 0.005 * Tnom BB = Tnom 206

If Ya < 0 Then For n = Tnom * 0.005 To 4 * Tnom Step 0.01 Ya = CalculateT(SIF, P, M, V, 1, n) BB = Tnom If Ya > 0 Then GoTo 9 Next n check_case = 1 End If 9 If Yb > 0 Then For g = 10 * Tnom To Tnom Step 0.01 Yb = CalculateT(SIF, P, M, V, 1, g) BB = g If Yb < 0 Then GoTo 10 Next g check_case = 1 End If

ElseIf check_case = 2 Then '(Slong-Sbend-Scomp) Ya = 0 Yb = CalculateT(SIF, P, M, V, 2, 5 * Tnom) Ya = CalculateT(SIF, P, M, V, 2, 0.005 * Tnom) 'n = Tnom 'BB = 0.005 * Tnom BB = 5 * Tnom n = 0.005 * Tnom If Ya <= 0 Then For n = 5 * Tnom To 0.4 * Tnom Step 0.01 Ya = CalculateT(SIF, P, M, V, 2, n) BB = Tnom n=n If Ya > 0 Then GoTo 11 Next n End If 11 If Yb > 0 Then For g = 10 * Tnom To Tnom Step 0.01 Yb = CalculateT(SIF, P, M, V, 2, g) BB = g If Yb < 0 Then GoTo 10 Next g End If check_case = 2

207

ElseIf check_case = 3 Then '(Slong+Sbend) Ya = CalculateT(SIF, 0, M, 0, 3, Tnom * 0.01) Yb = CalculateT(SIF, 0, M, 0, 3, 10 * Tnom) check_case = 3 n = 0.05 * Tnom BB = Tnom If Sgn(Ya) = Sgn(-1) Then For n = Tnom * 0.05 To 4 * Tnom Step 0.01 Ya = CalculateT(SIF, P, M, V, 3, n) 'n = Tnom If Ya > 0 Then GoTo 12 Next n End If 12 If Yb > 0 Then For g = 10 * Tnom To Tnom Step 0.01 Yb = CalculateT(SIF, P, M, V, 3, g) BB = g If Yb < 0 Then GoTo 10 Next g End If

ElseIf check_case = 4 Then '(Slong+Sbend+Scomp) Ya = 0 Ya = CalculateT(SIF, P, M, V, 1, 0.065 * Tnom) Yb = CalculateT(SIF, P, M, V, 1, Tnom) n = 0.005 * Tnom BB = Tnom If Ya < 0 Then For n = Tnom * 0.005 To 4 * Tnom Step 0.01 Ya = CalculateT(SIF, P, M, V, 1, n) BB = Tnom If Ya > 0 Then GoTo 19 Next n check_case = 1 End If 19 If Yb > 0 Then For g = 10 * Tnom To Tnom Step 0.01 Yb = CalculateT(SIF, P, M, V, 1, g) BB = g If Yb < 0 Then GoTo 10 Next g check_case = 1 208

End If ElseIf check_case = 5 Then '(Slong-Sbend+Scomp) Ya = 0 Ya = CalculateT(SIF, P, M, V, 1, 0.05 * Tnom) Yb = CalculateT(SIF, P, M, V, 1, Tnom) n = 0.005 * Tnom BB = Tnom If Ya < 0 Then For n = Tnom * 0.005 To 4 * Tnom Step 0.01 Ya = CalculateT(SIF, P, M, V, 1, n) BB = Tnom If Ya > 0 Then GoTo 29 Next n check_case = 1 End If 29 If Yb > 0 Then For g = 10 * Tnom To Tnom Step 0.01 Yb = CalculateT(SIF, P, M, V, 1, g) BB = g If Yb < 0 Then GoTo 10 Next g check_case = 1 End If

End If If Sgn(Ya) = Sgn(Yb) Then GoTo Errhandler 10 'when Ya and Yb are opposite signs, they will come here. Max = 15999 ' max number of iterations delta = 0.00001 epsilon = 0.00001 satisfied = "false" 'Begin false position root solver For k = 1 To Max Dx = Yb * (BB - n) / (Yb - Ya) C = BB - Dx Yc = CalculateT(SIF, P, M, V, check_case, C) If Yc = 0 Then satisfied = "true"

209

ElseIf Sgn(Yb) = Sgn(Yc) Then BB = C Yb = Yc Else n=C Ya = Yc End If If Abs(Dx) < delta And Abs(Yc) < epsilon Then satisfied = "true" GoTo 15 End If Next k 15 CalculateTmin = C ' C Gives result of Tmin Errhandler: ' Will go here if an error occurs Exit Function End Function

210

D2: Piping Span Choose Form

211

D2a: Piping Span Choose Form Code


Private Sub cmdCancelSpan_Click() frmInput.lblSpan.Caption = "" frmSpanChoose.Hide End Sub Private Sub cmdHelp_Click() tempArea = MsgBox("Span choice help", vbMsgBoxHelpButton, "Span Choice Help", App.Path & "\TminHelp.hlp", 106) End Sub Private Sub cmdSpanOK_Click() For i = 0 To 3 If optSpan1(i).Value = True Then Select Case i Case 0 ConfigID = 0 Call frmInput.DrawOutline frmInput.tbdInput.Tab = 1 Case 1 ConfigID = 1 frmInput.tbdInput.Tab = 1 Call frmInput.DrawOutline Case 2 ConfigID = 2 frmInput.tbdInput.Tab = 1 Call frmInput.DrawOutline Case 3 ConfigID = 3 frmInput.tbdInput.Tab = 5 End Select frmSpanChoose.Hide Exit Sub End If Next i MsgBox "Please choose span construction type", vbExclamation End Sub

212

D3: Valve Connection Form

213

D3a: Valve Connection Form Code

Private Sub cmdValveOK_Click() For i = 0 To 5 If optValve(i).Value = True Then Select Case i Case 0 'SIF_Valve = 1 Valve = "Butt" Case 1 'SIF_Valve = 1.2 Valve = "DblWeld" Case 2 ' SIF_Valve = 1.3 Valve = "FilletWld" Case 3 ' SIF_Valve = 1.6 Valve = "LapJoint" Case 4 ' SIF_Valve = 2.3 Valve = "Threaded" Case 5 ' SIF_Valve = 2.3 Valve = "DoNotKnow" End Select If ConfigID = 0 Then SIFHV1 = Valve ElseIf ConfigID = 1 Then SIFHV1 = Valve ElseIf ConfigID = 2 Then SIFHV1 = Valve ElseIf ConfigID = 3 Then SIFV1 = Valve ElseIf ConfigID = 4 Then SIFV2 = Valve ElseIf ConfigID = 5 Then SIFV3 = Valve End If frmValveConst.Hide Exit Sub End If Next i MsgBox "Please choose valve connection type", vbExclamation End Sub

214

D4: 2-D Vertical Analysis Form

215

D4a: 2-D Vertical Piping Span Analysis Code

'Addition for the vertical piping spans. Case Is = 3 ConfigID = 3 SIFV1 = "" Select Case lstPipeType(3).ListIndex Case Is = 0 lblSpan1(3).Caption = " Straight Pipe" ' will show straight pipe caption on the Tab lblSpan1(3).Font.Bold = False lblLenSegPic(3) = "" 61 TempInput = InputBox("Enter Length of L1 Pipe Span in feet.", "L1 Pipe Span Length", L1, vbOKCancel) If TempInput = "" Then TempInput = L1 InputID = "L1 Pipe Length" InputCheck If ValidInput = 0 Then GoTo 61 L1 = ValidInput lblLenSegPic(3) = L1 response1 = MsgBox("Do you have any valves in Pipe Span L1?", vbYesNo) If response1 = vbNo Then response1 = 31 SegmentID = 3 DrawNoLoadV lblLoadLocPic(3).Visible = False lblLoadMagPic(3).Visible = False DistF1 = 0 F1 = 0 GoTo 65 Else response1 = 30 SegmentID = Index DrawYesLoadV ' show the valve distance and wieght arrows 62 TempInput = InputBox("Enter Distance to Valve on Pipe Span L1 in feet.", "Distance to Valve 1", DistF1) If TempInput = L1 Then Reply = MsgBox("Distance to Valve cannot be equal to L1 Pipe Span!.") GoTo 62 ElseIf TempInput > L1 Then Reply = MsgBox("Distance to Valve cannot be larger than L1 Pipe Span!.") GoTo 62 End If 216

63

If TempInput = "" Then TempInput = DistF1 InputID = "Distance to Valve 1" InputCheck If ValidInput = 0 Then GoTo 62 DistF1 = ValidInput lblLoadLocPic(3) = DistF1 TempInput = "" ' will clear the valve distance so valve distance won't appear as valve weight TempInput = InputBox("Enter Valve Weight on Pipe Span L1.", "Weight of Valve 1", F1) If TempInput = "" Then TempInput = DistF1 InputID = "Weight of Valve 1" InputCheck If ValidInput = 0 Then GoTo 63 F1 = ValidInput lblLoadMagPic(3) = F1 frmInput.lblSpan.Caption = "Vertical Pipe Span--Two Axis" frmValveConst.Show End If Case Is = 1 ConfigID = 3 response1 = 31 lblSpan1(3).Font.Bold = False lblSpan1(3).Caption = " Maximum Span" ' will show Maximum straight pipe caption on the

65

Tab SegmentID = Index DrawNoLoadV lblLenSegPic(3) = 0 frmInput.lblSpan.Caption = "Vertical Pipe Span--Two Axis" DistF1 = 0 F1 = 0 End Select Case Is = 4 ConfigID = 4 Select Case lstPipeType(4).ListIndex Case Is = 0 SIFV2 = "" lblSpan1(4).Font.Bold = False lblSpan1(4).Caption = " Straight Pipe" ' will show straight pipe caption on the Tab lblLenSegPic(4) = "" 71 TempInput = InputBox("Enter Length of L2 Pipe Span in feet.", "L2 Pipe Span Length", L2, vbOKCancel) If vbOKCancel = True Then Exit Sub 217

End If If TempInput = "" Then TempInput = L2 InputID = "L2 Pipe Length" InputCheck If ValidInput = 0 Then GoTo 71 L2 = ValidInput lblLenSegPic(4) = L2 response2 = MsgBox("Do you have any valves in Pipe Span L2?", vbYesNo) If response2 = vbNo Then response2 = 41 SegmentID = 4 DrawNoLoadV lblLoadLocPic(4).Visible = False lblLoadMagPic(4).Visible = False DistF2 = 0 F2 = 0 GoTo 75 Else response2 = 40 SegmentID = Index DrawYesLoadV ' show the valve distance and wieght arrows 72 TempInput = InputBox("Enter Distance to Valve on Pipe Span L2 in feet.", "Distance to Valve 2", DistF2) If TempInput = L2 Then Reply = MsgBox("Distance to Valve cannot be equal to L2 Pipe Span!.") GoTo 72 ElseIf TempInput > L2 Then Reply = MsgBox("Distance to Valve cannot be larger than L2 Pipe Span!.") GoTo 72 End If If TempInput = "" Then TempInput = DistF2 InputID = "Distance to Valve 2" InputCheck If ValidInput = 0 Then GoTo 72 DistF2 = ValidInput lblLoadLocPic(4) = DistF2 TempInput = "" ' will clear the valve distance so valve distance won't appear as valve weight TempInput = InputBox("Enter Valve Weight on Pipe Span L2.", "Weight of Valve 2", F2) If TempInput = "" Then TempInput = F2 InputID = "Weight of Valve 2" InputCheck If ValidInput = 0 Then GoTo 73 F2 = ValidInput lblLoadMagPic(4) = F2 frmValveConst.Show 218

73

End If 75 Case Is = 1 ConfigID = 4 response2 = 41 lblSpan1(4).Font.Bold = False lblSpan1(4).Caption = " Maximum Span" ' will show Maximum straight pipe caption on the Tab SegmentID = Index DrawNoLoadV lblLenSegPic(4) = 0 DistF2 = 0 F2 = 0 End Select Case Is = 5 ConfigID = 5 Select Case lstPipeType(5).ListIndex Case Is = 0 SIFV3 = "" lblSpan1(5).Font.Bold = False lblSpan1(5).Caption = " Straight Pipe" ' will show straight pipe caption on the Tab lblLenSegPic(5) = "" 81 TempInput = InputBox("Enter Length of L3 Pipe Span in feet.", "L3 Pipe Span Length", L3) If TempInput = "" Then TempInput = L3 InputID = "L3 Pipe Length" InputCheck If ValidInput = 0 Then GoTo 81 L3 = ValidInput lblLenSegPic(5) = L3 response3 = MsgBox("Do you have any valves in Pipe Span L3?", vbYesNo) If response3 = vbNo Then response = 51 SegmentID = 5 DrawNoLoadV lblLoadLocPic(5).Visible = False lblLoadMagPic(5).Visible = False DistF3 = 0 F3 = 0 GoTo 85 Else response3 = 50 SegmentID = Index DrawYesLoadV ' show the valve distance and wieght arrows 219

82 TempInput = InputBox("Enter Distance to Valve on Pipe Span L3 in feet.", "Distance to Valve 3", DistF3) If TempInput = L3 Then Reply = MsgBox("Distance to Valve cannot be equal to L3 Pipe Span!.") GoTo 82 ElseIf TempInput > L3 Then Reply = MsgBox("Distance to Valve cannot be larger than L3 Pipe Span!.") GoTo 82 End If If TempInput = "" Then TempInput = DistF3 InputID = "Distance to Valve 3" InputCheck If ValidInput = 0 Then GoTo 82 DistF3 = ValidInput lblLoadLocPic(5) = DistF3 83 TempInput = InputBox("Enter Valve Weight on Pipe Span L3.", "Weight of Valve 3", F3) If TempInput = "" Then TempInput = F3 InputID = "Weight of Valve 3" InputCheck If ValidInput = 0 Then GoTo 83 F3 = ValidInput lblLoadMagPic(5) = F3 frmValveConst.Show End If 85 Case Is = 1 ConfigID = 5 response3 = 51 lblSpan1(5).Caption = " Maximum Span" ' will show Maximum straight pipe caption on the lblSpan1(5).Font.Bold = False SegmentID = Index DrawNoLoadV lblLenSegPic(5) = 0 DistF3 = 0 F3 = 0 End Select Case Is = 6 ConfigID = 6 Select Case lstPipeType(6).ListIndex Case 0 SIFType = "BENDLR" lblSpan1(6).Caption = " Standard Long Radius Bend" lblSpan1(6).Font.Bold = False 220

Tab

Case 1 SIFType = "BENDSR" lblSpan1(6).Caption = " Short Radius Bend" lblSpan1(6).Font.Bold = False Case 2 SIFType = "BEND3D" lblSpan1(6).Caption = " 3D Bend" lblSpan1(6).Font.Bold = False Case 3 SIFType = "BEND5D" lblSpan1(6).Caption = " 5D Bend" lblSpan1(6).Font.Bold = False ' Use short radius as default is user does not know Case 4 SIFType = "BENDSR" lblSpan1(6).Caption = " Do Not Know" lblSpan1(6).Font.Bold = False End Select Case Is = 7 ConfigID = 7 Select Case lstPipeType(7).ListIndex Case 0 SIFType = "BENDLR" lblSpan1(7).Caption = " Standard Long Radius Bend" lblSpan1(7).Font.Bold = False Case 1 SIFType = "BENDSR" lblSpan1(7).Caption = " Short Radius Bend" lblSpan1(7).Font.Bold = False Case 2 SIFType = "BEND3D" lblSpan1(7).Caption = " 3D Bend" lblSpan1(7).Font.Bold = False Case 3 SIFType = "BEND5D" lblSpan1(7).Caption = " 5D Bend" lblSpan1(7).Font.Bold = False ' Use short radius as default is user does not know 221

Case 4 SIFType = "BENDSR" lblSpan1(7).Caption = " Do Not Know" lblSpan1(7).Font.Bold = False frmInput.lblSpan.Caption = "Vertical Pipe Span--Two Plane" End Select

222

D5: Bookmark Code


Public Sub OpenWord(formPlant, formuser, formCalcNum, formArea, formLineID, _ formNPS, formSch, formTemp, formInsulation, formPressure, formPipeOD, _ formSG, formMaterial, formPipeWallThk, formNusr, formTstr, formThoop, formTmin, _ formTmech, SavingFile, formTscr, formTfat, formTcycl, formMaterial1, formCycles, _ formMoreC, formLowSG, formLowTnom, formWrongData, formSizeExceed, lblSizeFatigue, formTnom, _ formTmin1, formTmin6, formTminV1, formTminV2, formTminefi, formTminefo, formTmins1, formTmin2, _ formTmin3, formTmin44, formTmin4, formTmin5, formTminV3, formTmin89) Dim Range As Word.Range Dim Myw As Object name Microsoft word as Myw Dim FullName As Object If Myw Is Nothing Then Set Myw = GetObject("", "Word.Application") Myw.Visible = False If ConfigID <= 2 Then Myw.Documents.Add (App.Path & "\Dupont1-97.dot") 'this is the location of the template created for horizontal ElseIf ConfigID >= 3 Then Myw.Documents.Add (App.Path & "\Dupont2-97.dot") 'this is the location of the template created for vertical End If Myw.Application.WindowState = wdWindowStateMinimize End If ' runs the macro in the word template to import the piping image Dim Word As Object 'Declare an object variable Set Word = CreateObject("Word.Basic") 'Set the object pointer Word.ToolsMacro "Macro", True 'Run the macro ' pass data to the bookmarks in the template I created in Word and print it If ConfigID >= 3 Then ' only do these bookmarks for the vertical span ' if you remove this if statement, the word doc will not open Set Range = Myw.ActiveDocument.Bookmarks("Tmin1").Range Range.InsertAfter formTmin1 Set Range = Myw.ActiveDocument.Bookmarks("Tmins1").Range Range.InsertAfter formTmins1 Set Range = Myw.ActiveDocument.Bookmarks("Tmin2").Range Range.InsertAfter formTmin2 Set Range = Myw.ActiveDocument.Bookmarks("Tmin3").Range Range.InsertAfter formTmin3 Set Range = Myw.ActiveDocument.Bookmarks("Tmin4").Range

223

Range.InsertAfter formTmin4 Set Range = Myw.ActiveDocument.Bookmarks("Tmin44").Range Range.InsertAfter formTmin44 Set Range = Myw.ActiveDocument.Bookmarks("Tmin5").Range Range.InsertAfter formTmin5 Set Range = Myw.ActiveDocument.Bookmarks("Tmin6").Range Range.InsertAfter formTmin6 Set Range = Myw.ActiveDocument.Bookmarks("TminV1").Range Range.InsertAfter formTminV1 Set Range = Myw.ActiveDocument.Bookmarks("TminV2").Range Range.InsertAfter formTminV2 Set Range = Myw.ActiveDocument.Bookmarks("TminV3").Range Range.InsertAfter formTminV3 Set Range = Myw.ActiveDocument.Bookmarks("Tminefi").Range Range.InsertAfter formTminefi Set Range = Myw.ActiveDocument.Bookmarks("Tminefo").Range Range.InsertAfter formTminefo Set Range = Myw.ActiveDocument.Bookmarks("Tmin89").Range Range.InsertAfter formTmin89 End If Set Range = Myw.ActiveDocument.Bookmarks("SizeExceed").Range Range.InsertAfter formSizeExceed Set Range = Myw.ActiveDocument.Bookmarks("SizeFatigue").Range Range.InsertAfter lblSizeFatigue Set Range = Myw.ActiveDocument.Bookmarks("LowSG").Range Range.InsertAfter formLowSG Set Range = Myw.ActiveDocument.Bookmarks("LowTnom").Range Range.InsertAfter formLowTnom Set Range = Myw.ActiveDocument.Bookmarks("WrongData").Range Range.InsertAfter formWrongData Set Range = Myw.ActiveDocument.Bookmarks("MoreC").Range Range.InsertAfter formMoreC Set Range = Myw.ActiveDocument.Bookmarks("Area").Range Range.InsertAfter formArea Set Range = Myw.ActiveDocument.Bookmarks("Plant").Range Range.InsertAfter formPlant Set Range = Myw.ActiveDocument.Bookmarks("Title").Range Range.InsertAfter formLineID Set Range = Myw.ActiveDocument.Bookmarks("CalcNum").Range Range.InsertAfter formCalcNum Set Range = Myw.ActiveDocument.Bookmarks("user").Range Range.InsertAfter USER Set Range = Myw.ActiveDocument.Bookmarks("Sch").Range Range.InsertAfter formSch Set Range = Myw.ActiveDocument.Bookmarks("Temp").Range Range.InsertAfter formTemp 224

Set Range = Myw.ActiveDocument.Bookmarks("Insulation").Range Range.InsertAfter formInsulation Set Range = Myw.ActiveDocument.Bookmarks("Pressure").Range Range.InsertAfter formPressure Set Range = Myw.ActiveDocument.Bookmarks("SG").Range Range.InsertAfter formSG Set Range = Myw.ActiveDocument.Bookmarks("Dod").Range Range.InsertAfter formPipeOD Set Range = Myw.ActiveDocument.Bookmarks("Nusr").Range Range.InsertAfter formNusr Set Range = Myw.ActiveDocument.Bookmarks("Tscr").Range Range.InsertAfter formTscr Set Range = Myw.ActiveDocument.Bookmarks("Tfat").Range Range.InsertAfter formTfat Set Range = Myw.ActiveDocument.Bookmarks("Tcycl").Range Range.InsertAfter formTcycl Set Range = Myw.ActiveDocument.Bookmarks("Material").Range Range.InsertAfter formMaterial Set Range = Myw.ActiveDocument.Bookmarks("Tnom").Range Range.InsertAfter formTnom Set Range = Myw.ActiveDocument.Bookmarks("Tmech").Range Range.InsertAfter formTmech Set Range = Myw.ActiveDocument.Bookmarks("Thoop").Range Range.InsertAfter formThoop Set Range = Myw.ActiveDocument.Bookmarks("Tmin").Range Range.InsertAfter formTmin Set Range = Myw.ActiveDocument.Bookmarks("Cycles").Range Range.InsertAfter formCycles Set Range = Myw.ActiveDocument.Bookmarks("Tstr").Range Range.InsertAfter formTstr frmOutput.MousePointer = vbArrow ' restore mouse to pinter after word is open Myw.Visible = True 'show the word document after all fields are filled in. Myw.Application.WindowState = wdWindowStateMaximize Set Myw = Nothing 'remove Microsoft Word from memory End Sub

225

D6: Copy Image Code


'-------------------------------------------------------------------''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ' Visual Basic 6.0 16/32 Capture Routines ' ' This module contains several routines for capturing windows into a ' picture. All the routines work on both 16 and 32 bit Windows ' platforms. ' The routines also have palette support. ' ' CreateBitmapPicture - Creates a picture object from a bitmap and ' palette. ' CaptureWindow - Captures any window given a window handle. ' CaptureActiveWindow - Captures the active window on the desktop. ' CaptureForm - Captures the entire form. ' CaptureClient - Captures the client area of a form. ' CaptureScreen - Captures the entire screen. ' PrintPictureToFitPage - prints any picture as big as possible on ' the page. ' ' NOTES ' - No error trapping is included in these routines. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Option Explicit Option Base 0 Private Type PALETTEENTRY peRed As Byte peGreen As Byte peBlue As Byte peFlags As Byte End Type Private Type LOGPALETTE palVersion As Integer palNumEntries As Integer palPalEntry(255) As PALETTEENTRY ' Enough for 256 colors. End Type Private Type GUID Data1 As Long Data2 As Integer
226

Data3 As Integer Data4(7) As Byte End Type #If Win32 Then Private Const RASTERCAPS As Integer = 3 ' 38 Private Const RC_PALETTE As Integer = &H100 Private Const SIZEPALETTE As Integer = 4 '104 Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function CreateCompatibleDC Lib "GDI32" ( _ ByVal hDC As Long) As Long Private Declare Function CreateCompatibleBitmap Lib "GDI32" ( _ ByVal hDC As Long, ByVal nWidth As Long, _ ByVal nHeight As Long) As Long Private Declare Function GetDeviceCaps Lib "GDI32" ( _ ByVal hDC As Long, ByVal iCapabilitiy As Long) As Long Private Declare Function GetSystemPaletteEntries Lib "GDI32" ( _ ByVal hDC As Long, ByVal wStartIndex As Long, _ ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) _ As Long Private Declare Function CreatePalette Lib "GDI32" ( _ lpLogPalette As LOGPALETTE) As Long Private Declare Function SelectObject Lib "GDI32" ( _ ByVal hDC As Long, ByVal hObject As Long) As Long Private Declare Function BitBlt Lib "GDI32" ( _ ByVal hDCDest As Long, ByVal XDest As Long, _ ByVal YDest As Long, ByVal nWidth As Long, _ ByVal nHeight As Long, ByVal hDCSrc As Long, _ ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) _ As Long Private Declare Function DeleteDC Lib "GDI32" ( _ ByVal hDC As Long) As Long Private Declare Function GetForegroundWindow Lib "USER32" () _ As Long Private Declare Function SelectPalette Lib "GDI32" ( _ ByVal hDC As Long, ByVal hPalette As Long, _
227

ByVal bForceBackground As Long) As Long Private Declare Function RealizePalette Lib "GDI32" ( _ ByVal hDC As Long) As Long Private Declare Function GetWindowDC Lib "USER32" ( _ ByVal hWnd As Long) As Long Private Declare Function GetDC Lib "USER32" ( _ ByVal hWnd As Long) As Long Private Declare Function GetWindowRect Lib "USER32" ( _ ByVal hWnd As Long, lpRect As RECT) As Long Private Declare Function ReleaseDC Lib "USER32" ( _ ByVal hWnd As Long, ByVal hDC As Long) As Long Private Declare Function GetDesktopWindow Lib "USER32" () As Long Private Type PicBmp Size As Long Type As Long hBmp As Long hPal As Long Reserved As Long End Type Private Declare Function OleCreatePictureIndirect _ Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, _ ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long #ElseIf Win16 Then Private Const RASTERCAPS As Integer = 3 ' 38 Private Const RC_PALETTE As Integer = &H100 Private Const SIZEPALETTE As Integer = 4 '104 Private Type RECT Left As Integer Top As Integer Right As Integer Bottom As Integer End Type Private Declare Function CreateCompatibleDC Lib "GDI" ( _ ByVal hDC As Integer) As Integer Private Declare Function CreateCompatibleBitmap Lib "GDI" ( _ ByVal hDC As Integer, ByVal nWidth As Integer, _ ByVal nHeight As Integer) As Integer Private Declare Function GetDeviceCaps Lib "GDI" ( _
228

ByVal hDC As Integer, ByVal iCapabilitiy As Integer) As Integer Private Declare Function GetSystemPaletteEntries Lib "GDI" ( _ ByVal hDC As Integer, ByVal wStartIndex As Integer, _ ByVal wNumEntries As Integer, _ lpPaletteEntries As PALETTEENTRY) As Integer Private Declare Function CreatePalette Lib "GDI" ( _ lpLogPalette As LOGPALETTE) As Integer Private Declare Function SelectObject Lib "GDI" ( _ ByVal hDC As Integer, ByVal hObject As Integer) As Integer Private Declare Function BitBlt Lib "GDI" ( _ ByVal hDCDest As Integer, ByVal XDest As Integer, _ ByVal YDest As Integer, ByVal nWidth As Integer, _ ByVal nHeight As Integer, ByVal hDCSrc As Integer, _ ByVal XSrc As Integer, ByVal YSrc As Integer, _ ByVal dwRop As Long) As Integer Private Declare Function DeleteDC Lib "GDI" ( _ ByVal hDC As Integer) As Integer Private Declare Function GetForegroundWindow Lib "USER" _ Alias "GetActiveWindow" () As Integer Private Declare Function SelectPalette Lib "USER" ( _ ByVal hDC As Integer, ByVal hPalette As Integer, ByVal _ bForceBackground As Integer) As Integer Private Declare Function RealizePalette Lib "USER" ( _ ByVal hDC As Integer) As Integer Private Declare Function GetWindowDC Lib "USER" ( _ ByVal hWnd As Integer) As Integer Private Declare Function GetDC Lib "USER" ( _ ByVal hWnd As Integer) As Integer Private Declare Function GetWindowRect Lib "USER" ( _ ByVal hWnd As Integer, lpRect As RECT) As Integer Private Declare Function ReleaseDC Lib "USER" ( _ ByVal hWnd As Integer, ByVal hDC As Integer) As Integer Private Declare Function GetDesktopWindow Lib "USER" () As Integer Private Type PicBmp Size As Integer Type As Integer hBmp As Integer hPal As Integer Reserved As Integer End Type Private Declare Function OleCreatePictureIndirect _ Lib "oc25.dll" (PictDesc As PicBmp, RefIID As GUID, _
229

ByVal fPictureOwnsHandle As Integer, IPic As IPicture) _ As Integer #End If

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ' CreateBitmapPicture ' - Creates a bitmap type Picture object from a bitmap and ' palette. ' ' hBmp ' - Handle to a bitmap. ' ' hPal ' - Handle to a Palette. ' - Can be null if the bitmap doesn't use a palette. ' ' Returns ' - Returns a Picture object containing the bitmap. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' #If Win32 Then Public Function CreateBitmapPicture(ByVal hBmp As Long, _ ByVal hPal As Long) As Picture Dim r As Long #ElseIf Win16 Then Public Function CreateBitmapPicture(ByVal hBmp As Integer, _ ByVal hPal As Integer) As Picture Dim r As Integer #End If Dim Pic As PicBmp ' IPicture requires a reference to "Standard OLE Types." Dim IPic As IPicture Dim IID_IDispatch As GUID ' Fill in with IDispatch Interface ID. With IID_IDispatch .Data1 = &H20400 .Data4(0) = &HC0 .Data4(7) = &H46
230

End With ' Fill Pic with necessary parts. With Pic .Size = Len(Pic) ' Length of structure. .Type = vbPicTypeBitmap ' Type of Picture (bitmap). .hBmp = hBmp ' Handle to bitmap. .hPal = hPal ' Handle to palette (may be null). End With ' Create Picture object. r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic) ' Return the new Picture object. Set CreateBitmapPicture = IPic End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ' CaptureWindow ' - Captures any portion of a window. ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #If Win32 Then Public Function CaptureWindow(ByVal hWndSrc As Long, _ ByVal Client As Boolean, ByVal LeftSrc As Long, _ ByVal TopSrc As Long, ByVal WidthSrc As Long, _ ByVal HeightSrc As Long) As Picture Dim hDCMemory As Long Dim hBmp As Long Dim hBmpPrev As Long Dim r As Long Dim hDCSrc As Long Dim hPal As Long Dim hPalPrev As Long Dim RasterCapsScrn As Long Dim HasPaletteScrn As Long Dim PaletteSizeScrn As Long #ElseIf Win16 Then Public Function CaptureWindow(ByVal hWndSrc As Integer, _ ByVal Client As Boolean, ByVal LeftSrc As Integer, _ ByVal TopSrc As Integer, ByVal WidthSrc As Long, _
231

ByVal HeightSrc As Long) As Picture Dim hDCMemory As Integer Dim hBmp As Integer Dim hBmpPrev As Integer Dim r As Integer Dim hDCSrc As Integer Dim hPal As Integer Dim hPalPrev As Integer Dim RasterCapsScrn As Integer Dim HasPaletteScrn As Integer Dim PaletteSizeScrn As Integer #End If Dim LogPal As LOGPALETTE ' Depending on the value of Client get the proper device context. If Client Then hDCSrc = GetDC(hWndSrc) ' Get device context for client area. Else hDCSrc = GetWindowDC(hWndSrc) ' Get device context for entire ' window. End If ' Create a memory device context for the copy process. hDCMemory = CreateCompatibleDC(hDCSrc) ' Create a bitmap and place it in the memory DC. hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc) hBmpPrev = SelectObject(hDCMemory, hBmp) ' Get screen properties. RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS) ' Raster ' capabilities. HasPaletteScrn = RasterCapsScrn And RC_PALETTE ' Palette ' support. PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE) ' Size of ' palette. ' If the screen has a palette make a copy and realize it. If HasPaletteScrn And (PaletteSizeScrn = 256) Then ' Create a copy of the system palette. LogPal.palVersion = &H300 LogPal.palNumEntries = 256 r = GetSystemPaletteEntries(hDCSrc, 0, 256, _ LogPal.palPalEntry(0))
232

hPal = CreatePalette(LogPal) ' Select the new palette into the memory DC and realize it. hPalPrev = SelectPalette(hDCMemory, hPal, 0) r = RealizePalette(hDCMemory) End If ' Copy the on-screen image into the memory DC. r = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, _ LeftSrc, TopSrc, vbSrcCopy) ' Remove the new copy of the on-screen image. hBmp = SelectObject(hDCMemory, hBmpPrev) ' If the screen has a palette get back the palette that was ' selected in previously. If HasPaletteScrn And (PaletteSizeScrn = 256) Then hPal = SelectPalette(hDCMemory, hPalPrev, 0) End If ' Release the device context resources back to the system. r = DeleteDC(hDCMemory) r = ReleaseDC(hWndSrc, hDCSrc) ' Call CreateBitmapPicture to create a picture object from the ' bitmap and palette handles. Then return the resulting picture ' object. Set CaptureWindow = CreateBitmapPicture(hBmp, hPal) ' SavePicture(picture, End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ' CaptureClient ' - Captures the client area of a form. ' ' frmSrc ' - The Form object to capture. ' ' Returns ' - Returns a Picture object containing a bitmap of the form's
233

' client area. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function CaptureClient(frmSrc As Form) As Picture ' Call CaptureWindow to capture the client area of the form given ' its window handle and return the resulting Picture object. Set CaptureClient = CaptureWindow(frmSrc.hWnd, True, 0, 0, _ frmSrc.ScaleX(frmSrc.ScaleWidth, frmSrc.ScaleMode, vbPixels), _ frmSrc.ScaleY(frmSrc.ScaleHeight, frmSrc.ScaleMode, vbPixels)) End Function

234

D7: Call Macro Computer Code

' runs the macro in the word template to import the piping image Dim Word As Object 'Declare an object variable Set Word = CreateObject("Word.Basic") 'Set the object pointer Word.ToolsMacro "Macro", True 'Run the macro

235

Anda mungkin juga menyukai