2011年12月考试可视化程序设计(VB)第三次作业
一、填空题(本大题共60分,共 15 小题,每小题 4 分)
1.要使用状态栏控件设计状态栏,应首先在“部件”对话框中选择 Microsoft Windows Common Controls 6.0 ,然后从工具箱中选择 StatusBar 控件。
2.对象的边框类型由 BorderStyle 属性设置。
3.VB的每个菜单项都有一个下拉菜单,含有若干个 菜单 命令。用鼠标单击某个菜单项就执行相应的菜单命令。
4.菜单的热键指使用 Alt 键和菜单项标题中的一个字符来打开菜单。建立热键的方法是在菜单标题的某个字符前加上一个 & 符号,在菜单中这一字符会自动加上 下划线 ,表示该字符是一个热键字符。
5.运行时,要使工具栏控件Toolbarl中的第二个按钮的按钮菜单中的第三项无效(变成灰色),应使用语句:Toolbarl.Buttons(2).ButtonMenus(3).Enabled=False。
6.根据文件内容区分,文件分为 程序文件 和 数据文件 。
7.当使用Format函数与Print方法一起输出时,格式字符串中的”#”号表示一个数字位,它的个数决定 显示数据 的长度,若要显示的数据位数大于这个长度,则显示时数据按 原样 显示。
8.菜单在运行时的动态增减主要通过控件数组实现,首先将菜单项的 Visible 属性设为False,然后在程序中用Load 语句加载。
9.如果将工程的启动对象设置成 Main 子程序,则程序启动时可以不加载任何窗体。
10.要从字符串“Visual Basic 6.0”中截取子字符串“Basic”可使用的函数是 Mid(“Visual Basic 6.0”,8,5) 。
11.要在运行时给状态栏 StatusBar1的第二个窗格添加一幅图片,该图片由文件 “c:\windows\winupd.ico”指定,应使用语句:StatusBar1.Panels(2).Picture=LoadPicture(“C:\Windows\Winupd.ico”)。
12.若case子句中的表达式表列具有形式:表达式1 To 表达式2,则它的含义是:当测试表达式的值等于 这个范围内的值 时,执行该case子句相应的程序块。
13.表示x是5的倍数或是9的倍数的逻辑表达式是 x mod 5=0 OR x mod 9=0 。
14.程序运行过程中,在立即窗口显示变量f的语句是 Debug.Print f 。
15.设
Form1.Scaleleft=-250,
Form1.Scalertop=300,
Form1.Scalewidth=350,
Form1.Scaleheight=500,
则Form1的右下角坐标为 100,800 。
二、程序阅读题(本大题共40分,共 10 小题,每小题 4 分)
1.若窗体Form1上添加了通用对话框CommonDialog1,下面程序的功能是什么?
Dim filename As String
Dim str As String
CommonDialog1.Filter = \"文本文件(*.TXT)|*.txt\"
CommonDialog1.Action = 1
filename = CommonDialog1.filename
CommonDialog1.ShowColor
Form1.ForeColor = CommonDialog1.Color
Open filename
For Input As #1
Do While Not EOF(1)
str = str + Input(1, #1)
Loop
Form1.Print str
Close #1
以选择的颜色作为窗体前景色,将一个文本文件显示在Form1窗体上
2.Private Sub Form_Click()
num = 0
Do
num = num + 3
Print num
第1页,共4页
Mod 4 = 0
End Sub
程序运行后,单击窗体,输出结果是:3 6 9 12
3.写出下面事件过程的执行结果。
Private Sub Command1_Click()
Dim f(10) As Integer
f(0)=1
f(1)=1
For i=2 To 10
f(i)=f(i1)
Next i
For i=0 To 9
If i Mod 4=0 Then
Print f(i)
Next i
End Sub
执行结果是:1 1 2 3 5 8 13 21 34 55
4.下列标准模块和窗体模块的功能是给通信录文件“d:\\txrf1.dat”添加新记录,在横线上填上适当内容。
标准模块:
Type txr num As Integer
name As String * 10
tel As String * 8
addr As String * 20
End Type
窗体模块:
Private Sub Command1_Click()
Dim n%, zgr As txr
Open \"d:\\txrf1.dat\" For Random As #1
Len = Len(zgr)
zgr.num = InputBox(\"输入新职工编号:\")
zgr.name = InputBox(\"输入新职工姓名:\")
zgr.tel = InputBox(\"输入新职工电话号码:\")
zgr.addr = InputBox(\"输入新职工住址:\")
n = LOF(1) / Len(zgr) + 1 (2)Put #1, n, zgr
Close #1
End Sub
5.写出下面的程序运行后,连续单击4次窗体,在Form1上的执行结果。
Private Sub Form_Click( )
Static a As Integer
Dim b As Integer
b=a+b+1
a=a+b
Form1.Print “a=”;a, “b=”;b
End Sub
执行结果为: a=1 b=1 a=3 b=2 a=7 b=4 a=15 b=8
6.有如下事件过程,写出程序的功能(数学表达式)。
Private Sub Command1_Click()
T=0
M=1
Sum =0
Do
T=T+M
Sum =Sum+T
M=M+2
Print“Sum =”;Sum
End Sub
计算数学表达式:1+22+32+42+…+202==2870
7.编写如下代码:
dim flag as Boolean
private sub form_mousedown(button as integer,shift as integer,x as single,y as single)
flag=true
end sub
private sub form_mousemove(button as integer,shift as integer,x as single,y as single)
flag=false
end sub
private sub form_mouseup(button as integer,shift as integer,x as single,y as single)
if flag=false then
print \"DDDD\"
end if
end sub
程序运行后,如果在窗体上输出“DDDD”,则应执行的操作为 移动鼠标并松开鼠标左键 。
8.下面事件过程的功能是从键盘上输入若干个数据存放到一维数组a中,并求出这组数据的平均值,在横线上填上适当内容。
Private Sub Command1_Click()
Dim n%, i%Dim a() As Integer
n=InputBox(\"请输入数据个数:\")ReDim a(n)
For i=1 To n
a(i)=InputBox(\"请输入第\" & Str(i) & \"个数据:\")
Next i
For i=1 To n
Sum=Sum+a(i)
Next i
Print \"平均值:\"; Sum / n
End Sub
9.下面程序的作用是什么?
Private Sub Command1_Click()
Dim a()
a = Array(1, 2, 3, 4, 5, 6, 7, 8, 9)
For n = 0 To 8
Print a(n);
Next
Call s1(a)
For n = 0 To 8
Print a(n);
Next
End Sub
Private Sub s1(ByRef x())
s = UBound(x)
For n = 0 To s / 2
temp = x(n)
x(n) = x(sn) = temp
Next
End Sub
将数组a倒置
10.使用情况语句改写下列事件过程。
Private Sub Command1_Click()
Dim score!, grade$
score=InputBox(\"请输入一个学生的分数:\") If score>=90 Then
Grade=”A”
ElseIf score>=80 Then
Grade=”B”
ElseIf score>=70 Then
Grade=”C”
ElseIf score>=60 Then
Grade=”D”
Else
Grade=”E”
End If
Print \"该学生的分数等级为:\"; grade;End Sub
Private Sub Command1_Click()
Dim score!, grade$
score=InputBox(\"请输入一个学生的分数:\") Select Case score
Case Is>=90
grade=\"A\"
Case Is>=80
grade=\"B\"
Case Is>=70
grade=\"C\"
Case Is>=60
grade=\"D\"
Case Else
grade=\"E\"
End Select
Print \"该学生的分数等级为:\"; grade;End Sub