vb用自定义过程求一个数组的总和,急求!谢谢!么么哒!
展开全部
Option Explicit
Private Sub Command1_Click()
Dim MySum As Integer
Dim d(10) As Integer
Dim i As Integer
'为了调用过程,用随机函数给数组赋值
Randomize
For i = 1 To 10
d(i) = Rnd * 100
Next i
me.cls
'显示数组的元素值
For i = 1 To 10
Print d(i); " ";
Next i
Print
'调用该自定义过程,求数组的和
Call 求数组和(d, MySum)
Print "总和:";MySum
End Sub
'自定义过程
Private Sub 求数组和(ByRef d() As Integer, ByRef MyS As Integer)
Dim i As Integer
MyS = 0
For i = LBound(d) To UBound(d)
MyS = MyS + d(i)
Next i
End Sub
Private Sub Command1_Click()
Dim MySum As Integer
Dim d(10) As Integer
Dim i As Integer
'为了调用过程,用随机函数给数组赋值
Randomize
For i = 1 To 10
d(i) = Rnd * 100
Next i
me.cls
'显示数组的元素值
For i = 1 To 10
Print d(i); " ";
Next i
'调用该自定义过程,求数组的和
Call 求数组和(d, MySum)
Print "总和:";MySum
End Sub
'自定义过程
Private Sub 求数组和(ByRef d() As Integer, ByRef MyS As Integer)
Dim i As Integer
MyS = 0
For i = LBound(d) To UBound(d)
MyS = MyS + d(i)
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询