在窗体上画一个名称为Command1的命令按钮,然后编写如下程序代码: Private Sub Command1_Click() Dim a(5) As String Dim i As Integer Dim b As Variant Fo

admin2015-09-23  41

问题 在窗体上画一个名称为Command1的命令按钮,然后编写如下程序代码:
Private Sub Command1_Click()
  Dim a(5) As String
  Dim i As Integer
  Dim b As Variant
  For i = LBound(a) To UBound(a)
      a(i) = Chr(Asc("a") + (26 - i))
  Next i
  For Each b In a
      Print b;
  Next
End Sub
程序运行时,单击Command1,则输出结果是(    )。

选项 A、12345
B、abcde
C、zyxwv
D、出错

答案C

解析 "Option Base 1"表示数组下标从1开始,LBound函数和UBound函数分别得到数组下标的下界值和上界值。Asc(x$)返回字符串x$中第一个字符的ASCII码,Chr$(x)把x的值转换为相应的ASCII字符。For循环中,循环变量i=LBound(a)=1 to UBound(a)=5,循环共执行5次。当i=1时,a(1)= Chr(Asc("a") + (26 - 1))="z";当i=2时,a(2)= Chr(Asc("a") + (26 -2))="y";当i=3时,a(3)= Chr(Asc("a") + (26 - 3))="x";当i=4时,a(4)= Chr(Asc("a") + (26 - 4))="w";当i=5时,a(5)= Chr(Asc("a") + (26 -5))="v";最后通过For each循环输出数组元素的值,故选项C正确。
转载请注明原文地址:https://kaotiyun.com/show/ELLp777K
0

最新回复(0)