1.建立一个EXE工程,在默认窗体上放置标签,文本框和按钮如图26。
图26
- 输入代码:
Sub Form1_Command1_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd)
Dim Score1(3) As Single, Score2(4) As Single
Score1(0)=90:Score1(1)=80:Score1(2)=78
Score2(0) = 100 : Score2(1) = 77 : Score2(2) = 97 : Score2(3) = 85
Text1.Text = Average(Score1(),3)'注意在传递数组参数时不要遗漏括号
Text2.Text=Average(Score2(),4)
End Sub
Function Average(stuArray() As Single, n As Integer) As Single
Dim i As Integer
Dim aver As Single, sum As Single
For i As Integer = 0 To n -1
sum=sum+stuArray(i)
Next
aver = sum / n
Average=aver
End Function