2004年4月全国计算机等级考试二级VB笔试试卷(附参考答案)

出处:考试大 作者:onmars 日期:2007年07月18日 14时16分
     

(21) 在窗体上画一个命令按钮(其NAME属性为Command1),然后编写如下代码:
Option Base 1
Private Sub Command1_Click()
 Dim a
 s = 0
 a = Array(1,2,3,4)
 j = 1
 For i = 4 To 1 Step -1
 s = s + a(i) * j
 j = j * 10
 Next i
 Print s
End Sub
运行上面的程序,单击命令按钮,其输出结果是
A) 4321 B) 1234 C) 34 D) 12
(22) 在窗体上画一个名称为Text1的文本框,要求文本框只能接收大写字母的输入。以下能实现该操作的事件过程是
A) Private Sub Text1_KeyPress(KeyAscii As Integer)
 If KeyAscii < 65 Or KeyAscii > 90 Then
 MsgBox "请输入大写字母"
 KeyAscii = 0
 End If
End Sub
B) Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
 If KeyCode < 65 Or KeyCode > 90 Then
 MsgBox "请输入大写字母"
 KeyCode = 0
 End If
End Sub
C) Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
 If Asc(Text1.Text) < 65 Or Asc(Text1.Text) > 90 Then
 MsgBox "请输入大写字母"
 End If
End Sub
D) Private Sub Text1_Change()
 If Asc(Text1.Text) > 64 And Asc(Text1.Text) < 91 Then
 MsgBox "请输入大写字母"
 End If
End Sub
(23) 假定在窗体(名称为Form1)的代码窗口中定义如下记录类型:
Private Type animal
 AnimalName As String*20
 AColor As String*10
End Type
在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程:
Private Sub Command1_Click()
 Dim rec As animal
 Open "c:\vbTest.dat" For Random As #1 Len = Len(rec)
 rec.animalName = "Cat"
 rec.aColor = "White"
 Put #1, , rec
 Close #1
End Sub
则以下叙述中正确的是
A) 记录类型animal不能在Form1中定义,必须在标准模块中定义
B) 如果文件c:\vbTest.dat不存在,则Open命令执行失败
C) 由于Put命令中没有指明记录号,因此每次都把记录写到文件的末尾
D) 语句“Put #1, , rec”将animal类型的两个数据元素写到文件中
(24) 在窗体上画一个名称为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
 f2=x+x+x
End Function       

最后更新时间:2008-03-28 12:57:08
文章评论
共有 0 位网友发表了评论
用户名: 新注册) 密码: 匿名评论 [查看所有评论]

评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
您可以用以下几种方式找到此文章

考试全流程