VB 利用for each...next循环语句,求 1+2+3+...+100的值 .

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/30 07:12:55
VB 利用for each...next循环语句,求 1+2+3+...+100的值 .

VB 利用for each...next循环语句,求 1+2+3+...+100的值 .
VB 利用for each...next循环语句,求 1+2+3+...+100的值 .

VB 利用for each...next循环语句,求 1+2+3+...+100的值 .

需要的控件:

命令按钮,2个,command1,command2

标签,2个,label1,label2

command1代码:

Private Sub Command1_Click()
    Dim A(100) As Variant, B As Variant
    Dim S As Integer
    Dim I As Integer
    For I = 1 To 100
        A(I) = I
    Next
    S = 0
    For Each B In A()
        S = S + B
    Next B
    Label2.Caption = S
End Sub

command2代码:

Private Sub Command2_Click()
    End
End Sub

已经运行过.