收藏 分享(赏)

VB习题集答案-2011.doc

上传人:mcady 文档编号:4407158 上传时间:2018-12-27 格式:DOC 页数:30 大小:241KB
下载 相关 举报
VB习题集答案-2011.doc_第1页
第1页 / 共30页
VB习题集答案-2011.doc_第2页
第2页 / 共30页
VB习题集答案-2011.doc_第3页
第3页 / 共30页
VB习题集答案-2011.doc_第4页
第4页 / 共30页
VB习题集答案-2011.doc_第5页
第5页 / 共30页
点击查看更多>>
资源描述

1、1目 录第 1 章 Visual Basic 程序设计概述 .2第 2 章 VB 可视化编程基础 4第 3 章 VB 语言基础 10第 4 章 VB 控制结构 11第 6 章 过程 14第 7 章 用户界面设计 15第 8 章 数据文件 17第 9 章 图形操作 20第 10 章 数据库与数据访问技术 222第 1 章 Visual Basic 程序设计概述一、判断题1 23 说明:同类控件(如两个标签)相互重叠,设计时可以设置“置前”、“置后”属性。4 5 6 7 8 9 10 11 1213 14 15 16 17 18 19 20二、选择题1. C 2. B 3D 4C 5B 6A 7D

2、 8A 9B 10A 11C 12D三、填空题1对象、事件 2属性、方法、事件 3控件、屏幕(Screen)4对象 5Left、Top 6属性、.=7网格 8F orm19Load 或 Initialize 或 Resize 或 Activate(自动执行的先后顺序也按此排列)10Activate、Deactivate四、程序设计题程序 1界面设计参看图 10-1、10-2 以及表 10-1。表 10-1 实例 2 各控件的主要属性设置控件 属性(属性值) 属性(属性值)标签控件 1 Name(Label1) Caption(“我的第一个 VB 程序“)Name(Label2) Caption

