vb 中实时错误‘13’类型不匹配

来源:百度知道 编辑:UC知道 时间:2024/05/22 15:47:25
Private Sub Text1_Change(Index As Integer)
Text1(15).Text = 0.5 * Val(Text1(1).Text) + 0.5 * Val(Text1(2).Text) + 0.5 * Val(Text1(3).Text) + 0.5 * Val(Text1(4).Text) + 0.2 * Val(Text1(5).Text) + 0.2 * Val(Text1(6).Text) + 0.2 * Val(Text1(7).Text) + 0.2 * Val(Text1(8).Text) + 0.2 * Val(Text1(9).Text) + Val(Text1(10).Text * 0.3) + 0.3 * Val(Text1(11).Text) + 0.3 * Val(Text1(12).Text) + 0.3 * Val(Text1(13).Text) + 0.3 * Val(Text1(14).Text)
End Sub

程序如上,我的同学用同样的方法和同样的窗体设计能运行成功,不知道我什么地方出错了,望各位vb高手指教,谢谢您了。

问题出在“+ Val(Text1(10).Text * 0.3)”你输入错误,应该是
+ Val(Text1(10).Text )* 0.3

Private Sub Text1_Change(Index As Integer)
Text1(15).Text = 0.5 * Val(Text1(1).Text) + 0.5 * Val(Text1(2).Text) + 0.5 * Val(Text1(3).Text) + 0.5 * Val(Text1(4).Text) + 0.2 * Val(Text1(5).Text) + 0.2 * Val(Text1(6).Text) + 0.2 * Val(Text1(7).Text) + 0.2 * Val(Text1(8).Text) + 0.2 * Val(Text1(9).Text) + 0.3*Val(Text1(10).Text ) + 0.3 * Val(Text1(11).Text) + 0.3 * Val(Text1(12).Text) + 0.3 * Val(Text1(13).Text) + 0.3 * Val(Text1(14).Text)
End Sub
这样改一下就好了。

Private Sub Text1_Change(Index As Integer)
dim i as integer,c as double,sum as double
for i=1 to 14
if i<=4 then
c= 0.5
elseif i>4 and i<=9 then
c=0.2
else
c=0.3
end if
sum=sum+c*val(text1(i))
next i
End Sub
这样写,是不是简单一些?而且很清晰。

还可以简化的:
Private Sub Text1_Change(Index As Integer)
dim i as integer,c as double,sum as double
for