Private Sub Command1_Click()
Dim i As Integer
Dim s As Integer
Dim L As Integer
Dim n As Integer
L = 0
s = 0
n = InputBox("请输入1个自然数")
For i = 1 To n
L = L + i
s = s + L
Next i
Print s
End Sub
注释:在窗体的单击事件写如下代码,S 为输出结果
Private sub form1_click()
N = InputBox("请输入求和项N:")
For i = 1 To N
A =A + i
S = S + A
Next i
Print A
end sub
Private Sub Command1_Click()
Dim n As Integer, s As Integer, p As Integer
n = Val(Text1.Text)
For i = 1 To n
p = p + i
s = s + p
Next j
MsgBox "结果是:" & Str(s)
End Sub
Private Sub Command1_Click()
Dim i, n, s As Integer
n = Val(Text1.Text)
s = 0
For i = n To 0 Step -1
s = s + i * (i + 1) / 2
Next i
Text2.Text = s
End Sub