我用vb6编写一个计算物理中加速度的程序,可是在运行阶段说:实时错误:6溢出。怎么办啊?求解!高手
Dima,b,c,xAsIntegerPrivateSubCommand1_Click()Text1.Text=aText2.Text=bText3.Text=cx=(a...
Dim a, b, c, x As Integer
Private Sub Command1_Click()
Text1.Text = a
Text2.Text = b
Text3.Text = c
x = (a - b) / c
Text4.Text = x
End Sub 展开
Private Sub Command1_Click()
Text1.Text = a
Text2.Text = b
Text3.Text = c
x = (a - b) / c
Text4.Text = x
End Sub 展开
2个回答
展开全部
因为除数c=0或太接近0,得到的x>32767(这是Integer所能存储的最大数),所以这样写可能更好:
Dim a, b, c, x As Double
Private Sub Command1_Click()
Text1.Text = a
Text2.Text = b
Text3.Text = c
if c=0 then
msgbox "除数c为0",vbCritical
else
x = (a - b) / c
end if
Text4.Text = x
End Sub
Dim a, b, c, x As Double
Private Sub Command1_Click()
Text1.Text = a
Text2.Text = b
Text3.Text = c
if c=0 then
msgbox "除数c为0",vbCritical
else
x = (a - b) / c
end if
Text4.Text = x
End Sub
更多追问追答
追答
因为数学中一般除数不能为0,比如1/0这种式子在初等数学中认为没有意义,电脑也一样,所以要避开这样的错误。如果你不希望弹出这样的报错对话框,那就改成:
Dim a, b, c, x As Double
Private Sub Command1_Click()
On Error Resume Next
Text1.Text = a
Text2.Text = b
Text3.Text = c
x = (a - b) / c
Text4.Text = x
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询