当前位置:文档之家› VB程序设计作业参考答案

VB程序设计作业参考答案

《VB程序设计》作业参考答案
一.选择题
1-5 ABC CB 6—10 CCA DC 11-15 ABC DB 15-20CDA CB 21-25DBD CC
25-30DAC AA 31-35 DAC AA 36-40 BCC CD 41-45 CCC AC 46-50DDB AD 51-55 ACA CD 56-60 BCA DA 61-65 BAADB 66-70DBDAC 71-75BBBAD 76—80CDABC 81-85ABCD C 86-90BAADD 91-95CBBAD 96.B
二.填空题
(1) E (2) 程序代码(3) CmdDisplay.Visible =False(4) t=a(j)(5) And
(6) 回车符(7) text2.setfocus (8) 3 (9) D=B:B=C:C=D (10) Random
(11)事件过程(12) 打开对话框(13) 3 (14) a(i,j)=0 (15) L1.text
(16) Put # (17) True (18) I MOD 4=0 (19) AaBbCc (20)INT(Rnd*100) ;arr (21)Output ;Write #1,StuNo,StuName,StuEng (22)10 (23)4 (24) 顺序,随机
(25)INPUT,OUTPUT,APPEND (26)程序代码窗口的字符过大或过小,可以通过(工具→选项→编辑器格式→大小)去改变。

(27)窗体、控件、对象(28)界面设计(29)对象、代码(30)窗体、标准模块、类模块、工程(31)窗体(Form)、图片框(PictureBox)、打印机(Printer)、立即窗口(Debug) (32)E D(33)81 (34)程序,数据(35)窗体、控件、对象(36)对象、代码(37)用户界面的窗体、执行具体操作的代码。

(38)Picture属性、剪切板把图形粘贴
三.编程题
1.
Option Base 1
Private Sub Form_click()
Dim a(3) As Integer, m As Integer
Do While m <> -1 And i < 3
m = InputBox("请输入第" & i + 1 & "条边")
i = i + 1
a(i) = m
If a(i) < 0 Then
MsgBox "输入错误,请重新输入!"
i = i - 1
End If
Loop
If a(1) + a(2) > a(3) And Abs(a(1) - a(2)) < a(3) Then
s = (a(1) + a(2) + a(3)) / 2
s = Sqr(s * (s - a(1)) * (s - a(2)) * (s - a(3)))
Print "三角形的面积是"; s
Else
MsgBox "三条边不能构成三角形!"
End
End If
End Sub
2.
Option Base 1
Private Sub Form_click()
Dim a, b
a = Array(2, 8, 7, 6, 4, 28, 70, 25)
b = Array(79, 27, 32, 41, 57, 66, 78, 80)
Dim c(8)
For i = 1 To 8
c(i) = a(i) + b(i)
Print c(i);
Next i
End Sub
3.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Print spc(3); Chr$(KeyCode); spc(3); Hex$(KeyCode); spc(3); Oct$(KeyCode); spc(3); KeyCode End Sub
Private Sub Form_Load()
Print
Show
Print spc(3); "按键"; spc(3); "16进制"; spc(3); "8进制"; spc(3); "10进制" Print
End Sub
4.
Dim a(3) As Long, s As Long, p As Long '通用-声明
Sub Su(n As Long) '通用sub
p = 1
For i = 1 To n
p = p * i
Next i
End Sub
Function F(n As Long) As Long '通用Function
p = 1
For i = 1 To n
p = p * i
Next i
F = p
End Function
Private Sub Command1_Click()
s = 0
For i = 1 To 3
a(i) = InputBox("请输入第" & i & " 个数的值:")
Call Su(a(i))
s = s + p
Next i
Print "用Sub过程求得"; a(1); "! +"; a(2); "! +"; a(3); "! ="; s
End Sub
Private Sub Command2_Click()
s = 0
For i = 1 To 3
a(i) = InputBox("请输入第" & i & " 个数的值:")
s = s + F(a(i))
Next i
Print "用Function过程求得"; a(1); "! +"; a(2); "! +"; a(3); "! ="; s
End Sub
Private Sub Command3_Click()
End
End Sub
5. 如下图,在窗体上画一个图片框,一个文本框,再画两个标签。

①填写下表
②如图编写程序代码,要求键盘输入42,显示在文本框内;并将该整数范围内的偶数显示在图片框内。

(每行
打印7个数)
Private Sub Form_Load()
Text1.Text = 42
End Sub
Private Sub Picture1_Click()
k = 0
For j = 1 To 42
If k Mod 7= 0 Then Picture1.Print
If j Mod 2 = 0 Then
Picture1.Print Str$(j);
k = k + 1
End If
Next j
End Sub
6. 如图在窗体上画两个命令按钮和一个文本框,要求单击第一个命令按钮时,文本框消失,单击第二个命令按钮时,文本框复出,并在文本框中显示“编写程序乐趣无限”。

Private Sub Command1_Click()
Text1.Visible = False
End Sub
Private Sub Command2_Click()
Text1.Text = "编写程序乐趣无限"
Text1.Visible = True
End Sub
7. 如下图,在窗体上画一个图片框,一个文本框,再画两个标签。

①填写下表
②编写程序代码,如图,要求键盘输入任意一个整数作上限,显示在文本框内;并将该整数范围内能同时被3和5整除的整数,显示在图片框内。

Public n As String
Private Sub Form_Load()
n$ = InputBox("输入数的取值范围n")
Text1.Text = n$
End Sub
Private Sub Picture1_Click()
n = Val(n$)
k = 0
For j = 1 To n
If j Mod 3 = 0 And j Mod 5 = 0 Then
Picture1.Print Str$(j);
End If
Next j
End Sub
8. 输入任意一个字符串,检查字符串是否是“回文”.当一个字符串顺读倒读是一样的,则这样
的字符串就是“回文”,如“LEVEL”, “MADAM”, “123321”等都是“回文”
Private Sub Form_click()
a$ = InputBox("a$=")
n = Len(a$)
For i = 1 To Int(n / 2)
If Mid$(a$, i, 1) <> Mid$(a$, n - i + 1, 1) Then
Print "不是回文": Exit For
End If
Next i
If i > Int(n / 2) Then Print "是回文"
End Sub。

相关主题