请教:怎样vb的do while......loop语句计算1+2+3+.......+100的值?谢谢。

2024-12-04 23:27:45
推荐回答(2个)
回答1:

1. 如果你只是纯粹要达到题目要求

Dim a As Integer
a = 0

do while a<=100
a=a+1
loop

2. 如果你想显示在屏幕上

Dim a As Integer
a = 0

do while a<=100
a = a+1
Print a
Loop

3. 如果你想在用户单机单机窗体是显示出来

Private Sub Command1_Click()

Dim a As Integer
a = 0

do while a<=100
a = a+1
Print a
Loop

End Sub

如果你还有什么想法可以提出来大家讨论一下

回答2:

Dim i As Integer
Dim s As Integer

Do While (i <= 100)
s = s + i
i = i + 1
Loop
MsgBox CStr(s)