通过调用过程Average求数组的平均值,请装入该文件。使得程序运行后,在四个文本框中各输入一个整数,然后单击命令按钮,即可求出数组的平均值,并在窗体上显示出来.代码如下:
Option Base 1
Private Function average(a() As Integer) As Single
Dim start As Integer, finish As Integer
Dim i%, sum%
sum = 0
start = LBound(a)
finish = UBound(a)
For i = start To finish
sum = sum + a(i)
Next
average = sum / finish
End Function
Private Sub Command1_Click()
Dim arr1()
Dim arr2(4) As Integer
arr1(4) = Array(Val(Text1.Text), Val(Text2.Text), _
Val(Text1.Text), Val(Text2.Text))
For i = 1 To 4
arr2(i) = CInt(arr1(i))
Next
m = average(arr2(i))
Print m
End sub
为啥运行时系统提示“类型不匹配”