关键代码如下,按钮1点击
Private Sub Command1_Click()
Dim n As Integer, sum As Integer, i As Integer
n = CInt(Text1.Text)
For i = 1 To n
sum = sum + i
Next i
Text2.Text = sum
End Sub
截图
按纽click事件dim i as integerdim sum as integerdim n as integern = val(text1.value)sum = 0for i = 1 to nsum = sum + inexttext2.value = str(sum)大体上这样,好久没用VB了,转换函数也忘了
Private Sub Command1_Click()
Dim a As Integer
a = Val(Text1.Text)
Sum = 0
For k = 1 To a
Sum = Sum + k '累加
Next k
Text2.Text = Sum
End Sub