3、(“请输入你的姓名 “)标签控件 2FontUnderLine(True) FontItalic(True)命令按钮 1 Name(Command1) Caption(“确定( i * j;Next jPrintNext iEnd Sub程序 4界面设计略,过程设计如下:Private Sub Form_Click()Dim x As Single, s As Single, t As SingleDim i As Integer, n As Integerx = InputBox(“请输入 x 的值:“)n = InputBox(“请输入 n 的值:“)t = x / 2: s = tFor

4、 i = 3 To nt = t * x / is = s + t8Next iPrint sEnd Sub程序 5界面设计略,过程设计如下:Private Sub Form_Click()Dim e As Single, t As Single, i As Integere = 2: t = 1: i = 1While t = 0.0001i = i + 1: t = t / i: e = e + tWendPrint eEnd Sub程序 6界面设计略,过程设计如下:Option Base 1Private Sub Form_Click()Dim n As Integer, a(9, 9)

5、 As Integer, i As Integer, j As IntegerOn Error GoTo k 下列代码中若出现错误,转到标号为 K 的语句执行。n = InputBox(“请输入 n,0 Abs(xmax) Then xmax = x(i, j): ki = i: kj = jNext j, iEnd Sub第 7 章 用户界面设计一、判断题1 2 3 4 5 6 7 8 9 10二、选择题1D 2A 3C 4C 5B 6D 7A 8B 9D 10B11.A 12.A 13.D 14.C 15.B 16.C 17.A 18.B 19.D20.C 21.C 22.B 23.C 2

6、4.B 25.C 26.C 27.C 28.A29.C 30.C 31.C 32.B 33.D 34.C 35.C三、填空题1窗体控制菜单、下拉式菜单、快捷菜单 2ShowFont3打开文件、另存为、颜色、字体、打印对话框 4工程、部件5CommonDialog1.Action =3、CommonDialog1.ShowColor6提示信息、对话框类型、对话框标题 7Click8工具 9代码窗口、Click 10相同、正11.数据区、编辑区、菜单显示区 12.弹出式菜单、下拉式菜单13. 6 14.内缩符号 15.Checked 16.热键、访问键 17.用控件数组的下标18.用菜单编辑器建立

7、菜单 用 PopupMenu 方法显示弹出式菜单19.指定菜单位置 定义特殊菜单的行为 20.PopupMenu Mypopupmenu 21. Click22. KeyAscii=42 23. Ascii 码 24.下档字符的 ASCII 码 25.Shift、Ctrl、Alt26.Alt_Ctrl_Shift 27.MouseMove 28. Button=2 Flag=False29.Form1.MousePointer=99 30.数据区、编辑区、菜单项显示区31.弹出式菜单、下拉式菜单 32. 6 33.热键、快捷键 34.用作控件数组下标35. 用菜单编辑器建立菜单 用 Popup

8、Menu 方法显示弹出式菜单1236. 指定菜单位置 定义特殊菜单的行为 37. PopupMenu Mypopupmenu四、程序阅读题程序 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)m13.4.5.6.7.8.六、程序设计题程序 1界面设计略,过程设计如下:Private Su

9、b Command1_Click()CommonDialog1.ShowOpenList1.AddItem CommonDialog1.FileNameEnd Sub程序 2界面设计略,过程设计如下:Private Sub Command1_Click()CommonDialog1.ShowSaveList1.AddItem CommonDialog1.FileNameEnd Sub程序 3界面设计如图 10-9、表 10-2 所示,过程设计如下:Private Sub Sqr_Click()Shape1.Shape = 1End SubPrivate Sub Rec_Click()Shape

10、1.Shape = 0End SubPrivate Sub Oval_Click()Shape1.Shape = 2End SubPrivate Sub Circle_Click()Shape1.Shape = 313End SubPrivate Sub Rrec_Click()Shape1.Shape = 4End SubPrivate Sub RSqr_Click()Shape1.Shape = 5End SubPrivate Sub Shp_Click()Shape1.FillStyle = 2End SubPrivate Sub Shzh_Click()Shape1.FillStyle

11、 = 3End SubPrivate Sub Xiex_Click()Shape1.FillStyle = 4End SubPrivate Sub ShPJ_Click()Shape1.FillStyle = 6End SubPrivate Sub XJ_Click()Shape1.FillStyle = 7End SubPrivate Sub FillColor_Click()CommonDialog1.ShowColorShape1.FillColor = CommonDialog1.ColorEnd SubPrivate Sub Exit_Click()EndEnd Sub第 8 章 数

12、据文件一、判断题1 2 3 4 5 6 7 89 10 11 12 13 14 15二、选择题1A 2C 3B 4B 5A 6C 7C 8B149C 10B 11D 12B 13B 14.C 15.A 16.D17.D 18.B 19.C 20.C 21.C 22.D 23.D 24.C25.B 26.D 27.D 28.D 29.C 30.C三、填空题1ChDir 2FileLen 3Change 4EOF 5Line Input四、程序阅读题程序 1. y= 1 a= 1 程序 2. NO. 1 3 程序 3.y= 3 a= 2 NO. 2 4 窗体:36 25 16 9 4 1y= 6

13、a= 3 NO. 3 7 文件:1 4 9 16 25 36y= 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 34 4 4 45 5 5 5 5五、程序填空题1(1)Dim n As Integer (2)“C:windowscalc.exe“ (3)Output (4)End2(1)For Output As #2 (2)0 (3)“temp.dat“ As “c:a1.dat“3(1)Open “e:dataout.txt“ For Output As #1(2)t1

14、Mod t2 = 0 (3)If flag Then (4)Print coun六、程序设计题程序 1界面设计如图 8-1 所示,过程设计如下:Dim fn As StringPrivate Sub Drive1_Change()Dir1.Path = Drive1.DriveEnd SubPrivate Sub Dir1_Change()File1.Path = Dir1.PathEnd SubPrivate Sub File1_Click()If Right(File1.Path, 1) = “ Thenfn = File1.Path + File1.FileNameElsefn = Fi

15、le1.Path + “ + File1.FileNameEnd IfEnd SubPrivate Sub Command1_Click()Dim yesno As Byte15yesno = MsgBox(“确认要删除吗? “, vbYesNo, “删除文件“)If yesno = vbYes Then Kill fnFile1.RefreshEnd Sub程序 2建立 4 个文本框控件依次输入姓名、出生年月、外语、计算机成绩,按“确认”按钮追加该记录到磁盘文件 d:student.dat。过程设计如下:Private Sub Command1_Click()Dim b As Date, m

16、 As Byte, e As ByteOpen “d:student.dat“ For Append As #1b = Text2.Text: m = Text3.Text: e = Text4.TextWrite #1, Text1.Text, b, m, eText1.Text = “: Text2.Text = “: Text3.Text = “: Text4.Text = “Close #1End Sub程序 3界面设计如图 10-3 所示,过程设计如下:Private Sub Form_Load()Dim ss As StringOpen “e:student.txt“ For Ap

17、pend As #1 如文件不存在则先建立该文件Close #1Open “d:student.dat“ For Input As #1 将文件中所有记录在列表框中显示While Not EOF(1)Line Input #1, ss: List1.AddItem ssWendClose #1 在选中表项之前“删除 ”、“修改”按钮不可用Command2.Enabled = False: Command3.Enabled = FalseEnd SubPrivate Sub List1_Click() 选中表项后可“删除”或“修改 ”,不可“追加”。Command1.Enabled = Fals

18、e: Command2.Enabled = TrueCommand3.Enabled = True: Text1.Text = List1.TextEnd SubPrivate Sub Command1_Click() 追加记录If Trim(Text1.Text) 1 ThenAdodc2.Recordset.MovePreviousElseCommand1(3).Enabled = False: Command1(4).Enabled = FalseEnd IfCase 2If Not Adodc3.Recordset.BOF And Adodc3.Recordset.Bookmark 1

19、 ThenAdodc3.Recordset.MovePreviousElseCommand1(3).Enabled = False: Command1(4).Enabled = FalseEnd IfEnd SelectCommand1(5).Enabled = True: Command1(6).Enabled = TrueCase 5Select Case SSTab1.TabCase 0If Not Adodc1.Recordset.EOF And _Adodc1.Recordset.Bookmark Adodc1.Recordset.RecordCount ThenAdodc1.Rec

20、ordset.MoveNextElseCommand1(5).Enabled = False: Command1(6).Enabled = FalseEnd IfCase 1If Not Adodc2.Recordset.EOF And _Adodc2.Recordset.Bookmark Adodc2.Recordset.RecordCount ThenAdodc2.Recordset.MoveNextElseCommand1(5).Enabled = False: Command1(6).Enabled = FalseEnd IfCase 227If Not Adodc3.Recordse

21、t.EOF And _Adodc3.Recordset.Bookmark Adodc2.Recordset.RecordCount ThenAdodc3.Recordset.MoveNextElseCommand1(5).Enabled = False: Command1(6).Enabled = FalseEnd IfEnd SelectCommand1(3).Enabled = True: Command1(4).Enabled = TrueCase 6Select Case SSTab1.TabCase 0: Adodc1.Recordset.MoveLastCase 1: Adodc2

22、.Recordset.MoveLastCase 2: Adodc3.Recordset.MoveLastEnd SelectCommand1(6).Enabled = False: Command1(5).Enabled = FalseCommand1(4).Enabled = True: Command1(3).Enabled = TrueCase 7Unload MeEnd SelectIf Not Adodc1.Recordset.EOF Then Text1.Text = Adodc1.Recordset(“学号“)If Not Adodc2.Recordset.EOF Then Te

23、xt5.Text = Adodc2.Recordset(“课程号“)If Not Adodc3.Recordset.EOF ThenText11.Text = Adodc3.Recordset(“学号“)Text12.Text = Adodc3.Recordset(“课程号“)End IfExit suberrshow:MsgBox Err.DescriptionEnd SubPrivate Sub SSTab1_Click(PreviousTab As Integer)If Not Adodc1.Recordset.EOF Then Text1.Text = Adodc1.Recordset

24、(“学号“)If Not Adodc2.Recordset.EOF Then Text5.Text = Adodc2.Recordset(“课程号“)If Not Adodc3.Recordset.EOF ThenText11.Text = Adodc3.Recordset(“学号“)Text12.Text = Adodc3.Recordset(“课程号“)End IfEnd SubPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)28Dim xh As StringIf KeyCode = vbKeyReturn T

25、henrn = Adodc1.Recordset.Bookmark: Adodc1.Recordset.MoveFirstAdodc1.Recordset.Find “学号=“ & Text1.Text & “If Adodc1.Recordset.EOF ThenAdodc1.Recordset.Bookmark = rn: xh = Adodc1.Recordset(“学号“)Adodc1.Recordset (“学号“) = Text1.TextAdodc3.Recordset.MoveFirstDoAdodc3.Recordset.Find “学号=“ & xh & “If Not A

26、dodc3.Recordset.EOF ThenAdodc3.Recordset (“学号“) = Text1.TextElseExit DoEnd IfLoopAdodc3.Recordset.MoveFirst: SendKeys “tab“ : vlt = TrueElseMsgBox “学号重号,重新输入!“, , “输入验证!“Adodc1.Recordset.Bookmark = rn : vlt = False: Text1.SelStart = 0Text1.SelLength = Len(Text1.Text)End IfEnd IfEnd SubPrivate Sub Te

27、xt1_Validate(Cancel As Boolean)If vlt = True Then Cancel = FalseElse MsgBox “学号重号,重新输入!“, , “输入验证!“Cancel = TrueEnd IfEnd SubPrivate Sub Text5_KeyDown(KeyCode As Integer, Shift As Integer)Dim kch As StringIf KeyCode = vbKeyReturn Thenrn = Adodc2.Recordset.Bookmark: Adodc2.Recordset.MoveFirstAdodc2.R

28、ecordset.Find “课程号=“ & Text5.Text & “If Adodc2.Recordset.EOF Then29Adodc2.Recordset.Bookmark = rn: kch = Adodc2.Recordset(“课程号“)Adodc2.Recordset (“课程号“) = Text5.Text: Adodc3.Recordset.MoveFirstDoAdodc3.Recordset.Find “课程号=“ & kch & “If Not Adodc3.Recordset.EOF ThenAdodc3.Recordset(“课程号“) = Text5.Tex

29、tElseExit DoEnd IfLoopAdodc3.Recordset.MoveFirst: SendKeys “tab“: vlt = TrueElseMsgBox “课程号重号,重新输入!“, , “输入验证!“Adodc2.Recordset.Bookmark = rn: vlt = False: Text5.SelStart = 0Text5.SelLength = Len(Text5.Text)End IfEnd IfEnd SubPrivate Sub Text5_Validate(Cancel As Boolean)If vlt = True ThenCancel = Fa

30、lse Else MsgBox “课程号重号,重新输入!“, , “输入验证!“Cancel = TrueEnd IfEnd SubPrivate Sub Text11_KeyDown(KeyCode As Integer, Shift As Integer)Dim xh As StringIf KeyCode = vbKeyReturn ThenAdodc1.Recordset.MoveFirstAdodc1.Recordset.Find “学号=“ & Text11.Text & “If Not Adodc1.Recordset.EOF ThenAdodc3.Recordset(“学号“)

31、 = Text11.Text: SendKeys “tab“: vlt = TrueElseMsgBox “学号不存在,重新输入!“, , “输入验证!“vlt = False: Text11.SelStart = 0: Text11.SelLength = Len(Text11.Text)End IfAdodc1.Recordset.MoveFirst30End IfEnd SubPrivate Sub Text11_Validate(Cancel As Boolean)If vlt = True Then Cancel = False Else MsgBox “学号不存在,重新输入!“,

32、, “输入验证!“Cancel = TrueEnd IfEnd SubPrivate Sub Text12_KeyDown(KeyCode As Integer, Shift As Integer)Dim kch As StringIf KeyCode = vbKeyReturn ThenAdodc2.Recordset.MoveFirstAdodc2.Recordset.Find “课程号=“ & Text12.Text & “If Not Adodc2.Recordset.EOF ThenAdodc3.Recordset(“课程号“) = Text12.Text: SendKeys “ta

33、b“: vlt = TrueElseMsgBox “课程号不存在,重新输入!“, , “输入验证!“vlt=False:Text12.SelStart=0:Text12.SelLength= Len(Text12.Text)End IfAdodc2.Recordset.MoveFirstEnd IfEnd SubPrivate Sub Text12_Validate(Cancel As Boolean)If vlt = True Then Cancel = False Else MsgBox “课程号不存在,重新输入!“, , “输入验证!“: Cancel = TrueEnd IfEnd Sub

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 网络科技 > 软件工程

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报