VB课后习题答案 陈庆章主编 -
更新时间:2024-01-15 06:08:01 阅读量: 教育文库 文档下载
- vb第五版课后答案推荐度:
- 相关推荐
第1章 Visual Basic 6.0程序设计概述
一、判断题 1.√ 2.√
3.× 说明:同类控件(如两个标签)相互重叠,设计时可以设置“置前”、“置后”属性。 4.√ 5.× 6.√ 7.× 8.√ 9.√ 10.× 11.√ 12.√ 13.× 14.√ 15.× 16.√ 17.√ 18.√ 19.√ 20.√ 二、选择题
1. C 2. B 3.D 4.C 5.B 6.A 7.D 8.A 9.B 10.A 11.C 12.D 三、填空题
1.对象、事件 2.属性、方法、事件 3.控件、屏幕(Screen)
4.对象 5.Left、Top 6.属性、<对象名>.<属性名>=<表达式> 7.网格 8.F orm1
9.Load或Initialize或Resize或Activate(自动执行的先后顺序也按此排列) 10.Activate、Deactivate 四、程序设计题
程序1.界面设计参看图10-1、10-2以及表10-1。
表10-1 实例2各控件的主要属性设置
控件 标签控件1 标签控件2 命令按钮1 命令按钮2 属性(属性值) Name(Label1) Name(Label2) FontUnderLine(True) Name(Command1) Name(Command2) 属性(属性值) Caption(\我的第一个VB程序\ Caption(\请输入你的姓名\ FontItalic(True) Caption(\确定(&O)\Caption(\结束(&X)\过程设计如下:
Private sub Form_Click() Command2.Enabled = False Een Sub
Private Sub Command1_Click() Label2.Visible = False
Label1.Caption = Text1.Text + \欢迎使用\ Text1.Visible = False
Command1.Enabled = False: Command2.Enabled = True End Sub
Private Sub Command2_Click() End End Sub
程序2.界面设计略,过程设计如下:
Private Sub Command1_Click() '字体变大 Form1.FontSize = Form1.FontSize + 3 Form1.Cls: Print \欢迎使用VB\End Sub
Private Sub Command2_Click() '字体变小 Form1.FontSize = Form1.FontSize - 3 Form1.Cls: Print \欢迎使用VB\End Sub
Private Sub Command3_Click() '字体加粗 Form1.FontBold = True
Form1.Cls: Print \欢迎使用VB\End Sub
Private Sub Command4_Click() '字体不加粗 Form1.FontBold = False Form1.Cls: Print \欢迎使用VB\End Sub
运行时,不得连续、过多次单击“字体变小”按钮,因为当FontSize属性值小于0会产生适时错误。
程序3.界面设计略,过程设计如下(窗体Height值的计量包括标题、边框,而ScaleHeight值仅与窗体有效绘图区域的高度有关):
Private Sub Form_Load()
Text1.Text = \程序设计\End Sub
Private Sub Form_Resize() Text1.Top = 0: Text1.Left = 0
Text1.Width = Form1.ScaleWidth/2 '用 Form1.ScaleWidth效果优于用Form1. Width Text1.Height = Form1.ScaleHeight/2 '用 Form1.ScaleHeight优于用Form1. Height Command1.Top = Form1.ScaleHeight - Command1.Height Command1.Left = Form1.ScaleWidth - Command1.Width
End Sub
第2章 程序设计基础
一、判断题
1.√ 2.× 3.× 4.× 5.√ 6.× 7.√ 8.√ 9.√ 10.× 二、选择题
1.B 2.D 3.A 4.C 5.C 6.B 7.A 8.D 9. C 10.A 三、填空题
1.String 2.4 3.\ 4.145 5.6 6.3 7.18 8.False 9.(x Mod 10) * 10 + x \\ 10 10.10 + Int( Rnd * 90 ) 11.a * b Mod c 12.Log(x)+Sin(3.141593/6) 13.Const PI=3.1415926 14.日期 15.Int(x)+1 四、程序设计题
程序1.界面设计略,过程设计如下: 方法一、用文本框控件输入圆的半径 Private Sub Command1_Click() Dim x As Single x = Text1.Text
Label1.Caption = x * x * 3.141593 End Sub
方法二、用InputBox函数输入圆的半径 Private Sub Command1_Click()
Dim x As Single '若要求计算结果具有15位有效位数,声明x为Double类型 x = InputBox(\输入圆的半径\ Label1.Caption = x * x * 3.141593 End Sub 程序2.略。
第3章 结构化程序设计与数组
一、判断题
1.√ 2.× 3.√ 4.× 5.√ 6.× 7.× 8.√ 9.× 10.√ 二、选择题
1.A 2.D 3.C 4.C 5.D 6.B
三、填空题
1.If x>y Then t=y: y=x: x=t 2.IS
3.For i = 0 to 9: B(i) = InputBox(\4.Dim 5.String 6.8 四、程序阅读题(写出下列程序的运行结果)
程序1. 0 5 程序2. 20 程序3. 2 4 7 11 16 程序4. 1 4 9 16 25
程序5. 程序6.
五、程序填空题
1.(1)q * i (2)s + p * i / q 2.(1)r = 0 (2)m Mod n
3.(1)i + j - 1 (2)7 - i (3)Print
4.(1)10 + Int(Rnd * 90) (2)i + 1 To 30 (3)a(i)=a(j) (4)a(i) Mod 2 = 1 六、程序设计题
程序1.界面设计略,过程设计如下: Private Sub Form_Click()
Dim x As Integer, y As Integer, z As Integer
Dim max As Integer, midd As Integer, min As Integer x = InputBox(\请输入x的值:\ y = InputBox(\请输入y的值:\ z = InputBox(\请输入z的值:\ If x > y Then max = x Else max = y If z > max Then max = z
If x < y Then min = x Else min = y If z < min Then min = z midd = x + y + z - max - min Print max; midd; min End Sub
程序2.界面设计略,过程设计如下: Private Sub Form_Click() Dim x As Single, y As Single x = InputBox(\请输入x的值:\ If x > 3 Then
(3)Next i
y = x + 3
ElseIf x >= 1 Then y = x * x ElseIf x > 0 Then y = Sqr(x) Else y = 0 End If Print y End Sub
程序3.界面设计略,过程设计如下: Private Sub Form_Click()
Dim i As Integer, j As Integer For i = 1 To 9 For j = 1 To 9
Print Tab((j - 1) * 4); i * j; Next j Print Next i End Sub
程序4.界面设计略,过程设计如下: Private Sub Form_Click()
Dim x As Single, s As Single, t As Single Dim i As Integer, n As Integer x = InputBox(\请输入x的值:\ n = InputBox(\请输入n的值:\ t = x / 2: s = t For i = 3 To n t = t * x / i s = s + t Next i Print s End Sub
程序5.界面设计略,过程设计如下: Private Sub Form_Click()
Dim e As Single, t As Single, i As Integer e = 2: t = 1: i = 1
While t >= 0.0001
i = i + 1: t = t / i: e = e + t Wend Print e End Sub
程序6.界面设计略,过程设计如下: Option Base 1
Private Sub Form_Click()
Dim n As Integer, a(9, 9) As Integer, i As Integer, j As Integer On Error GoTo k '下列代码中若出现错误,转到标号为K的语句执行。 n = InputBox(\请输入n,0 For i = 1 To n: a(i, 1) = 1: a(i, i) = 1: Next i For i = 3 To n For j = 2 To i - 1 a(i, j) = a(i - 1, j - 1) + a(i - 1, j) Next j, i For i = 1 To n Print Tab(30 - 2 * i); For j = 1 To i Print Space(4 - Len(Trim(Str(a(i, j))))); Trim(Str(a(i, j))); Next j Print Next i Exit Sub k: MsgBox \输入n值小于1或大于10,数组下标超界。\End Sub 第4章 函数与过程 一、判断题 1.× 2.√ 3.× 4.× 5.√ 6.× 7.× 8.√ 二、填空题 1.按地址传送 2.b() As Long 3.6 4.按值传递 5.按地址传递 6.Public x As Single 7.Static x As Integer 8.Form2.y 三、程序阅读题(写出下列程序的运行结果) 程序1. s = 2 程序2. 1 程序3. 1 1 2 1 1 2 1 2 2 2 2 3 s = 5 1 1 s = 9 1 2 1 1 3 3 1 1 4 6 4 1 四、程序填空题 1.(1)ByeVal (2)k Mod i (3)k = k \\ i 2.(1)a() Aa Double (2)n-1 (3)a(j) < a(k) 3.(1)a() As Double, n As Integer 五、程序设计题 程序1.界面设计略,过程设计如下: Private Function fsum(x() As Double, n As Integer) As Double Dim i As Integer For i = 1 To n fsum = fsum + x(i) Next i fsum = fsum / n End Function 程序2.界面设计略,过程设计如下: Private Sub ff(a() As Single, n As Integer) Dim i As Integer, x As Single For i = 1 To n \\ 2 x = a(n - i + 1): a(n - i + 1) = a(i): a(i) = x Next i End Sub 程序3.界面设计略,过程设计如下: Private Sub find(x() As Single, m As byte, n As Byte, _ xmax As Single,ki As Byte,kj As Byte) xmax = x(1,1): ki = 1: kj = 1 For i = 1 To m For j = 1 To n If Abs(x(i, j)) > Abs(xmax) Then xmax = x(i, j): ki = i: kj = j Next j, i End Sub (2)t = t * x (3)f = s (4)Call pp(i) 第5章 常用控件 一、判断题 1.× 2.× 3.× 4.√ 5.× 6.√ 7.× 8.√ 9.√ 10.√ 11.× 12.× 13.√ 14.√ 15.× 16.× 17.× 18.√ 19.√ 20.× 21.√ 22.× 23.√ 24.× 25.√ 二、选择题 1.C 2.D 3.B 4.B 5.B 6.C 7.B 8.B 9.B 10.A 11.D 12.C 13.B 14.B 15.A 16.D 17.B 18.B 19.B 20.A 三、填空题 1.上、下、左、左 2.缇、无关 3.&、+ 19.下拉式组合框、简单组合框、下拉式列表框 20.Scroll 21.Value 22.Change 23.定时器不起作用 24.Timer 25.65535 四、程序阅读题 程序1. 116 程序2. 8 程序3. 23451 程序4. 小,你好! 程序5. 您好 34512 小李,你好! 欢迎使用Visual Basic! 程序6. 李子 程序7. y = 6 程序8. n = 1 苹果 y = 14 n = 3 橘子 n = 5 葡萄 柚子 香蕉 五、程序填空题 1.(1)a(i) = Mid(str1, i, 1) 或 a(i) = Mid(Text1.Text, i, 1) (2)p = j (3)a(i) = a(p) (4)Command2.Enabled = True 2.(1)1 To 2*i–1 (2)Command2.Enabled = True (3)Command2.Enabled = False 3.(1)Text2.Enabled = False (2)p = 2 (3)Print i (4)Val(Text1.Text) < 2 或 Val(Text1.Text) <= 1 (5)KeyAscii = 13 4.(1)List1.ListCount (2)List1.RemoveItem I (3)i = i + 1 5.(1)Timer1.Enabled = True (2)x \\ 3600 (3)(x Mod 3600) \\ 60 或 (x - 3600 * h) \\ 60 (4)x = x + 1 6.(1)Label1.Left (2)Label1.Left = -Label1.Width 六、程序设计题 程序1. 界面设计略,过程设计如下: Private Sub Command1_Click() If Command1.Caption = \显示\ Print \欢迎使用Visual Basic!\清除\ Else Form1.Cls: Command1.Caption = \显示\ End If End Sub Private Sub Command2_Click() End End Sub Private Sub Form_Load() Form1.Cls: Command1.Caption = \显示\退出\End Sub 程序2.界面设计略,过程设计如下: Private Sub Form_Load() Text1.MaxLength = 1: Text1.Text = \End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) Label1.Caption = CStr(KeyAscii) End Sub 程序3.界面设计略,过程设计如下: Const pwd As String = \预设密码为123456 Private Sub Command1_Click() Cls: Print \欢迎进入!\End Sub Private Sub Form_Load() Command1.Caption = \进入\ Text1.Text = \End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then If Text1.Text = pwd Then m = MsgBox(\口令正确,欢迎进入!\ Else m = MsgBox(\口令错误,请重新输入!\ End If End If End Sub 程序4.界面设计略,过程设计如下: Dim num As Integer, m As Integer, rec As Integer Private Sub Form_Load() Command1.Caption = \出题\ Text1.Text = \End Sub Private Sub Command1_Click() Randomize: num = Int(Rnd * 100) + 1: Text1.Enabled = True Label1.Caption = \End Sub Private Sub Command2_Click() End End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then m = Val(Text1.Text): rec = rec + 1: Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text): Text1.SetFocus If rec > 10 Then Label1.Caption = \差!重新开始\ Else If m > num Then Label1.Caption = Str(m) & \大了!\ ElseIf m < num Then Label1.Caption = Str(m) & \小了!\ Else If rec < 5 Then Label1.Caption = \好!猜对了。\ Else Label1.Caption = \还行!猜对了。\ End If Call Form_Load End If End If End If End Sub 程序5.界面设计如图10-3所示,过程设计如下: Private Sub Form_Load() Command1(0).Enabled = False: Command1(1).Enabled = False Command1(2).Enabled = False: Label1.Caption = \End Sub Private Sub Command1_Click(Index As Integer) Select Case Index Case 0 Clipboard.Clear: Clipboard.SetText Text1.SelText Text1.SelText = \请选择要粘贴的位置!\ Command1(0).Enabled = False: Command1(1).Enabled = False Command1(2).Enabled = True Case 1 Clipboard.Clear: Clipboard.SetText Text1.SelText Label1.Caption = \请选择要粘贴的位置!\Command1(0).Enabled = False Command1(1).Enabled = False: Command1(2).Enabled = True Case Else Text1.SelText = Clipboard.GetText(): Form_Load Label1.Caption = \粘贴完成!\ End Select End Sub Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, _ X As Single, Y As Single) Dim n As Integer n = Text1.SelLength If n > 0 Then Label1.Caption = \选择了\个字,请选择下一步操作!\ Command1(0).Enabled = True: Command1(1).Enabled = True Else Label1.Caption = \ End If End Sub 程序6.界面设计如图10-4所示,过程设计如下: Private Sub Form_Load() Label1.Caption = \当前日期:\ Option1(0).Caption = \显示日期\显示时间\ Option1(0).Value = True: Command1.Caption = \退出\End Sub Private Sub Option1_Click(Index As Integer) Select Case Index Case 0 Label1.Caption = \当前日期:\ Case 1 Label1.Caption = \当前时间:\ End Select End Sub Private Sub Command1_Click() End End Sub 程序7.过程设计如下: Private Sub Form_Load() Label1.Caption = \当前日期:\ Option1(0).Caption = \显示日期\显示时间\ Option1(0).Value = True: Command1.Caption = \退出\ Combo1.AddItem \年-月-日\月-日-年\ Combo1.AddItem \日-月-年\年-月-日\End Sub Private Sub Combo1_Click() Dim n As String Select Case Combo1.ListIndex Case 0: n = \ Case 1: n = \ Case 2: n = \ End Select Text1.Text = Format(Date, n) End Sub Private Sub Option1_Click(Index As Integer) Select Case Index Case 0: Label1.Caption = \当前日期:\ Case 1: Label1.Caption = \当前时间:\ End Select End Sub Private Sub Command1_Click() End End Sub 程序8. 界面设计如图10-5所示,过程设计如下: Private Sub Form_Load() List1.AddItem \ List1.AddItem \End Sub Private Sub Command1_Click() List1.AddItem Text1.Text: Text1.SetFocus Text1.SelStart = 0: Text1.SelLength = Len(Text1.Text) End Sub Private Sub Command3_Click() List1.Clear End Sub Private Sub Command4_Click() End End Sub Private Sub Command2_Click() If List1.ListIndex <> -1 Then List1.RemoveItem List1.ListIndex End Sub 9.界面设计如图10-6所示,过程设计如下: Private Sub Form_Load() Option1(0).Caption = \八进制\十六进制\ Option1(2).Caption = \二进制\End Sub Private Function tran(k As Long, n As Integer) As String Dim x As Integer, y As String * 1, k1 As Long tran = \ Do While k1 > 0 x = k1 Mod n If x >= 10 Then y = Chr(Asc(\ tran = y + tran k1 = k1 \\ n Loop If k < 0 Then tran = \End Function Private Sub Option1_Click(Index As Integer) Dim k As Long, n As Integer k = Val(Text1.Text) Select Case Index Case 0 Label2.Caption = \八进制\ Case 1 Label2.Caption = \十六进制\ Case 2 Label2.Caption = \二进制\ End Select Text2.Text = tran(k, n) End Sub 10.界面设计如图10-7所示,过程设计如下: Private Sub Form_Load() Label1.Left = Width / 2 - Label1.Width / 2 Label1.AutoSize = True HScroll1.Min = 1: HScroll1.Max = 1000 HScroll1.SmallChange = 10: HScroll1.LargeChange = 100 HScroll1.Value = 500: Timer1.Interval = 500 End Sub Private Sub HScroll1_Change() Timer1.Interval = HScroll1.Value End Sub Private Sub HScroll1_Scroll() Call HScroll1_Change End Sub Private Sub Timer1_Timer() Label1.FontSize = Label1.FontSize + 2 Label1.Left = Width / 2 - Label1.Width / 2 If Label1.FontSize >= 72 Then Timer1.Enabled = False End Sub 第6章 图形控件和图形方法 一、判断题 1.√ 2.× 3.√ 4.× 5.√ 6.× 7.× 8.× 9.√10.√ 二、选择题 1.C 2.B 3.C 4.A 5.A 6.C 7.A 8.C 9.C 10.B 11.A 12.B 13.B 14.C 15.C 三、填空题 1. Circle (ScaleLeft + ScaleWidth / 2, ScaleTop + ScaleHeight / 2), 800 2.LoadPicture 3.AutoSize、Stretch、False、False 4.选中、属性 5.形状、矩形 6.Picture1.Picture=LodePicture(\7.图片框、其他控件 8.缇、SclaeMode 9.颜色 10.颜色、圆弧起点处转角、圆弧终点处转角、椭圆纵轴与横轴长度之比 四、程序阅读题 程序1. 转动一条红色直线,其轨迹形成一个圆 程序2. 在窗体上随机的位置、用随机的颜色、半径绘制1000个空心的圆。 程序3. 在图片框内绘制多个黄色边框矩形,填充样式在“实心”、“透明”间交替变换。 五、程序填空题 1.(1)Combo1.ListIndex (2)Shape1.BorderStyle (3)Combo2.AddItem Str(i) 2.(1)Call pic (2)False (3)n = n + 1 (4)LoadPicture(\ (4)LoadPicture(fn) 六、程序设计题 程序1.界面设计略,过程设计如下: Private Sub Form_Load() Picture1.ScaleMode = 3 End Sub Private Sub Command1_Click() Dim x1 As Single, y1 As Single, x2 As Single, y2 As Single x1 = InputBox(\ x2 = InputBox(\ Picture1.Line (x1, y1)-(x2, y2), , B End Sub 程序2.界面设计略,过程设计如下: Private Sub Form_click() Dim r As Single, xo As Single, yo As Single If Form1.ScaleHeight < Form1.ScaleWidth Then r = Form1.ScaleHeight / 3 Else r = Form1.ScaleWidth / 3 End If xo = Form1.ScaleLeft + Form1.ScaleWidth / 2 yo = Form1.ScaleTop + Form1.ScaleHeight / 2 Form1.FillStyle = 0: Form1.FillColor = vbBlue Form1.DrawWidth = 2: Form1.ScaleMode = 6 Form1.Circle (xo, yo), r, vbYellow End Sub 程序3.界面设计略,过程设计如下: Private Sub Form_Load() Dim i As Integer For i = 1 To 7: List1.AddItem i: Next i Form1.ScaleMode = 1 End Sub Private Sub List1_Click() Form1.Cls: Form1.ScaleMode = List1.Text Form1.Circle (Form1.ScaleLeft + Form1.ScaleWidth / 2, _ Form1.ScaleTop + Form1.ScaleHeight / 2), 50 End Sub 第7章 对话框与菜单程序设计 一、判断题 1.√ 2.√ 3.√ 4.× 5.× 6.× 7.√ 8.√ 9.√ 10.√ 二、选择题 1.D 2.A 3.C 4.C 5.B 6.D 7.A 8.B 9.D 10.B 三、填空题 1.窗体控制菜单、下拉式菜单、快捷菜单 2.ShowFont 3.打开文件、另存为、颜色、字体、打印对话框 4.工程、部件 5.CommonDialog1.Action =3、CommonDialog1.ShowColor 6.提示信息、对话框类型、对话框标题 7.Click 8.工具 9.代码窗口、Click 10.相同、正 四、程序阅读题 程序1. 显示提示信息为“5”、标题为“na的输出结果”、有一个“确定”按钮的消息框。 程序2. 显示提示信息为“您选择了第1项”、标题为“第一项”、有一个“确定”按钮的消息框。 五、程序填空题 1.(1)Int(Rnd*100) (2)Str(i) (3)Exit For 2.(1)False (2)Date (3)CommonDialog1.Color (4)m1 六、程序设计题 程序1.界面设计略,过程设计如下: Private Sub Command1_Click() CommonDialog1.ShowOpen List1.AddItem CommonDialog1.FileName End Sub 程序2.界面设计略,过程设计如下: Private Sub Command1_Click() CommonDialog1.ShowSave List1.AddItem CommonDialog1.FileName End Sub 程序3.界面设计如图10-9、表10-2所示,过程设计如下: Private Sub Sqr_Click() Shape1.Shape = 1 End Sub Private Sub Rec_Click() Shape1.Shape = 0 End Sub Private Sub Oval_Click() Shape1.Shape = 2 End Sub Private Sub Circle_Click() Shape1.Shape = 3 End Sub Private Sub Rrec_Click() Shape1.Shape = 4 End Sub Private Sub RSqr_Click() Shape1.Shape = 5 End Sub Private Sub Shp_Click() Shape1.FillStyle = 2 End Sub Private Sub Shzh_Click() Shape1.FillStyle = 3 End Sub Private Sub Xiex_Click() Shape1.FillStyle = 4 End Sub Private Sub ShPJ_Click() Shape1.FillStyle = 6 End Sub Private Sub XJ_Click() Shape1.FillStyle = 7 End Sub Private Sub FillColor_Click() CommonDialog1.ShowColor Shape1.FillColor = CommonDialog1.Color End Sub Private Sub Exit_Click() End End Sub 第8章 文 件 一、判断题 1.× 2.√ 3.× 4.√ 5.√ 6.× 7.√ 8.× 9.√ 10.√ 11.× 12.× 13.√ 14.× 15.× 二、选择题 1.A 2.C 3.B 4.B 5.A 6.C 7.C 8.B 9.C 10.B 11.D 12.B 13.B 三、填空题 1.ChDir 2.FileLen 3.Change 4.EOF 5.Line Input 四、程序阅读题 程序1. y= 1 a= 1 程序2. NO. 1 3 程序3. y= 3 a= 2 NO. 2 4 窗体:36 25 16 9 4 1 y= 6 a= 3 NO. 3 7 文件:1 4 9 16 25 36 y= 10 a= 4 NO. 4 11 程序4. 程序5. 1 程序6. 1 窗体上显示内容:20 2 2 1 2 文件中内容:4 6 8 10 12 3 3 3 1 2 3 4 4 4 4 5 5 5 5 5 五、程序填空题 1.(1)Dim n As Integer (2)\ (3)Output (4)End 2.(1)For Output As #2 (2)0 (3)\3.(1)Open \ (2)t1 Mod t2 = 0 (3)If flag Then (4)Print coun 六、程序设计题 程序1.界面设计如图10-10所示,过程设计如下: Dim fn As String Private Sub Drive1_Change() Dir1.Path = Drive1.Drive End Sub Private Sub Dir1_Change() File1.Path = Dir1.Path End Sub Private Sub File1_Click() If Right(File1.Path, 1) = \ fn = File1.Path + File1.FileName Else fn = File1.Path + \ End If End Sub Private Sub Command1_Click() Dim yesno As Byte yesno = MsgBox(\确认要删除吗?\删除文件\ If yesno = vbYes Then Kill fn File1.Refresh End Sub 程序2.建立4个文本框控件依次输入姓名、出生年月、外语、计算机成绩,按“确认”按钮追加该记录到磁盘文件d:\\student.dat。过程设计如下: Private Sub Command1_Click() Dim b As Date, m As Byte, e As Byte Open \ b = Text2.Text: m = Text3.Text: e = Text4.Text Write #1, Text1.Text, b, m, e Text1.Text = \ Close #1 End Sub 程序3.界面设计如图10-11所示,过程设计如下: Private Sub Form_Load() Dim ss As String Open \ Close #1 Open \将文件中所有记录在列表框中显示 While Not EOF(1) Line Input #1, ss: List1.AddItem ss Wend Close #1 '在选中表项之前“删除”、“修改”按钮不可用 Command2.Enabled = False: Command3.Enabled = False End Sub Private Sub List1_Click() '选中表项后可“删除”或“修改”,不可“追加”。 Command1.Enabled = False: Command2.Enabled = True Command3.Enabled = True: Text1.Text = List1.Text End Sub '如文件不存在则先建立该文件 Private Sub Command1_Click() '追加记录 If Trim(Text1.Text) <> \ Text1.Text = \End Sub Private Sub Command2_Click() '修改记录 List1.AddItem Text1.Text, List1.ListIndex List1.RemoveItem List1.ListIndex Command1.Enabled = True: Command2.Enabled = False Command3.Enabled = False: Text1.Text = \ '修改后,不可“删除”、“修改” End Sub Private Sub Command3_Click() '删除记录 List1.RemoveItem List1.ListIndex '删除后,不可“删除”、“修改” Command1.Enabled = True: Command2.Enabled = False Command3.Enabled = False: Text1.Text = \End Sub Private Sub Command4_Click() '保存文件,将列表框中所有表项输出到文件 Dim i As Integer Open \ For i = 0 To List1.ListCount - 1: Print #1, List1.List(i): Next i Close #1 End Sub Private Sub Command5_Click() '退出之前先保存文件 Call Command4_Click: End End Sub 第9章 数据库与数据访问技术 一、判断题 1. √ 2. √ 3. × 4. √ 5. × 6. × 7. √ 8. √ 9. × 10.× 11.√ 12.√ 13.√ 14.√ 15.√ 16.× 17.× 18.× 19.√ 20.√ 21.√ 22.× 二、选择题 1.A 2.D 3.C 4.B 5.C 6.A 7.C 8.D 9.D 10.C 11.A 12.D 13.A 14.B 15.B 16.C 三、程序设计题 程序1. (1)数据访问控件以及数据绑定控件的相关属性设置如下 Data1:Connect(\、DatabaseName(\学籍.mdb\、RecordSource(\学生)\Text1:DataSource(\、DataField(\学号\Text2:DataSource(\、DataField(\姓名\Check1:DataSource(\、DataField(\性别\Text3:DataSource(\、DataField(\出生日期) Text4:DataSource(\、DataField(\奖学金\Text5:DataSource(\、DataField(\简历\OLE1:DataSource(\、DataField(\照片\ Adodc1:ConnectionString(\Data Source = E:\\GYH\\VB\\学籍1b.mdb; Persist Security Info = False\CommandType(\、RecordSource(\成绩\DataGrid1:DataSource(\ (2)主要事件过程代码 Option Explicit Private Sub Form_Load() Caption = \学籍信息编辑浏览\ Label1.Caption = \学号:\姓名:\Label3.Caption = \出生年月:\奖学金:\Label5.Caption = \简历:\照片:\Check1.Caption = \性别(选中表示男,否则为女)\ Label7.Caption = \成绩信息查询显示\End Sub Private Sub Data1_Reposition() Adodc1.RecordSource = \成绩.课程号,课程名,成绩 from 学生,课程,成绩 \_ & \学生.学号 = 成绩.学号 and \成绩.课程号 = 课程.课程号 and \\成绩.学号='\学号\成绩.课程号\Label7.Caption = Trim(Data1.Recordset(\姓名\成绩信息查询显示\Adodc1.Refresh End Sub 程序2. (1)数据访问控件以及数据绑定控件的相关属性设置如下: Adodc1:ConnectionString(\ Data Source = E:\\GYH\\VB\\学籍1b.mdb; Persist Security Info = False\CommandType(\、RecordSource(\学生) DataGrid1:DataSource(\ (2)主要事件过程代码 Option Explicit Private Sub Form_Load() Dim i As Integer Caption = \学籍信息查询浏览\ Label1.Caption = \选择查询方式:\全部都显示\ Label2.Caption = \全部表文件数据浏览表格:\Text1.Visible = False: Text1.Text = \For i = 0 To 2 Combo1.AddItem Mid(\全部都显示按学号查询按姓名查询\Next i End Sub Private Sub Combo1_Click() Select Case Combo1.ListIndex Case 0 Text1.Visible = False: Label3.Visible = False Adodc1.RecordSource = \学生\ Label2.Caption = \全部表文件数据浏览表格:\ Case 1 Label3.Caption = \输入查询条件(学号):\ Label3.Visible = True: Text1.SetFocus Case 2 Label3.Caption = \输入查询条件(姓名):\ Label3.Visible = True: Text1.SetFocus End Select End Sub Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyReturn Then If Combo1.ListIndex = 1 Then Adodc1.Recordset.MoveFirst Adodc1.Recordset.Find \学号='\ If Adodc1.Recordset.EOF Then Adodc1.RecordSource = \学生\ Label2.Caption = \全部表文件数据浏览表格:\ Adodc1.Refresh: MsgBox \查无此人!\ Else Adodc1.RecordSource = \学生 \ 学号='\ Label2.Caption = \学生\的数据浏览表格:\ End If Else Adodc1.Recordset.MoveFirst Adodc1.Recordset.Find \姓名='\ If Adodc1.Recordset.EOF Then Adodc1.RecordSource = \学生\ Label2.Caption = \全部表文件数据浏览表格:\ Adodc1.Refresh: MsgBox \查无此人!\ Else Adodc1.RecordSource = \学生 \ \姓名='\ End If End If Adodc1.Refresh End If End Sub 程序3. (1)数据访问控件以及数据绑定控件的相关属性设置如下: Adodc1(xs):ConnectionString(\ Data Source = E:\\GYH\\VB\\学籍1b.mdb; Persist Security Info=False\CommandType(\、RecordSource(\学生\ Adodc2(kc):ConnectionString(\ Data Source = E:\\GYH\\VB\\学籍1b.mdb; Persist Security Info=False\CommandType(\、RecordSource(\课程\ Adodc3(cjcx):ConnectionString(\_ Data Source = E:\\GYH\\VB\\学籍1b.mdb; Persist Security Info=False\CommandType(\ RecordSource(\成绩.学号,学生.姓名,成绩.课程号,课程.课程名, _ 成绩.成绩 from 学生,课程,成绩 where 成绩.课程号 = 课程.课程号 _ and 成绩.学号 = 学生.学号 \ DataGrid1:DataSource(\ DataList1:RowSource(\、ListField (\姓名\)、BoundColumn(\学号\DataList2:RowSource(\、ListField(\课程名\、BoundColumn(\课程号\ (2)主要事件过程代码 Option Explicit Dim p As Byte Private Sub Form_Load() Dim i As Integer For i = 0 To 4 Label1(i).Caption = Mid(\优秀良好中等及格差等\ Text1(i).Text = \ Text1(i).Locked = True Next i cjcx.RecordSource = \成绩.学号,学生.姓名,成绩.课程号,课程.课程名, \ & \成绩.成绩from 学生,课程,成绩 \ \成绩.课程号=课程.课程号 and 成绩.学号=学生.学号\cjcx.Refresh: Label2.Caption = \成绩信息列表\ Label3.Caption = \选择学生姓名:\选择课程名:\xs.Visible = False: kc.Visible = False: cjcx.Visible = False Caption = \学籍信息查询\End Sub Private Sub DataList1_Click() p = 0: Call cjdctj End Sub Private Sub DataList2_Click() p = 1: Call cjdctj End Sub Private Sub cjdctj() Dim cjdcjs(5) As Integer, dcase As Byte, i As Byte If p = 0 Then cjcx.RecordSource = \成绩.学号,学生.姓名,成绩.课程号, \ & \课程.课程名,成绩.成绩 from 学生,课程,成绩 \ & \成绩.学号='\& \成绩.课程号=课程.课程号 and \ & \成绩.学号=学生.学号) order by 成绩.课程号\ Frame1.Caption = \单位:门\ Label2.Caption = Trim(DataList1.Text) & \成绩信息列表\Else cjcx.RecordSource = \成绩.学号,学生.姓名,成绩.课程号, \ & \课程.课程名,成绩.成绩 from 学生,课程,成绩 \ & \成绩.课程号='\& \成绩.课程号=课程.课程号 and \& \成绩.学号=学生.学号) order by 成绩.学号\ Frame1.Caption = \单位:人\ Label2.Caption = Trim(DataList2.Text) & \成绩信息列表\End If cjcx.Refresh If Not cjcx.Recordset.EOF Then cjcx.Recordset.MoveFirst While Not cjcx.Recordset.EOF If cjcx.Recordset(\成绩\ dcase = 0 Els dcase = (cjcx.Recordset(\成绩\– 5 End If Select Case dcase Case 4, 5: cjdcjs(0) = cjdcjs(0) + 1 Case 3: cjdcjs(1) = cjdcjs(1) + 1 Case 2: cjdcjs(2) = cjdcjs(2) + 1 Case 1: cjdcjs(3) = cjdcjs(3) + 1 Case 0: cjdcjs(4) = cjdcjs(4) + 1 End Select cjcx.Recordset.MoveNext Wend For i = 0 To 4: Text1(i).Text = cjdcjs(i): Next i End Sub 程序4. (1)数据访问控件以及数据绑定控件的相关属性设置如下: Adodc1:ConnectionString(\ Data Source = E:\\GYH\\VB\\学籍1b.mdb; Persist Security Info = False\CommandType(\、RecordSource(\学生\LockType(\ Adodc2:ConnectionString(\ Data Source = E:\\GYH\\VB\\学籍1b.mdb; Persist Security Info=False\CommandType(\、RecordSource(\课程\LockType(\ Adodc3:ConnectionString(\ Data Source = E:\\GYH\\VB\\学籍1b.mdb; Persist Security Info = False\CommandType(\、RecordSource(\成绩\LockType(\ Text1:用于显示编辑\学号\,但是本字段不设置数据绑定属性,输入或修改后的\学号\数据通过代码方式写入数据源中。 Text2:DataSource(\、DataField(\姓名\Check1:DataSource(\、DataField(\性别\Text3:DataSource(\、DataField(\出生日期\Text4:DataSource(\、DataField(\奖学金\ Text5:用于显示编辑\课程号\,但是本字段不设置数据绑定属性,输入或修改后的\课程号\数据通过代码方式写入数据源中。 Text6:DataSource(\、DataField(\课程名\Text7:DataSource(\、DataField(\学时数\Text8:DataSource(\、DataField(\学分数\Text9:DataSource(\、DataField(\开课学期\Text10:DataSource(\、DataField(\考试考查标志\ Text11:用于显示编辑成绩表中的\学号\,但是本字段不设置数据绑定属性,输入或修改后的\学号\数据通过代码方式写入数据源中。 Text12:用于显示编辑成绩表中的\课程号\,但是本字段不设置数据绑定属性,输入或修改后的\课程号\数据通过代码方式写入数据源中。 Text12:DataSource(\、DataField(\成绩\ (2)主要事件过程代码 Option Explicit Dim vlt As Boolean, rn As Variant Private Sub Form_Load() Dim i As Integer For i = 0 To 7 Command1(i).Caption = Mid(\追加更新删除表首前翻后翻表尾返回\2 * i + 1, 2) Next i Command1(3).Enabled = False: Command1(4).Enabled = False Label1.Caption = \学号:\姓名:\ Label3.Caption = \出生年月:\奖学金:\ Check1.Caption = \性别(选中为男,否则为女)\ Label5.Caption = \课程号:\课程名:\ Label7.Caption = \学时数:\学分数:\ Label9.Caption = \开课学期:\考试考查标志:\ Label11.Caption = \学号:\课程号:\ Label13.Caption = \成绩\ Label14.Caption = \“追加”、“删除”或是修改操作完成之后必须按“更新”按钮\ Caption = \学籍信息浏览编辑\ Text1.Text=Adodc1.Recordset(\学号\课程号\ Text11.Text=Adodc3.Recordset(\学号\Text12.Text=Adodc3.Recordset(\课程号\ vlt = True End Sub Private Sub Command1_Click(Index As Integer) Dim xh As String, kch As String, answer As Byte On Error GoTo errshow Select Case Index Case 0 Select Case SSTab1.Tab Case 0 Adodc1.Recordset.AddNew: Adodc1.Recordset (\学号\= \ Case 1 Adodc2.Recordset.AddNew: Adodc2.Recordset (\课程号\= \ Case 2 Adodc3.Recordset.AddNew: Adodc3.Recordset (\学号\= \ Adodc3.Recordset (\课程号\ End Select Case 1 Select Case SSTab1.Tab Case 0: Adodc1.Recordset.UpdateBatch Case 1: Adodc2.Recordset.UpdateBatch Case 2: Adodc3.Recordset.UpdateBatch End Select Case 2 answer = MsgBox(\真的确定要删除当前记录吗?\删除确认\ If answer = 1 Then Select Case SSTab1.Tab Case 0 xh = Adodc1.Recordset(\学号\Adodc3.Recordset.MoveFirst Do Adodc3.Recordset.Find \学号='\ If Not Adodc3.Recordset.EOF Then Adodc3.Recordset.Delete: Adodc3.Recordset.MoveNext Else Exit Do End If Loop Adodc3.Recordset.MoveFirst: Adodc1.Recordset.Delete Adodc1.Recordset.MoveNext Case 1 kch = Adodc2.Recordset(\课程号\ Do Adodc3.Recordset.Find \课程号='\ If Not Adodc3.Recordset.EOF Then Adodc3.Recordset.Delete: Adodc3.Recordset.MoveNext Else Exit Do End If Loop Adodc3.Recordset.MoveFirst: Adodc2.Recordset.Delete Adodc2.Recordset.MoveNext Case 2 Adodc3.Recordset.Delete: Adodc3.Recordset.MoveNext End Select End If Case 3 Select Case SSTab1.Tab Case 0: Adodc1.Recordset.MoveFirst Case 1: Adodc2.Recordset.MoveFirst Case 2: Adodc3.Recordset.MoveFirst End Select Command1(3).Enabled = False: Command1(4).Enabled = False Command1(5).Enabled = True: Command1(6).Enabled = True Case 4 Select Case SSTab1.Tab Case 0 If Not Adodc1.Recordset.BOF And Adodc1.Recordset.Bookmark > 1 Then Adodc1.Recordset.MovePrevious Else Command1(3).Enabled = False: Command1(4).Enabled = False End If Case 1 If Not Adodc2.Recordset.BOF And Adodc2.Recordset.Bookmark > 1 Then Adodc2.Recordset.MovePrevious Else Command1(3).Enabled = False: Command1(4).Enabled = False End If Case 2 If Not Adodc3.Recordset.BOF And Adodc3.Recordset.Bookmark > 1 Then Adodc3.Recordset.MovePrevious Else Command1(3).Enabled = False: Command1(4).Enabled = False End If End Select Command1(5).Enabled = True: Command1(6).Enabled = True Case 5 Select Case SSTab1.Tab Case 0 If Not Adodc1.Recordset.EOF And _ Adodc1.Recordset.Bookmark < Adodc1.Recordset.RecordCount Then Adodc1.Recordset.MoveNext Else Command1(5).Enabled = False: Command1(6).Enabled = False End If Case 1 If Not Adodc2.Recordset.EOF And _ Adodc2.Recordset.Bookmark < Adodc2.Recordset.RecordCount Then Adodc2.Recordset.MoveNext Else Command1(5).Enabled = False: Command1(6).Enabled = False End If Case 2 If Not Adodc3.Recordset.EOF And _ Adodc3.Recordset.Bookmark < Adodc2.Recordset.RecordCount Then Adodc3.Recordset.MoveNext Else Command1(5).Enabled = False: Command1(6).Enabled = False End If End Select Command1(3).Enabled = True: Command1(4).Enabled = True Case 6 Select Case SSTab1.Tab Case 0: Adodc1.Recordset.MoveLast Case 1: Adodc2.Recordset.MoveLast Case 2: Adodc3.Recordset.MoveLast End Select Command1(6).Enabled = False: Command1(5).Enabled = False Command1(4).Enabled = True: Command1(3).Enabled = True Case 7 Unload Me End Select If Not Adodc1.Recordset.EOF Then Text1.Text = Adodc1.Recordset(\学号\If Not Adodc2.Recordset.EOF Then Text5.Text = Adodc2.Recordset(\课程号\If Not Adodc3.Recordset.EOF Then Text11.Text = Adodc3.Recordset(\学号\ Text12.Text = Adodc3.Recordset(\课程号\End If Exit sub errshow: MsgBox Err.Description End Sub Private Sub SSTab1_Click(PreviousTab As Integer) If Not Adodc1.Recordset.EOF Then Text1.Text = Adodc1.Recordset(\学号\If Not Adodc2.Recordset.EOF Then Text5.Text = Adodc2.Recordset(\课程号\If Not Adodc3.Recordset.EOF Then Text11.Text = Adodc3.Recordset(\学号\ Text12.Text = Adodc3.Recordset(\课程号\End If End Sub Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) Dim xh As String If KeyCode = vbKeyReturn Then rn = Adodc1.Recordset.Bookmark: Adodc1.Recordset.MoveFirst Adodc1.Recordset.Find \学号='\ If Adodc1.Recordset.EOF Then Adodc1.Recordset.Bookmark = rn: xh = Adodc1.Recordset(\学号\ Adodc1.Recordset (\学号\ Adodc3.Recordset.MoveFirst Do Adodc3.Recordset.Find \学号='\ If Not Adodc3.Recordset.EOF Then Adodc3.Recordset (\学号\ Else Exit Do End If Loop Adodc3.Recordset.MoveFirst: SendKeys \ Else MsgBox \学号重号,重新输入!\输入验证!\ Adodc1.Recordset.Bookmark = rn : vlt = False: Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End If End If End Sub Private Sub Text1_Validate(Cancel As Boolean) If vlt = True Then Cancel = False Else MsgBox \学号重号,重新输入!\输入验证!\Cancel = True End If End Sub Private Sub Text5_KeyDown(KeyCode As Integer, Shift As Integer) Dim kch As String If KeyCode = vbKeyReturn Then rn = Adodc2.Recordset.Bookmark: Adodc2.Recordset.MoveFirst Adodc2.Recordset.Find \课程号='\ If Adodc2.Recordset.EOF Then Adodc2.Recordset.Bookmark = rn: kch = Adodc2.Recordset(\课程号\ Adodc2.Recordset (\课程号\= Text5.Text: Adodc3.Recordset.MoveFirst Do Adodc3.Recordset.Find \课程号='\ If Not Adodc3.Recordset.EOF Then Adodc3.Recordset(\课程号\ Else Exit Do End If Loop Adodc3.Recordset.MoveFirst: SendKeys \ Else MsgBox \课程号重号,重新输入!\输入验证!\ Adodc2.Recordset.Bookmark = rn: vlt = False: Text5.SelStart = 0 Text5.SelLength = Len(Text5.Text) End If End If End Sub Private Sub Text5_Validate(Cancel As Boolean) If vlt = True Then Cancel = False Else MsgBox \课程号重号,重新输入!\输入验证!\Cancel = True End If End Sub Private Sub Text11_KeyDown(KeyCode As Integer, Shift As Integer) Dim xh As String If KeyCode = vbKeyReturn Then Adodc1.Recordset.MoveFirst Adodc1.Recordset.Find \学号='\ If Not Adodc1.Recordset.EOF Then Adodc3.Recordset(\学号\= Text11.Text: SendKeys \vlt = True Else MsgBox \学号不存在,重新输入!\输入验证!\ vlt = False: Text11.SelStart = 0: Text11.SelLength = Len(Text11.Text) End If Adodc1.Recordset.MoveFirst End If End Sub Private Sub Text11_Validate(Cancel As Boolean) If vlt = True Then Cancel = False Else MsgBox \学号不存在,重新输入!\输入验证!\Cancel = True End If End Sub Private Sub Text12_KeyDown(KeyCode As Integer, Shift As Integer) Dim kch As String If KeyCode = vbKeyReturn Then Adodc2.Recordset.MoveFirst Adodc2.Recordset.Find \课程号='\ If Not Adodc2.Recordset.EOF Then Adodc3.Recordset(\课程号\= Text12.Text: SendKeys \vlt = True Else MsgBox \课程号不存在,重新输入!\输入验证!\ vlt=False:Text12.SelStart=0:Text12.SelLength= Len(Text12.Text) End If Adodc2.Recordset.MoveFirst End If End Sub Private Sub Text12_Validate(Cancel As Boolean) If vlt = True Then Cancel = False Else MsgBox \课程号不存在,重新输入!\输入验证!\End If End Sub
正在阅读:
VB课后习题答案 陈庆章主编 -01-15
改革创新奖奖励办法04-04
电子负载 - 电路图 - 设计方案完整版03-29
苗桥镇妇联07-09
反假币考试资料08-09
Logitech Optical USB Mouse04-11
我最喜欢的狗作文800字06-23
课改经验交流《老师是干什么的》06-27
欢迎到我家乡来的作文06-30
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 课后
- 习题
- 主编
- 答案
- 陈庆章
- 第七章opengl文字显示
- 武汉理工大学优秀毕业生公示
- 英语修辞学课程教学大纲2013版
- 办实事 求实效 出实绩
- 2019年注册安全工程师安全生产法及相关法律知识重点难点考点总结
- 最新会计电算化试题WORD下载版
- 第一批全国建筑幕墙设计人员岗位能力评价通过人员继续教育复习题
- 人防工程防护设备及通风系统安装施工质量检测报告分析
- 中科院模式识别大作业 - 人脸识别
- 汉字的结构和发展(北京大学邵永海) - 图文
- 2019年高考一轮总复习区域地理第三章世界地理分区第3节东南亚南亚—印度练习题(含解析)- 副本
- 奇数和偶数奥数教案
- 2016数模校内选拔赛赛题(中南财经政法大学)
- 最新《世界现代设计史》考研笔记
- matlab复变函数画图形
- 出入境证件照片规范 - 图文
- 2011年二级建造师资格考试建设工程施工管理模拟试题及答案(三)
- SFDA植入牙指南
- 中华人民共和国建筑法全文 - 图文
- 地产项目考察学习汇报 - 图文