vba, 提示 编译错误:类型声明文字与声明的数据类型不符
SubPKLength1()DimQAsInteger,t1AsInteger,EAsLong,vAsDouble,uAsInteger,HAsDouble,VspAsB...
Sub PKLength1()
Dim Q As Integer, t1 As Integer, E As Long, v As Double, u As Integer, H As Double, Vsp As Byte, Cw As Double
Dim l1 As Double, Vl1 As Double, Vf1 As Double, deltaV As Double
Q = Sheet1.[C2]
t1 = Sheet1.[B8]
E = Sheet1.[C4]
v = Sheet1.[F4]
u = Sheet1.[F2]
H = Sheet1.[C3]
Vsp = Sheet1.[C5]
Cw = Sheet1.[F3]
l1 = 51.5 * Q^(6 / 10) * t1^(8 / 10) * E^(2 / 10) / ((1 - v * v) ^ (2 / 10) * u^(2 / 10) * H^(8 / 10))
Do
Vl1 = 4 * Vsp * l1 * H + (8 * Cw * l1 * H * Sqr(t1)) ^ 0.2
Vf1 = 0.04 * H * l1^(5 / 4) * (1 - v * v) ^ (1 / 4) * u^(1 / 4) * (Q * t1 - Vl1) ^ (1 / 4) / E^(1 / 4)
deltaV = Q * t1 - Vl1 - Vf1
Select Case deltaV
Case Is > 0.05: l1 = l1 + 0.1
Case Is < 0: l1 = l1 - 0.1
Case Else: Exit Do
End Select
Loop While deltaV > 0.05 Or deltaV < -0.05
Sheet1.[C9] = l1
End Sub
改了好几遍,总是出现这句提示,求大侠指导到底哪里出问题了 展开
Dim Q As Integer, t1 As Integer, E As Long, v As Double, u As Integer, H As Double, Vsp As Byte, Cw As Double
Dim l1 As Double, Vl1 As Double, Vf1 As Double, deltaV As Double
Q = Sheet1.[C2]
t1 = Sheet1.[B8]
E = Sheet1.[C4]
v = Sheet1.[F4]
u = Sheet1.[F2]
H = Sheet1.[C3]
Vsp = Sheet1.[C5]
Cw = Sheet1.[F3]
l1 = 51.5 * Q^(6 / 10) * t1^(8 / 10) * E^(2 / 10) / ((1 - v * v) ^ (2 / 10) * u^(2 / 10) * H^(8 / 10))
Do
Vl1 = 4 * Vsp * l1 * H + (8 * Cw * l1 * H * Sqr(t1)) ^ 0.2
Vf1 = 0.04 * H * l1^(5 / 4) * (1 - v * v) ^ (1 / 4) * u^(1 / 4) * (Q * t1 - Vl1) ^ (1 / 4) / E^(1 / 4)
deltaV = Q * t1 - Vl1 - Vf1
Select Case deltaV
Case Is > 0.05: l1 = l1 + 0.1
Case Is < 0: l1 = l1 - 0.1
Case Else: Exit Do
End Select
Loop While deltaV > 0.05 Or deltaV < -0.05
Sheet1.[C9] = l1
End Sub
改了好几遍,总是出现这句提示,求大侠指导到底哪里出问题了 展开
2个回答
展开全部
哪句有问题,看不出呢
更多追问追答
追问
运行的时候提示这句
l1 = 51.5 * Q^(6 / 10) * t1^(8 / 10) * E^(2 / 10) / ((1 - v * v) ^ (2 / 10) * u^(2 / 10) * H^(8 / 10))
有编译错误,如果把^和*这些运算去掉,改成加减,就不出现那句提示,实在是搞不懂为什么
追答
可能是单元格里边的数据有问题,比如有空格等。能把文件发给我吗(个人资料里有QQ),帮你分析分析
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
下面两行是你的申明语句:
Dim Q As Integer, t1 As Integer, E As Long, v As Double, u As Integer, H As Double, Vsp As Byte, Cw As Double
Dim l1 As Double, Vl1 As Double, Vf1 As Double, deltaV As Double
你什么的变量都有特定的类型,例如Q就是Integer类型,那么凡是使用中给它赋值字符或者超过范围(65536)的数值都会出错。例如你的语句:
Q = Sheet1.[C2]
如果C2的类型不是Integer兼容的,就会报错。
解决方法一是单步执行查看错误的语句,然后追踪表格数据,看看错误原因。
另外,可以去申明语句中的类型,例如:
Dim Q , t1 , E , v , u , H , Vsp , Cw
Dim l1 , Vl1 , Vf1 , deltaV
Dim Q As Integer, t1 As Integer, E As Long, v As Double, u As Integer, H As Double, Vsp As Byte, Cw As Double
Dim l1 As Double, Vl1 As Double, Vf1 As Double, deltaV As Double
你什么的变量都有特定的类型,例如Q就是Integer类型,那么凡是使用中给它赋值字符或者超过范围(65536)的数值都会出错。例如你的语句:
Q = Sheet1.[C2]
如果C2的类型不是Integer兼容的,就会报错。
解决方法一是单步执行查看错误的语句,然后追踪表格数据,看看错误原因。
另外,可以去申明语句中的类型,例如:
Dim Q , t1 , E , v , u , H , Vsp , Cw
Dim l1 , Vl1 , Vf1 , deltaV
更多追问追答
追答
应该保留适当的空格,例如下面这样:
l1 = 51.5 * Q ^ (6 / 10) * t1 ^ (8 / 10) * E ^ (2 / 10) / ((1 - v * v) ^ (2 / 10) * u ^ (2 / 10) * H ^ (8 / 10))
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询