'General Section Declaration Option Base 0 'array base Option Compare Text Private Const atm As Double = 101.325 ' Atmospheric pressure in kPA Public Const pi As Double = 3.14159265358979
Function DuctSize_Cir_mm(Air_cmh, Optional dP_Pa = 1, Optional V_mps = 8, Optional e_mm = 0.09) 'Calculate Circular Duct Size, Default for 1Pa/m, 8 m/s and Medium Surface Roughness 0.09mm Dim dV As Double, dD As Double, dA As Double Dim dP As Double
'calc Area which satisfy the velocity limits dV = V_mps dA = Air_cmh / (3600# * dV) dD = (4 * dA / pi) ^ 0.5 * 1000
'call function for Friction Loss dP = DuctFrictionLoss_Pa(Air_cmh, dD, e_mm)
If dP > dP_Pa Then Do 'Use Power rule estimation for iteration dD = dD * (dP / dP_Pa) ^ 0.25 dP = DuctFrictionLoss_Pa(Air_cmh, dD, e_mm) 'exit error 1% If Abs((dP - dP_Pa) / dP_Pa) < 0.01 Then Exit Do Loop End If DuctSize_Cir_mm = dD End Function
Function DuctFrictionLoss_Pa(Air_cmh, DuctDia_mm, Optional e_mm = 0.09) 'Calculate Friction Loss Dim dQ As Double, dD As Double 'flowrate (m3/s), diameter(mm) Dim dV As Double, dF As Double 'velocity (m/s), friction factor Dim dM As Double, dE As Double 'density (kg/m3), surface roughness Dim Re As Double, dA As Double
'For Cold Air Standard at density=1.2kg/m3 If Air_cmh * DuctDia_mm > 0 Then dQ = Air_cmh / 3600# 'convert air flowrate to m3/s dD = DuctDia_mm dM = 1.2 'kg/m3 for cold air std dA = 0.25 * pi * (dD / 1000#) ^ 2 dV = dQ / dA 'v=Q/A Re = 66.4 * dD * dV 'Ref ASHRAE: or use Re = V * d / nu dF = f_Colebrook(e_mm / dD, Re) DuctFrictionLoss_Pa = 500 * dF * dM * dV * dV / dD Else DuctFrictionLoss_Pa = 0 End If End Function
Function f_Colebrook(e_by_D, Re) 'e_by_D Relative roughness; Dh: Hydraulic Dia, Re: Reynold number 'Calculate Colebrook friction Factor
Dim f As Double, root_f As Double, root_f1 As Double
'Start with Tsal's estimation f = 0.11 * (e_by_D + 68 / Re) ^ 0.25 If f < 0.018 Then f = 0.85 * f + 0.0028 End If
root_f = f ^ 0.5 Do root_f1 = -0.5 * Log(10) / Log(e_by_D / 3.7 + 2.51 / (root_f * Re)) 'check if error is less than 0.5% If Abs((root_f1 - root_f) / root_f) < 0.005 Then Exit Do root_f = 0.5 * (root_f + root_f1) 'Use binary approach iteration Loop f_Colebrook = root_f ^ 2 End Function
Use of VBA Functions in Excel Worksheet
ၿပီးရင္ေတာ့ ဒီ Function ေတြကို Excel Spreadsheet မွာ အသင့္သံုးႏိုင္ပါၿပီ။
ပထမ Insert function ကိုသြားၿပီး select a category မွာ User Defined ကိုေရြးလိုက္ရင္ ဒီ Function ေတြ ေပၚလာပါလိမ့္မယ္။
ၿပီးရင္ေတာ့ Excel Formula သံုးေနက် အတိုင္းသံုးရံုပါပဲ။ ဒီအထဲ မွာ Air_cmh ဆိုတဲ့ ကြက္လပ္ကိုေတာ့ ျဖည့္ကို ျဖည့္ရပါမယ္။ အျခား ကြက္လပ္ေတြ ကို Function မွာထဲ က Optional အေနနဲ႔ ေရြးၿပီး Assign လုပ္ထားတာမို႔ မျဖည့္လည္း ရပါတယ္။ Assigned လုပ္ခဲ့တဲ့ value ေတြကေတာ့ အသံုးမ်ားတဲ့
Rectangular Duct ရဲ့ Equivalent Diameter ရွာမဲ့ Function ကိုသံုးႏိုင္ဘို႔ VBA Code ကိုေအာက္မွာ ေဖာ္ျပေပးထားပါတယ္။ Function DuctR2C(dH, dW) As Double 'Rectangular Duct to Circular Duct If dW * dH > 0 Then DuctR2C = 1.3 * ((dH * dW) ^ 0.625) / ((dH + dW) ^ 0.25) Else DuctR2C = 0 End If End Function
Oval Duct ရဲ့ Equivalent Diameter ရွာမဲ့ Function ကိုသံုးႏိုင္ဘို႔ VBA Code ကိုေအာက္မွာ ေဖာ္ျပေပးထားပါတယ္။ Function DuctO2C(dH, dW) As Double 'Oval Duct to Circular Duct Dim dA As Double, P As Double If dW * dH > 0 Then dA = (pi * dH ^ 2 / 4) + dH * (dW - dH) P = pi * dH + 2 * (dW - dH) DuctO2C = 1.55 * (dA ^ 0.625) / (P ^ 0.25) Else DuctO2C = 0 End If End Function
Circular Duct ကေန Equivalent Rectangular Duct Size ရွာမဲ့ Function ကိုသံုးႏိုင္ဘို႔ VBA Code ကိုေအာက္မွာ ေဖာ္ျပေပးထားပါတယ္။ Function DuctC2R(dD, Optional dH = 0) As Double 'Circular Duct to Rectangular Duct 'if Dimension (dH) is zero, square duct 'dH could be either dimension: "Width" or "Height" Dim dW As Double, dW1 As Double Dim dD1 As Double
If dH > 0 Then 'Estimate dH dW = 0.25 * pi * dD * dD / dH Do dD1 = 1.3 * ((dH * dW) ^ 0.625) / ((dH + dW) ^ 0.25) dW = dW * (dD / dD1) ^ 2 If Abs((dD1 - dD) / dD) < 0.005 Then Exit Do Loop Else dW = dD * 0.9148 End If DuctC2R = dW End Function
Circular Duct ကေန Equivalent Oval Duct Size ရွာမဲ့ Functionကိုသံုးႏိုင္ဘို႔ VBA Code ကိုေအာက္မွာ ေဖာ္ျပေပးထားပါတယ္။ Function DuctC2O_Width(dD, Optional dH = 0) As Double 'Circular Duct to Rectangular Duct 'if Dimension (dH) is zero, square duct + round, ie, a = 2 * b 'dH is dimension b for "Height", dW is dimension a for "Width" 'As nature, dH < dD Dim dW As Double, dW1 As Double Dim dD1 As Double Dim dA As Double, P As Double
If dH > 0 Then 'Estimate dH dW = 0.25 * pi * (dD * dD - dH * dH) / dH Do dA = (pi * dH ^ 2 / 4) + dH * (dW - dH) P = pi * dH + 2 * (dW - dH) dD1 = 1.55 * (dA ^ 0.625) / (P ^ 0.25) dW = dW * (dD / dD1) ^ 2 If Abs((dD1 - dD) / dD) < 0.005 Then Exit Do Loop Else dW = dD / 1.5234 End If DuctC2O_Width = dW End Function
Duct Design ကိုလိုက္လို႔ ရႏိုင္မဲ့ Air Flow Limits ကိုတြက္ႏိုင္ဘို႔ Function သံုးခုကို ေအာက္မွာ ေပးထားပါတယ္။
Function DuctAirFlow_Cir_cmh(dD_mm, Optional dP_Pa = 1, Optional dV_mps = 9, Optional e_mm = 0.09) Dim cmh As Double, dP As Double Dim dD As Double, dV As Double
dV = dV_mps dD = dD_mm cmh = 0.0009 * pi * dD * dD * dV '0.0009 <- 0.25*3600/1000000 dP = DuctFrictionLoss_Pa(cmh, dD, e_mm) If dP > dP_Pa Then Do dV = dV * (dP_Pa / dP) ^ 0.5 cmh = 0.0009 * pi * dD * dD * dV dP = DuctFrictionLoss_Pa(cmh, dD, e_mm) If Abs(dP - dP_Pa) / dP_Pa < 0.01 Then Exit Do Loop End If DuctAirFlow_Cir_cmh = cmh End Function
Function DuctAirFlow_Rec_cmh(dW_mm, dH_mm, Optional dP_Pa = 1, Optional dV_mps = 9, Optional e_mm = 0.09) Dim dD As Double, dV As Double dV = dV_mps dD = DuctR2C(dW_mm, dH_mm) DuctAirFlow_Rec_cmh = DuctAirFlow_Cir_cmh(dD, dP_Pa, dV_mps, e_mm) End Function
Function DuctAirFlow_Oval_cmh(dW_mm, dH_mm, Optional dP_Pa = 1, Optional dV_mps = 9, Optional e_mm = 0.09) Dim dD As Double, dV As Double dV = dV_mps dD = DuctO2C(dW_mm, dH_mm) DuctAirFlow_Oval_cmh = DuctAirFlow_Cir_cmh(dD, dP_Pa, dV_mps, e_mm) End Function
Screenshots of Adding VBA Codes in Excel
Excel 2002-2003 (or Earlier)
နမူနာ အေနနဲ႔ Microsoft Excel 2002-2003 မွာဆိုရင္ေတာ့ ဒီလိုေတြ႕ရပါလိမ့္မယ္။
"You do not know, you cannot know, what it means to have eyes in a world in which everyone else is blind. I am not a king, no, I am simply the one who was born to see this horror. You can feel it; I can both feel and see it."
No comments:
Post a Comment