VB中如何计算数值数组中各元素值之和
发布网友
发布时间:2022-06-26 11:43
我来回答
共3个回答
热心网友
时间:2024-11-16 21:26
Option Explicit
Option Base 1
Private Sub Form_Activate()
Dim a(5), sum As Integer, i As Integer
a(1) = 1: a(2) = 2: a(3) = 3: a(4) = 4: a(5) = 5
For i = 1 To 5
sum = sum + a(i)
Next
MsgBox Join(a, "+") & "=" & sum
Unload Me
End Sub
热心网友
时间:2024-11-16 21:26
Private Sub Command1_Click()
Dim a() As Integer
n = 5 '假设为输入5个
For i = 1 To n '
ReDim a(i)
a(i) = Val(InputBox("请输入数字"))
Sum = Sum + a(i)
Next
Print Sum
End Sub
热心网友
时间:2024-11-16 21:27
Private Sub Command1_Click()Dim i, s, a(5) As Integera(1) = 1a(2) = 2a(3) = 3a(4) = 4a(5) = 5s = 0For i = 1 to 5 s = s + a(i)NextPrint sEnd Sub