![[填空题] 如果存在如下过程:Private Function Fun(a() As Integer)Dim First As Integer, Last As Integer,i As In,第1张 [填空题] 如果存在如下过程:Private Function Fun(a() As Integer)Dim First As Integer, Last As Integer,i As In,第1张](/aiimages/%5B%E5%A1%AB%E7%A9%BA%E9%A2%98%5D+%E5%A6%82%E6%9E%9C%E5%AD%98%E5%9C%A8%E5%A6%82%E4%B8%8B%E8%BF%87%E7%A8%8B%EF%BC%9APrivate+Function+Fun%28a%28%29+As+Integer%29Dim+First+As+Integer%2C+Last+As+Integer%2Ci+As+In.png)
[填空题] 如果存在如下过程:
Private Function Fun(a() As Integer)
Dim First As Integer, Last As Integer,i As Integer
First=LBound(a)
Last=UBound(a)
Max=a(First)
For i=First To Last
If a(i)> Max Then Max=a(i)
Next
Fun=Max
End Function
在窗体上添加一个命令按钮,然后编写如下事件过程:
Private Sub Command1_Click()
ReDim m(1 To 4)As Integer
m(1)=20: m(2)=30: m(3)=50: m(4)=100
c=Fun(m)
Print C
End Sub
单击命令按钮,其输出结果为 (9) 。
正确答案:100
参考解析:在程序Sub中定义了一个含4个元素的数组,并且分别给它们赋值,数组上界是4,下界为1;将数组m作为实参调用Max事件过程,并将数组m的地址传递给数组a,即此时数组a与m共用一个存储空间;将数组的上界和下界分别赋给变量Last和First,在赋值表达式中分别调用了LBound()函数求数组下界及UBound()函数求数组的上界;在循环语句中,变量的初始值为数组的下界为1,终值为数组的上界为4,循环体是一个条件语句,如果a (i)中的值大于Max,就将a(i)的值赋给Max,当循环结束后,将Max作为函数的返回值,所以此事件过程的功能即为求数组中的最大值。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)