Private
Sub
Command1_Click()
Dim
i
As
Integer
Dim
s
As
Integer
s
=
0:
i
=
0
Do
While
i
<=
1000
i
=
i
+
1:
If
i
Mod
2
=
1
Then
s
=
s
+
i
End
If
Loop
Print
"计算1至1000之间的奇数之和为:";
s
End
Sub
没有学过VB但是楼主的程序确实存在问题,这样改一下应该差不多了,对于楼上说的溢出问题就要看整形数的表示范围了。
先把代码发出来,等会在评论中给你解释吧。复制粘贴以下代码:
Option
Explicit
Private
Sub
Command1_Click()
Dim
i
As
Long
Dim
s
As
Long
s
=
0
i
=
0
Do
While
i
<
1000
i
=
i
+
1
If
i
Mod
2
=
1
Then
s
=
s
+
i
End
If
Loop
Print
"计算1至1000之间的奇数之和为:";
s
End
Sub
看运行结果吧