vb程序出现 实时错误 6 什么意思
Subjiecheng(n)DimiAsIntegerDimsAsIntegers=1i=1Fori=1Tons=s*i-------------此行提示实时错误6Nex...
Sub jiecheng(n)
Dim i As Integer
Dim s As Integer
s = 1
i = 1
For i = 1 To n
s = s * i -------------此行提示实时错误 6
Next i
Text1.Text = s
End Sub
Private Sub Command1_Click()
Call jiecheng(5)
End Sub
Private Sub Command2_Click()
Call jiecheng(9)
End Sub
Private Sub Command3_Click()
Call jiecheng(12)
End Sub 展开
Dim i As Integer
Dim s As Integer
s = 1
i = 1
For i = 1 To n
s = s * i -------------此行提示实时错误 6
Next i
Text1.Text = s
End Sub
Private Sub Command1_Click()
Call jiecheng(5)
End Sub
Private Sub Command2_Click()
Call jiecheng(9)
End Sub
Private Sub Command3_Click()
Call jiecheng(12)
End Sub 展开
5个回答
展开全部
运算溢出,
计算阶乘,要定义为 双精度型,double
Sub jiecheng(n) as double
Dim i As Integer
Dim s As double
s = 1
For i = 1 To n
s = s * i
Next i
jiecheng = s
End Sub
计算阶乘,要定义为 双精度型,double
Sub jiecheng(n) as double
Dim i As Integer
Dim s As double
s = 1
For i = 1 To n
s = s * i
Next i
jiecheng = s
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
整数型(Integer)最大到65535,而Command2_Click()和Command3_Click()两个事件的运算结果超出最大值了.
建议变量定义为单精度型
Dim i As Single
Dim s As Single
建议变量定义为单精度型
Dim i As Single
Dim s As Single
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Sub jiecheng(n As Integer)
Dim i As Integer
Dim s As Double
s = 1
i = 1
For i = 1 To n
s = s * i
Next i
Text1.Text = s
End Sub
Private Sub Command1_Click()
Call jiecheng(5)
End Sub
Private Sub Command2_Click()
Call jiecheng(9)
End Sub
Private Sub Command3_Click()
Call jiecheng(12)
End Sub
9的阶乘是:362880
12的阶乘是:479001600
它们都超出了Integer(整型变量的范围)
所以提示实时错误 6(溢出)
所以可以定义s变量为double(双精度类型)
Dim i As Integer
Dim s As Double
s = 1
i = 1
For i = 1 To n
s = s * i
Next i
Text1.Text = s
End Sub
Private Sub Command1_Click()
Call jiecheng(5)
End Sub
Private Sub Command2_Click()
Call jiecheng(9)
End Sub
Private Sub Command3_Click()
Call jiecheng(12)
End Sub
9的阶乘是:362880
12的阶乘是:479001600
它们都超出了Integer(整型变量的范围)
所以提示实时错误 6(溢出)
所以可以定义s变量为double(双精度类型)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我要回答的和yfv2000一样。你可以
Dim i As Integer
Dim s As Long
数值会大一些
Dim i As Integer
Dim s As Long
数值会大一些
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
n的值从哪来。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询