VB程序设计练习题答案.doc
文本预览下载声明
参考答案
第一章 Visual Basic程序设计概述
一、填空题C 2、C 3、C 4、D 5、D
第二章 简单的VB程序设计
一、填空题Tabstop
2、Left、top、height、width
3、enabled
4、backcolor
5、name
6、name和caption属性标准模块文件运行模式填空题Const
2、Variant
3、隐式声明、显示声明
4、option base、ubound、lbound
5、强制变量声明
6、表示a2是一个可选参数
7、End
8、Msgbox、Inputbox
9、*.*、showprint
10、Mid()
11、6
12、redim preserve arraya(ubound(arraya())+1)
13、static
14、0
15、f
16、rem、’
17、变量、数组
18、1 to 4,1 to 5
19、Index
20、按地址Option Explicit
22、13
23、ityo
24、符号
25、LCase
26、ESC
27、部件
28、断点
29、False
30、Option Explicit
31、UCase
32、Mid
33、#
34、过程
35、private
36、求x的绝对值
37、2.5
二、选择题
1、D
2、B
3、D
4、C
5、B
6、C
7、D
8、C
9、D
10、A
11、A
12、D
13、B
14、B
15、D
16、B
17、A
18、D
19、D
20、C
21、D
22、B
23、B
24、B
25、B
26、A
27、B
28、C
28、B
30、C
四、读程序题
1、结果如下:
B
2、结果如下:
BB
CCC
DDDD
EEEEE
3、功能如下:
在20个由小到大排列的数据中插入一个数,插入数据后的数据仍按由小到大的顺序排列。
4、输出结果输出结果输出结果输出结果
0 2 0
8、输出结果3
3 3 2
五、编程题
1、参考代码如下:
Private Sub Command1_Click()
Dim year, x As Integer
year = Val(Text1.Text)
If year Mod 400 = 0 Then
Label2.Caption = 是闰年
Else
下面是嵌套块If语句
If year Mod 4 = 0 And year Mod 100 0 Then
Label2.Caption = 是闰年
Else
Label2.Caption = 不是闰年
End If
End If
End Sub
2、程序参考代码如下:
Private Sub Command1_Click()
Dim m, n, r As Integer
m = Val ( Text1.Text )
n = Val ( Text2.Text )
If m 0 Or n 0 Then ‘ 若判断为非法数据,Then子句输出相应信息
Label2.Caption = 输入数据有错!
Else ‘ 若判断为合法数据,Else子句用辗转相除法求余数
r = m Mod n
Do While r 0
m = n
n = r
r = m Mod n
Loop
‘ 循环结束后n中存放的就是最大公约数,输出n值
Label2.Caption = 最大公约数为: n
End If
End Sub
3、参考代码如下:
Private Sub Command1_Click()
Dim x As Single
x = Val(Text1.Text)
If x 100 Or
显示全部