全国计算机二级考试VB程序设计复习试题答案(14)
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 (D)120
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中显示的内容是
(A)10 (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 (C)72 36 (D)108 36
4. 设在工程中有一个标准模块,其中定义了如下记录类型
Type Books
Name As String * 10
TelNum As String * 20
End Type
在窗体上画一个名为Command1的命令按钮,要求当执行事件过程Command1_Click( )时,在顺序文件Ks74 . Txt中写入一条记录。下列能够完成该操作的事件过程是( 【79】 )
(A)Private Sub Command1_Click( )
Dim b As Books
Open “D:Vb2003KsKs74.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:Vb2003KsKs74.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:Vb2003KsKs74.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:Vb2003KsKs74.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程序设计 (D)Visual Basic程序设计
6. 下列程序运行后,运行结果不是144的程序是( 【80】 )
(A)Dim z As Integer (B)Dim x As Integer
Private Sub Form_Click( ) Private Sub Form_Click( )首页 1 2 3 尾页