VB除数为0,要怎么改

[复制链接]
查看11 | 回复3 | 2012-5-28 22:29:06 | 显示全部楼层 |阅读模式
If op1.Value = True Then c = 7
Label1.Caption = divsum(c)
If op2.Value = True Then a = 3
Label1.Caption = divsum(a)这两句if....then 都没有end if,相当于每个条件句都只到当行结束。这样,如果op1.value=true时,a实际上等于0,执行到 Label1.Caption = divsum(a)句时就会报错。同理,op1.value=false时,c=0,执行Label1.Caption = divsum(c)当然也会出错。把这段改成:If op1.Value...
回复

使用道具 举报

千问 | 2012-5-28 22:29:06 | 显示全部楼层
'd=0肯定就不用算吧,加一句退出Public Function divsum(d As Integer)
Dim i As Integer, o As Integer
if d=0 then divsum=0:exit function '退出,结果为0
o = 0
For i = 500 To 600 ...
回复

使用道具 举报

千问 | 2012-5-28 22:29:06 | 显示全部楼层
Dim c As Integer, a As IntegerPublic Function divsum(d As Integer)
Dim i As Integer, o As Integer
o = 0
For i = 500 To 600
If i Mod d = 0 Then o = o + i...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行