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

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

2016-6-18编辑:ljnbset

1.       有如下一个函数过程:

  Function Func (ByVal Num As Long )

   Dim k As Long

   k=1

   Num = Abs (Num)

   Do While ( Num)

    k = k * (Num Mod 10)

    Num = Num \ 10

   Loop

   Func = k

  End Function

 以下是一个调用该函数的事件过程,在运行该过程后,在输入对话框中输入“2345”,则该过程的运行结果是( 【78】 )

  Private Sub Command1_Click( )

   Dim n As Long , r As Long

   n = InputBox ( “请输入数据:” )

   n = CLng ( n )       ‘CLng函数的返回值是一个长整型数值

   r = Func ( n )

      Print r

  End Sub

 (A)0     (B)24     (C)60     D120

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

Private Sub Command1_Click()

n = Val(Text1.Text)

Select Case n

Case 1 To 20

x = 10

Case 2, 4, 6

x= 20

Case Is < 10

x = 30

Case 10

x = 40

End Select

Text2.Text = x

End Sub

程序运行后,如果在文本框Text1中输入10,然后单击命令按钮,则在Text2中显示的内容是

A10      (B)20      (C)30       (D)40

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

Private Sub Command1_Click()

  N=Val(Text1.Text)

  If n \ 2 = n / 2 Then

    f=f1(N)

  Else

    F=f2(N)

  End If

  Print f; n

End Sub

Public Function f1(ByRef x)

  x = x * x

  f1=x + x

End Function

Public Function f2(ByVal x)

  x = x * x

  f1=x + x + x

End Function

程序运行后,在文本框中输入6,然后单击命令按钮,窗体上显示的是( 【79】 )

 (A)72  6   (B)108  6   C72  36   (D)108  36

4.       设在工程中有一个标准模块,其中定义了如下记录类型

  Type Books

   Name As String * 10

   TelNum As String * 20

  End Type

 在窗体上画一个名为Command1的命令按钮,要求当执行事件过程Command1_Click( )时,在顺序文件Ks74 . Txt中写入一条记录。下列能够完成该操作的事件过程是( 【79】 )

 (APrivate Sub Command1_Click( )

Dim b As Books

Open “D:\Vb2003Ks\Ks74.Txt” For OutPut As #1

b.Name = InputBox ( “输入姓名”)

b.TelNum = Inputbox ( “输入电话号码”)

Write #1 , b.Name , b.TelNum

Close #1

End Sub

(B)Private Sub Command1_Click( )

Dim b As Books

Open “D:\Vb2003Ks\Ks74.Txt” For InPut As #1

b.Name = InputBox ( “输入姓名”)

b.TelNum = Inputbox ( “输入电话号码”)

Print #1 , b.Name , b.TelNum

Close #1

End Sub

(C)Private Sub Command1_Click( )

Dim b As Books

Open “D:\Vb2003Ks\Ks74.Txt” For OutPut As #1

b.Name = InputBox ( “输入姓名”)

b.TelNum = Inputbox ( “输入电话号码”)

Write #1 , b

Close #1

End Sub

(D)Private Sub Command1_Click( )

Dim b As Books

Open “D:\Vb2003Ks\Ks74.Txt” For InPut As #1

b.Name = InputBox ( “输入姓名”)

b.TelNum = Inputbox ( “输入电话号码”)

Print #1 , Name , TelNum

Close #1

End Sub

5.       在窗体上画一个名称为Text1的文本框,并编写如下程序:

Private Sub Form_Load()

Show

Text1.Text = ""

Text1.SetFocus

End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

Print "程序设计"

End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)

Print "Visual Basic";

End Sub

程序运行后,如果按"A"键,然后单击窗体,则在窗体上显示的内容是

(A)Visual Basic         (B)程序设计

(C)A程序设计          DVisual Basic程序设计

6.       下列程序运行后,运行结果不是144的程序是( 【80】 )

(A)Dim z As Integer              (B)Dim x As Integer

    Private Sub Form_Click( )                       Private Sub Form_Click( )

     x=12                                         x=12

     Call Fun ( x )                                  Call Fun ( x , z)

     Print z                                        Print z 

    End Sub                                      End Sub

    Sub Fun ( y )                                  Sub Fun ( y , z )

     z = y * y                                      z = y * y 

    End Sub                                      End Sub 

CPrivate Sub Form_Click( )                  (D)Private Sub Form_Click( )

         x=12                                         x=12

         Call Fun ( x )                                  Call Fun ( x , z )

         Print z                                        Print z

       End Sub                                      End Sub

       Sub Fun ( Byref  y )                             Sub Fun ( Byref  y , z )

         z = 12 * 12                                    z = y * y

       End Sub                                      End Sub

7.       设有如下程序:

Private Sub Command1_Click()

Dim sum As Double, x As Double

sum = 0

n = 0

For i = 1 To 5

x = n / i

n = n + 1

sum = sum + x

Next

End Sub

该程序通过For循环计算一个表达式的值,这个表达式是

(A)1+1/2+ 2/3+3/4+4/5       (B)1+1/2+2/3+3/4

C1/2+2/3+3/4+4/5        (D)1+1/2+1/3+1/4+1/5

8.       程序如下:

  Private Sub Form_Click( )

   Dim a As Integer , b As Integer

   a = 5 : b = 8

   Call Fun (a , b)

   Print a , b

  End Sub

    Private Sub Fun ( x As Integer , y As Integer )

   x = x * y

   y = y * x

  End Sub

 程序运行时,单击窗体后,在窗体上输出的结果为( 【81】 )

 (A)5  8   (B)40 40   (C)40 8   D40 320

9.       在窗体上画一个命令按钮,然后编写如下事件过程:

  Private Sub Command1_Click( )

   x=0

   For i=1 to 3

    x=1

    For j=1 to 4

     x=2

     For k=1 to 5

      x = x + 2

     Next k

    Next j

   Next i

   Print x

  End Sub

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

 (A12    (B)24    (C)36    (D)48

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

  Private Type Record

   ID As Integer

   Name As String * 20

  End Type

  Private Sub Command1_Click( )

   Dim MaxSize , NextChar , MyChar

   Open “D:\Vb2003Ks\Ks78.Dat ” For Binary As #1

   MaxSize = LOF ( 1 )

   For NextChar = MaxSize To 1 Step -1

    Seek # 1 , NextChar

    MyChar = Input ( 1 , # 1 )

   Next NextChar

   Print EOF ( 1 )

   Close # 1

  End Sub

 程序运行后,单击命令按钮,其输出结果为( 【83】 )

 (A)True    BFalse    (C)Null    (D)0

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

热点推荐

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