急!!!!VB编程求1加到100的和,5种方法!!!!!

2024-12-25 23:43:19
推荐回答(1个)
回答1:

Option Explicit

Private Sub Command1_Click()
Dim i As Integer, s As Integer
For i = 1 To 100
s = s + i
Next
Print s
End Sub

Private Sub Command2_Click()
Dim i As Integer, s As Integer
Do While i <= 100
s = s + i
i = i + 1
Loop
Print s
End Sub

Private Sub Command3_Click()
Dim i As Integer, s As Integer
Do
i = i + 1
s = s + i
Loop While i <= 99
Print s
End Sub

Private Sub Command4_Click()
Dim i As Integer, s As Integer
While i <= 100
s = s + i
i = i + 1
Wend
Print s
End Sub

Private Sub Command5_Click()
Dim i As Integer, s As Integer
GOTONEXT:
s = s + i
i = i + 1
If i <= 100 Then GoTo GOTONEXT
Print s
End Sub