在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程: Option Base 1 Private Sub Command1_Click() Dim a As Variant Dim i As Integer, m As Integ

admin2015-06-30  21

问题 在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程:
Option Base 1
Private Sub Command1_Click()
  Dim a As Variant
  Dim i As Integer, m As Integer, index As Integer
  a = Array(-10, 23, -50, 90)
  m = a(LBound(A))
  index = LBound(A)
  For i = LBound(A) To UBound(A)
      If a(i) < m Then
         m = a(i)
         index = i
      End If
  Next i
  Print index
End Sub
程序运行时,单击Command1,则在窗体上输出的结果是

选项 A、0
B、1
C、2
D、3

答案D

解析 UBound函数返回为指定的数组维可用的最大下标,LBound函数返回为指定的数组维可用的最小下标。程序开头定义了Option Base 1这时定义一维数组下标从1开始;故LBound(A)=1,Ubound(A)=4;m = a(LBound(A))=a(1)=-10,index=LBound(A)=1。If 条件 Then部分,如果选择的条件为真,则执行then部分;For i=1 To 4,当i=1时,if条件a(i)=a(1)=-10<-10为假,不执行then部分;当i=2时,if条件a(i)=a(2)=23<-10为假,不执行then部分;当i=3时,if条件a(i)=a(3)=-50<-10为真,执行then部分,m=a(3)=-50,接着执行index=i=3;当i=4时,if条件a(i)=a(4)=90<-10为假,不执行then部分;外层for循环结束,故index=3。本题正确选项为D。
转载请注明原文地址:https://kaotiyun.com/show/vVQp777K
0

最新回复(0)