回复 10楼 lowxiong
十分感谢你的帮助。受益匪浅
回复 10楼 lowxiong
麻烦您再看看我的代码吧资料下载地址:http://wenku.baidu.com/view/f56736e919e8b8f67c1cb9e1.html
我的程序如下,但是在验证过程中,部分数据计算错误,不知道问题出在了哪里。
Private Sub Command1_Click()
Dim k0, k1, pt, p15, p155, p20, a, vcf, t1, t2, p, vt, v20, m, dt, t3, vs, qy, cy, pjq, ms, a1 As Double
If Trim(Text1.Text) = "" Then
MsgBox "无法计算", vbOKOnly + vbExclamation, ""
Exit Sub
Text1.SetFocus
End If
If Trim(Text2.Text) = "" Then
MsgBox "无法计算", vbOKOnly + vbExclamation, ""
Exit Sub
Text2.SetFocus
End If
If Trim(Text3.Text) = "" Then
MsgBox "无法计算", vbOKOnly + vbExclamation, ""
Exit Sub
Text3.SetFocus
End If
t1 = Val(Text1.Text) ''''''''''''''''''''视温
p = Val(Text2.Text) ''''''''''''''''''''视密
t2 = Val(Text3.Text) ''''''''''''''''''''油温
vt = Val(Text4.Text)
If p <= 770.3 And p >= 653 Then ''''''''''''''''''''653~770 石油产品(汽油)
k0 = 346.4228
k1 = 0.4388
pt = p * (1 - 2.3 * 10 ^ (-5) * (t1 - 20) - 2 * 10 ^ (-8) * (t1 - 20) * (t1 - 20))
p15 = pt
Do
p155 = p15
a = k0 / (p155 * p155) + k1 / p155
p15 = pt / Exp(-a * (t1 - 15) * (1 + a * (t1 - 15) * 0.8))
Loop Until Abs(p15 - p155) < 0.005
a = k0 / (p15 * p15) + k1 / p15
p20 = p15 * Exp(-a * 5 * (1 + a * 4))
vcf = Exp(-a * (t2 - 20) * (1 + a * 0.8 * (t2 - 20) + 8 * a))
v20 = vt * vcf
m = (p20 / 1000 - 0.0011) * v20
dt = vcf * (p20 - 1.1)
p20 = Int(p20 * 10 + 0.5) / 10
vcf = Int(vcf * 10000 + 0.5) / 10000
v20 = Int(v20 + 0.5)
m = Int(m + 0.5)
dt = Int(dt * 10 + 0.5) / 10
Text6.Text = vcf
Text5.Text = p20
Text7.Text = v20
Text8.Text = m
Text9.Text = dt
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Else
If p <= 838.5 And p >= 787.5 Then ''''''''''''''''''''787.5~838.5 石油产品
k0 = 594.5418
k1 = 0
pt = p * (1 - 2.3 * 10 ^ (-5) * (t1 - 20) - 2 * 10 ^ (-8) * (t1 - 20) * (t1 - 20))
p15 = pt
Do
p155 = p15
a = k0 / (p155 * p155) + k1 / p155
p15 = pt / Exp(-a * (t1 - 15) * (1 + a * (t1 - 15) * 0.8))
Loop Until Abs(p15 - p155) < 0.005
a = k0 / (p15 * p15) + k1 / p15
p20 = p15 * Exp(-a * 5 * (1 + a * 4))
vcf = Exp(-a * (t2 - 20) * (1 + a * 0.8 * (t2 - 20) + 8 * a))
v20 = vt * vcf
m = (p20 / 1000 - 0.0011) * v20
dt = vcf * (p20 - 1.1)
p20 = Int(p20 * 10 + 0.5) / 10
vcf = Int(vcf * 10000 + 0.5) / 10000
v20 = Int(v20 + 0.5)
m = Int(m + 0.5)
dt = Int(dt * 10 + 0.5) / 10
Text6.Text = vcf
Text5.Text = p20
Text7.Text = v20
Text8.Text = m
Text9.Text = dt
Else
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If p <= 1075 And p >= 838.3 Then ''''''''''''''''''''838.3~1075 石油产品
k0 = 186.9696
k1 = 0.4862
pt = p * (1 - 2.3 * 10 ^ (-5) * (t1 - 20) - 2 * 10 ^ (-8) * (t1 - 20) * (t1 - 20))
p15 = pt
Do
p155 = p15
a = k0 / (p155 * p155) + k1 / p155
p15 = pt / Exp(-a * (t1 - 15) * (1 + a * (t1 - 15) * 0.8))
Loop Until Abs(p15 - p155) < 0.005
a = k0 / (p15 * p15) + k1 / p15
p20 = p15 * Exp(-a * 5 * (1 + a * 4))
vcf = Exp(-a * (t2 - 20) * (1 + a * 0.8 * (t2 - 20) + 8 * a))
v20 = vt * vcf
m = (p20 / 1000 - 0.0011) * v20
dt = vcf * (p20 - 1.1)
p20 = Int(p20 * 10 + 0.5) / 10
vcf = Int(vcf * 10000 + 0.5) / 10000
v20 = Int(v20 + 0.5)
m = Int(m + 0.5)
dt = Int(dt * 10 + 0.5) / 10
Text6.Text = vcf
Text5.Text = p20
Text7.Text = v20
Text8.Text = m
Text9.Text = dt
Else
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If p <= 787.5 And p >= 770.5 Then ''''''''''''''''''''770.5~787.5 石油产品
k0 = 2680.321
k1 = 0
a1 = -0.00336312
pt = p * (1 - 2.3 * 10 ^ (-5) * (t1 - 20) - 2 * 10 ^ (-8) * (t1 - 20) * (t1 - 20))
p15 = pt
Do
p155 = p15
a = k0 / (p155 * p155) + k1 / p155 + a1
p15 = pt / Exp(-a * (t1 - 15) * (1 + a * (t1 - 15) * 0.8))
Loop Until Abs(p15 - p155) < 0.005
a = k0 / (p15 * p15) + k1 / p15 + a1
p20 = p15 * Exp(-a * 5 * (1 + a * 4))
vcf = Exp(-a * (t2 - 20) * (1 + a * 0.8 * (t2 - 20) + 8 * a))
v20 = vt * vcf
m = (p20 / 1000 - 0.0011) * v20
dt = vcf * (p20 - 1.1)
p20 = Int(p20 * 10 + 0.5) / 10
vcf = Int(vcf * 10000 + 0.5) / 10000
v20 = Int(v20 + 0.5)
m = Int(m + 0.5)
dt = Int(dt * 10 + 0.5) / 10
Text6.Text = vcf
Text5.Text = p20
Text7.Text = v20
Text8.Text = m
Text9.Text = dt
Else
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
MsgBox "该密度超出计算范围", vbOKOnly + vbExclamation, ""
End If
End If
End If
End If
End Sub