计算机等级 > 二级考试 > Visual Basic > VB模拟试题 > 文章内容

全国计算机二级考试VB程序设计复习试题答案(13)

2016-6-18编辑:ljnbset

1. 在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程:

Private Sub Command1_Click()

Dim num As Integer

num = 1

Do Until num > 6

Print num;

num = num + 2.4

Loop

End Sub

程序运行后,单击命令按钮,则窗体上显示的内容是

(A)1  3.4  5.8   B1  3  5  (C)1  4  7  (D)无数据输出

2. 有如下函数:

  Function Facn ( x As Integer ) As Long

   Dim p As Long , i As Integer

   p = 1

   For i = 1 To x

    p = p * i

   Next i

   Facn = p

  End Function

 调用它的事件过程如下:

  Private Sub Command1_Click ( )

   i = Val ( InputBox ( “请输入数据”))

   a = Facn (( i ) )                ‘实参i用圆括号括起,则强制为值传递

   Print a

  End Sub

 若输入数据6,则程序运行结果为( 【73】 )

 (A)60     (B)120     (C)600     D720

3. 在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程:

Private Sub Command1_Click()

Dim a As Integer, s As Integer

a = 8

s = 1

Do

s = s + a

a = a-1

Loop While a <= 0

Print s; a

End Sub

程序运行后,单击命令按钮,则窗体上显示的内容是

(A) 7  9      (B) 34  0      C 9  7      (D)死循环

4. 下列程序的执行结果为( 【74】 )

   Dim IntSum As Integer , i As Integer

   IntSum = 0

   For i = 30.2 To 1 Step -5.3

    IntSum = IntSum + i

   Next i

   Print IntSum

 (A)106    B105    (C)102    (D)101

5. 在窗体上画一个命令按钮,然后编写如下事件过程,该过程执行结果为( 【75】 )

  Option Base 1

Private Sub Command1_Click ( )

   Dim a As Variant , s As Integer

   a = Array ( 2 , 4 , 6 , 8 )

   j = 1

   For i = 1 To 4 Step 1

    s = s + a ( i ) * j

    j = j *10

   Next i

   Print s

  End Sub

 (A)0    (B)1110    (C)2468    D8642

设有如下通用过程:

Public Function f(x As Integer)

Dim y As Integer

x = 20

y = 2

f = x * y

End Function

6. 在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程:

Private Sub Command1_Click()

Static x As Integer

x = 10

y=5

y = f(x)

Print x; y

End Sub

程序运行后,如果单击命令按钮,则在窗体上显示的内容是

(A)10  5    (B)20  5   C20  40    (D)10 40

7. 对窗体编写如下代码:

  Option Base 1

  Private Sub Form_KeyPress( KeyAscii As Integer)

   a = Array (123 , 86 , 57 , 248 , 32)

   m1 = a ( 1 )

   m2 = 1

   If KeyAscii = 13 Then

    For i=2 To 5

     If a ( i ) > m1 Then

      m1 = a ( i )

      m2 = i

     End If

    Next i

   End If

   Print m1 , m2

  End Sub

 程序运行后,按回车键,输出结果为( 【76】 )

 (A)32  5   B248  4   (C)32  1   (D)248  5

设有如下通用过程:

Public Sub Fun(a(), ByVal x As Integer)

For i = 1 To 5

x = x + a(i)

Next

End Sub

8. 在窗体上画一个名称为Text1的文本框和一个名称为Command1的命令按钮,然后编写如下的事件过程:

Private Sub Command1_Click()

Dim arr(5) As Variant

For i = 1 To 5

arr(i) = i

Next

n = 10

Call Fun(arr(), n)

Text1.Text = n

End Sub

程序运行后,单击命令按钮,则在文本框中显示的内容是

A10     (B)15      (C)25      (D)24

9. 阅读程序:

  Function Func ( a As Integer )

   b = 1

   Static c As Integer

   b = b +1

   c = c +1

   Func = a + b + c

  End Function

  Private Sub Command1_Click( )

   Dim a As Integer

   a = 3

   For i =1 to 3

    Print Func( a )

   Next i

  End Sub

 运行上面的程序,单击命令按钮后,输出结果为( 【77】 )

 A6      (B)6     (C)6             (D)6

    7               6               8                  13

       8               6               10                 21

10.   在窗体上画一个名称为Command1的命令按钮,然后编写如下代码:

Option Base 1

Private Sub Command1_Click()

d = 0

c = 10

x = Array(10, 12, 21, 32, 24)

For i = 1 To 5

If x(i) > c Then

d = d + x(i)

c = x(i)

Else

d = d-c

End If

Next i

Print d

End Sub

程序运行后,如果单击命令按钮,则在窗体上输出的内容为

(A)89     (B)99     C23     (D)77

全国计算机二级考试VB程序设计复习试题答案(12)

热点推荐

登录注册
触屏版电脑版网站地图