VB程序设计课后习题答案(科学出版社)
VB课后练习答案.doc
VB课后练习答案P12第一章课后练习答案:一、选择题二、填空题第二章(P39)选择题答案:填空题答案:1.Cmdl, Click2.Text 1.Text二"Hello"P64第三章课后练习答案一、选择题二、填空题1.(Y Mod 4=0 And Y Mod 10000) Or Y Mod 400=0 2.a<>0 And b*2-4*a*c>=0 3.X Mod 5=0 And X Mod 2=0 或 Tnt(x/5)=X/5 And Int(X/2)=X/2 4. 注意:返回的均是字符型。
第四章课后答案:P79一、选择题答案为:$$41.50010二、填空题三、程序设计题(提示)1、鸡的头数为x,兔的头数为y,则可列方程式:\x-\- y = h (兀 * 2 + y * 4 =于求得x, y 的值再在窗体上输出结果。
2、 利用Format 格式函数,再通过窗体的Print 将格式化后的信息输出到窗体上。
3、 厶员I 的周长=2加" $岡的面积=加25、通过Inputbox 函数或用文本框输入三边和圆的半径a,b,c, r,利用公式:. a + b + cn 二 ---------2 S 三角形面积=Jh (h - - b )(h - c )P97第五章课后练习答案:第9题| D一、选择题答案D 改为:30二、填空题第]题Y Mod 4二0 And Y Mod 100二0 Or Y Mod 400二0 第2题笫3题笫4题Private Sub Command l_Click()X=Val(Textl.Text)Select Case XCase Is>200. Isv-10()Print “xv 100 Or x>200"Case ls<=0Y=l()()-XCase Isv二100Y=100+XCase Is<=200Y=400End SelectText2.Text=yEnd Sub三、程序设计题(提示)1、判断条件:假设一个整数为xX Mod 3=0 Or x Mod 5=0 或x/3=x\3 Or x/5=x\52、选项按钮的知识点在P182,利用该控件的Wlue属性判断是否选中该项。
visual basic 程序设计课后习题参考答案
[Exit Function] End Function
(4). Function 过程的调用方法: ①直接调用 像使用 VB 内部函数一样,只需写出函数名
和相应的参数即可 ②用 Call 语句调用 与调用 Sub 过程一样来调用 Function
过程,当用这种方法调用 Function 过程时,将会放弃返回值 3、简述 VB 过程中参数传递的两种方式。
第五章 数 组
4
一、选择题
1 2 3 4 5 6 7 8 9 10 DADEBBCCC A
二、填空题
1 2、12、1、3、-1、2 0123 2222
2 2101 4444
3 name、index 4 preserve、erase 5 ubound、lbound
第六章 过 程
一、选择题
1 2 3 4 5 6 7 8 9 10 DCDCBABAB D 11 12 13 14 15 16 17 18 19 20 ACCDABCDB C
二、填空题
1 bas 2 形式、实际 3 a()、Ubound(b)、n=n-1 4 30、70 5 fedcba、static
三、简答题
6 static 7 static 8 12、7 9 visual basic 程序设计 10 -100
1、简述事件过程和通用过程的含义和联系。
5
VB 应用程序是由过程组成的,过程是完成某种特殊功能的一 组独立的程序代码。VB 中的过程有两大类:事件过程和通用过程
Visual basic 程序设计习题参考答案
第一章 Visual basic 程序设计
一、选择题
1 2 3 4 5 6 7 8 9 10
DC
CDCBAC B
vb程序设计书习题和参考答案
vb程序设计书习题和参考答案练习题习题⼀⼀、判断题1.Visual Basic是以结构化的Basic语⾔为基础、以事件驱动作为运⾏机制的可视化程序设计语⾔。
2.⾯向对象的程序设计是⼀种以对象为基础,由事件驱动对象的编程技术。
3.事件是由Visual Basic预先定义的对象能够识别的动作。
4.新建⼯程时系统会⾃动将窗体标题设置为Form1。
5.控件的属性值不可以在程序运⾏时动态地修改。
6.决定对象是否可见的属性为Visible属性,决定对象可⽤性的属性是Enabled属性。
7.保存Visual Basic⽂件时,若⼀个⼯程包含多个窗体或模块,则系统先保存⼯程⽂件,再分别保存窗体或模块⽂件。
8.单击“启动”菜单项将窗体装⼊内存时,⼀定触发窗体的Load事件。
9.“事件过程”是⽤来完成事件发⽣后所要执⾏的程序代码。
10.在打开某窗体时,初始化该窗体中的各控件,应选⽤Load事件。
⼆、选择题1.⼯程⽂件的扩展名为。
A、.frxB、.basC、.vbpD、.frm2.下列不属于对象的基本特征是。
A、属性B、⽅法C、事件D、函数3.在设计模式双击窗体将显⽰的窗⼝是A、⼯程窗⼝B、⼯具箱C、代码窗⼝D、属性窗⼝4.VB中运⾏程序的快捷键是A、F2B、F5C、Alt+F35.改变控件在窗体中的上下位置应修改该控件的属性。
A、TopB、LeftC、WidthD、Right6.窗体模块的⽂件扩展名是A、.exeB、.basC、.frxD、frm7.设置窗体的字体⽤属性。
A、FontNameB、FontSizeC、FontBoldD、FontItalic8.设置窗体的字号⽤属性。
A、FontNameB、FontSizeC、FontBoldD、FontItalic9.下列选项中不属于事件的是。
A、DblclickB、LoadC、ShowD、KeyUp10.VB编制的程序保存在磁盘上,⾄少会产⽣何种⽂件。
A、.doc与.txtB、.com与.exe.C、.bat与.frmD、.vbp与.frm三、程序设计题1.新建⼀个⼯程,单击窗体时,在窗体上显⽰“欢迎使⽤Visual Basic程序”。
VisualBasic程序设计基础课后习题参考答案
资料内容仅供您学习参考,如有不当或者侵权,请联系改正或者删除。
第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. C2. 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 orm19.Load或Initialize或Resize或Activate( 自动执行的先后顺序也按此排列)10.Activate、 Deactivate四、程序设计题程序1.界面设计参看图10-1、 10-2以及表10-1。
表10-1 实例2各控件的主要属性设置过程设计如下:Private sub Form_Click()Command2.Enabled = FalseEen SubPrivate Sub Command1_Click()Label2.Visible = FalseLabel1.Caption = Text1.Text + ": 欢迎使用" +资料内容仅供您学习参考,如有不当或者侵权,请联系改正或者删除。
Label1.CaptionText1.Visible = FalseCommand1.Enabled = False: Command2.Enabled = True End SubPrivate Sub Command2_Click()EndEnd Sub程序2.界面设计略, 过程设计如下:Private Sub Command1_Click() '字体变大 Form1.FontSize = Form1.FontSize + 3Form1.Cls: Print "欢迎使用VB"End SubPrivate Sub Command2_Click() '字体变小 Form1.FontSize = Form1.FontSize - 3Form1.Cls: Print "欢迎使用VB"End SubPrivate Sub Command3_Click() '字体加粗 Form1.FontBold = TrueForm1.Cls: Print "欢迎使用VB"End SubPrivate Sub Command4_Click() '字体不加粗 Form1.FontBold = FalseForm1.Cls: Print "欢迎使用VB"End Sub运行时, 不得连续、过多次单击”字体变小”按钮, 因为当FontSize属性值小于0会产生适时错误。
VB程序设计教材习题及参考解答
第 1 章概述一、叙述题1.简述VB具有哪些特点。
(1)面向对象的可视化设计工具(2)事件驱动的编程机制(3)易学易用的应用程序集成开发环境(4)结构化的程序设计语言(5)充分利用Windows资源(6)开放的数据库功能与网络支持2.简述事件驱动的程序设计原理。
解答:VB程序的运行没有固定的顺序,它通过事件来激活某个对象,随着该对象的活动,会引发新的事件,这个事件又可能使另一个对象激活,对象之间就是以这种方式联系在一起的。
每个事件都可以通过一段程序(称为“事件过程”)来响应,在事件发生时,系统将自动执行相应的事件过程,用以实现指定的操作并达到运算、处理的目的。
为不同对象响应不同事件编写的事件过程构成了一个完整的应用程序,这就是VB事件驱动的程序设计原理。
3.VB的集成开发环境由哪些元素组成?解答:标题栏、菜单栏、工具栏、工具箱、窗体窗口、代码窗口、工程资源管理器窗口、属性窗口及窗体布局窗口等。
4.VB集成开发环境的工具栏能否自行定义?标准工具栏中包含一些什么按钮?解答:VB集成开发环境的工具栏可以自定义,方法是:用鼠标右击标准工具栏的任意位置,可以打开或关闭其余工具栏。
标准工具栏中包含的按钮有:添加Standard EXE工程、添加窗体、菜单编辑器、打开工程、保存工程、剪切、复制、粘贴、查找、撤销、重复、启动、中断、结束、工程资源管理器、属性窗口、窗体布局窗口、对象浏览器、工具箱、数据视图窗口、可视组件管理器及窗体位置与大小等。
5.当创建只有一个窗体的应用程序后,该工程涉及多少个要保存的文件?若要保存该工程中的所有文件,应先保存什么文件?后保存什么文件?解答:涉及两个文件要保存。
先保存窗体文件(.frm),再保存工程文件(.vbp)。
6.简述用VB开发应用程序的一般步骤。
(1)创建应用程序界面(2)设置界面上各个对象的属性(3)编写对象响应事件的程序代码(4)保存工程(5)运行和调试应用程序(6)创建可执行程序二、单选题1.D VB是一种面向对象的可视化程序设计语言。
VB程序设计教程第四课后答案
vb课后习题答案第一章习题参考答案一、填空题1、对象事件驱动2、编译运行模式解释运行模式二、简答题1、简述VB的特点。
答:①可视化的程序设计方法②面向对象的程序设计思想③事件驱动的编程机制④结构化的程序设计语言⑤高度的可扩充性⑥强大的数据库访问能力⑦支持动态数据交换⑧支持对象链接与嵌入2、简述VB的安装过程。
答:①向光驱中放入VB安装光盘;②计算机将运行自动安装程序,若没有,执行VB目录下的Setup.exe;③根据提示逐一回答问题,并点击“下一步”;④点击“完成”;2、如何启动VB。
答:三种方法:①单击“开始”按钮,选择“程序”菜单下的“Microsoft Visual Basic 6.0 中文版”菜单项并单击;②双击桌面上的VB6.0快捷图标;③在“开始”菜单的运行对话框中输入命令来启动VB;第二章习题参考答案一、选择题:1-10、DCACD BCBBC11-20、BADCA BBAAB21-29、AACBB CDDC二、填空题1.窗体、控件2.属性值3.属性窗口设置、代码窗口设置4.事件过程5.对象名、下划线、事件名6.Form_Click第三章习题参考答案一、选择题1、B2、C3、A4、B5、A6、C7、C二、填空题1、11字符型、字节型、整型、长整型、单精度型、双精度型、货币型、逻辑型、日期型、对象型、变体型。
String、Byte、Integer、Long、Single、Double、Currency、Boolean、Date、Object、Variant2、双引号(英文)、#3、ASCII、1、24、public、通用、Dim、Static、Private、Static5、&、+、+6、Now()、Time、日期型三、解答题1、(3)2、(1 )3、(1)常量(关键字)(2)字符型常量(3)逻辑型常量(4)变量(5)字符串常量(6)变量(7)字符串常量(8)变量(9)日期型常量(题目应是#11/16/1999#)(10)数值型常量(单精度)4、315、(1)(1+y/x)/(1-y/x) (2)x^3+3*x*y/(2-y)(3)sqr(abs(a*b-c^3)) (4)sqr(s*(s-a)*(s-b)*(s-c))6、7、(1)13 (2)17(3)#1999-11-12# (4)zxy123ABC8、(1)19 (2)8.16666666666667(3)5.25 (4)29、(1)-4 (2)2 . 82842712474619 (3)-3 (4)49 (5)”hello” (6)He7)16 (8)“-459.65” (9)510、(4)11、(2)12、(4)第四章习题参考答案一、选择题:1—7: DAABBCD二、填空题1.500.00%2.将字号扩大为原来的二倍3.B三、编程题(略)1.文本框、标签和命令按钮的名称分别为text1、label1、command1Private Sub Command1_Click()Label1.caption=text1.textCommand1.caption=text1.textEnd Sub2.单价、数量、折扣和应付款对应的文本框的名称分别为:text1、text2、text3和text4,计算和清除命令按钮的名称分别为:command1和command2。
VB程序设计教程 习题解答
VB程序设计教程习题解答vb程序设计教程习题解答《VB编程课程》(第三版)问题解决习题1答案一、多项选择题1.1visualbasic6.0分为3种版本,不属于这3种版本的是a)学习版b)专业版c)企业版d)业余版【答】d。
1.2在以下方法中,无法退出Visual Basic的方法是a)按Alt+Qb)按下alt+f组合键,然后按esc键c)按f10键,然后按f键,再按x键d)打开“文件”菜单→“退出”命令【答】b。
1.3 visual basic集成的主窗口不包括a)属性窗口b)标题栏C)菜单栏d)工具栏[answer]a。
1.4下列操作可以打开立即窗口的是a)ctrl+db)ctrl+fc)ctrl+gd)ctrl+e【答】c。
二、填空题1.5与传统编程语言相比,Visual Basic最突出的特点是。
[答:]事件驱动编程机制。
1.6如果不使用鼠标,用键盘打开菜单和执行菜单命令,第一步应按____键。
[答:]功能键F10或alt。
1.7建立一个新的标准模块,应该选择____菜单下的“添加模块”命令。
【答】“工程”菜单。
三、思考问题1.8简述visualbasic的特点。
[答:]与通用编程语言相比,VB具有以下特点:(1)可视化设计平台;(2)面向对象设计方法;(3)事件驱动编程机制;(4)结构化设计语言;(5)充分利用windows资源;(6)开放数据库功能和网络支持。
1.9简述visualbasic集成开发环境的组成。
[答:]VB6 0集成开发环境不仅有标准Windows环境的标题栏、菜单栏和工具栏,还有工具箱、属性窗口、项目管理器窗口、表单设计器、即时窗口和表单布局窗口等有用的开发工具。
(1)标题栏和菜单栏:标题栏中显示的有窗体控制菜单图标、当前激活的工程名称、当前工作模式以及最小化、最大化m还原、关闭按钮。
菜单栏中显示了“文件”、“编辑”、“视图”、“工程”、“格式”等菜单项,其中包含了vb编程的常用命令。
VB程序设计教程课后参考答案
VB程序设计教程课后参考答案习题一一、填空题1.对象、事件驱动2.窗体、控件3.属性4.属性窗口、编程设置5.事件过程6.对象名、下划线、事件名7.Form_click8.Print form1.print “我的VB”9.主窗口、属性、工具箱、代码、窗体、工程资源管理10.菜单、快捷键二、选择题1.C 2. A 3. B 4. B 5. D 6. B C 7. A 三、简答题(略)习题二一、选择题1. D2. C3. C4. B5. C6. B7. C8. B 9. A 10. B 11. B 12. C 13. D 14. B15. A 16. A 17. A 18. A 19. B 20. C 21. A22. B 23. B 24. A 25. C 26. A 27. B 28. B29. C 30. B 31. D 32. D 33. C二、填空题1.Controlbox、Maxbutton、Minbutton2.Multiline TRUE3.******4.单文档界面(SDI)多文档界面(MDI)5.窗体显示6.Passwordchar7._change()三、编程题(略)习题三一、基础知识题(略)二、填空题1.整型、长整型、单精度、双精度2.(x mod 10)*10+x\103.Sin(3.14*15/180)+sqr(x+exp(3))/abs(x-y)-log(3*x)4.(a+b)/(1/(c+5)-c*d/2)5.X mod 5=0 or x mod 9=06.False7.-4、3、-3、3、-4、48.CDEF9.GBCDEFA10.TRUE11.变量、属性12.‘_ :13.(略)14.“”#15.Public、通用/模块、Dim、static、private16.+ 、&、+17.Now() 、time()、日期18.Inputbox()、字符串、val()19.Msgbox()三、选择题1.B 2. C 3. A 4. B D此题有误 5. B 6. A7. D 8. B 9. B 10. C 11. D 12. B13. C 14. B 15. A 16. C 17.A 18. D19. A 20. D 21. A 22. C 23. C 24. D25. A 26. D 27. D 28. B 29. C 30. B31. C 32. B 33. C D此题有误34. C 35. A36. D 37. C 38. A 39. B 40. A 41. C42. C 43. D 44. C 45. D 46. A四、编程题1.Option ExplicitPrivate Sub Command1_Click()Dim a%, b%, c%, delta%Dim x1#, x2#, x#a = Val(InputBox("please input data to a:", "info", 1))b = Val(InputBox("please input data to b:", "info", 1))c = Val(InputBox("please input data to c:", "info", 1))If a = 0 And b <> 0 Thenx = -c / bPrint "所构成的方程是:" & b & "x" & "+" & c & "=0"Print "该一元一次方程的根是:", xEnd IfIf a = 0 And b = 0 ThenPrint "很抱歉,不能构成合法的方程!"End IfIf a <> 0 Thendelta = b * b - 4 * a * cIf delta >= 0 Thenx1 = (-b + Sqr(delta)) / (2 * a)x2 = (-b - Sqr(delta)) / (2 * a)Print "所构成的方程是:" & a & "x2" & "+" & b & "x" & "+" & c & "=0"Print "该方程的根是:"Print "第一个根是:", x1Print "第二个根是:", x2ElsePrint "所构成的方程是:" & a & " x2" & "+" & b & "x" & "+" & c & "=0"Print "该方程有两个虚根:"Print "第一个虚根是:" & -b / (2 * a) & "+" & Sqr(Abs(delta)) / (2 * a) & "i"Print "第二个虚根是:" & -b / (2 * a) & "-" & Sqr(Abs(delta)) / (2 * a) & "i" End IfEnd IfEnd Sub2.Option ExplicitPrivate Sub Command1_Click()Dim i%, s%s = 0For i = 1 To 99 Step 2s = s + iNextPrint sEnd Sub3.Option ExplicitPrivate Sub Command1_Click()Dim i%Dim s#s = 0For i = 1 To 100s = s + 1 / i * (-1) ^ (i + 1)NextPrint sEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim i%, n%Dim t#, s#n = Val(InputBox("please input data:", "info", 5))s = 0t = 1For i = 1 To nt = t * is = s + tNextPrint sEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim a%, b%, c%Dim p#, s#a = Val(InputBox("please input data to a:", "info", 3))b = Val(InputBox("please input data to b:", "info", 4))c = Val(InputBox("please input data to c:", "info", 5))。
VB程序设计教程课后答案解析
A.1Private Sub Comma nd1_Click( Label3 = TextlEnd SubA.2Private Sub Form_Load(Timer1 .In terval = 0End SubPrivate Sub Comma nd1_Click(自动Timer1.I nterval = 200End SubPrivate Sub Comma nd2_Click(手动Timer1.I nterval = 0Call MyMoveEnd SubPrivate Sub Timer1_Timer(Call MyMoveEnd SubSub MyMove(Labell.Move Labell.Left - 50If Labell 丄eft < 0 Then Labell 丄eft = Forml.Width End Sub A. 3Private Sub Form_Click(Text1 = V al(Text1 + 1End SubPrivate Sub Form_Load(Textl = 0End SubA.4Private Sub Form_Click(Caption ="单击窗体,改变图片"Picture = LoadPicture(App.Path + "\n_015.bmp"Print"欢迎使用VB"End SubPrivate Sub Form_DblClick(ClsCaption ="双击窗体,卸去图片"Picture = LoadPicture("”End SubPrivate Sub Form_Load(Caption ="装入窗体"Picture = LoadPicture(App.Path + "\n_016.bmp"Print "装入图"End SubPrivate Sub Form_Resize(该事件的作用窗体始终与图一样大'Caption ="窗体大小不变"'Form1.Width = 260 * 16'260 是Tongji-2.bmp 图的宽度,象素单位'Forml.Height = 260 * 16 + 200'260是图的高度,象素单位,200是窗体的标题栏高度End SubA. 5Sub Comma nd1_Click(Textl.Fo ntName ="隶书”Textl.Fo ntSize = 25End SubSub Comma nd2_Click(Text2.Text = Textl.SelTextText2.Fo ntName = Textl.Fo ntNameText2.Fo ntSize = Textl.Fo ntSizeEnd SubB.1Private Sub Comma nd1_Click(Text2 = Format(5 / 9 * (V al(Text1 - 32, "0.00" End SubPrivate Sub Comma nd2_Click(Text1 = Format(9 / 5 * V al(Text2 + 32, "0.00" End Sub或Private Sub Comma nd1_Click(Dim f!, c!'声明两个变量f = V al(Text1c = 5 / 9 * (f - 32Text2 = Format(c, "0.00"'保留两位小数End SubPrivate Sub Comma nd2_Click(Dim ff!, cc!'声明两个变量cc = V al(Text2ff = 9 / 5 * cc + 32Textl = Format(ff, "0.00"'保留两位小数End SubB.2Label2 = Format(V al(Text1 * V al(Text1 * 3.14, "0.00" End Sub Private Sub Comma nd2_Click(Label3 = Format(V al(Text1 * 3.14 * 2, "0.00"End SubPrivate Sub Text1_LostFocus(If Not lsNumeric(Text1.Text The nMsgBox "输入有非数字字符,请重新输入",,"警告"Textl.Text =""Textl.SetFocusEnd IfEnd Sub或Private Sub Comma nd1_Click(Label2 = Format(V al(Text1 * V al(Text1 * 3.14, "0.00" End Sub Private Sub Comma nd2_Click(Label3 = Format(V al(Text1 * 3.14 * 2, "0.00"End SubPrivate Sub Text1_KeyPress(KeyAscii As In teger If KeyAscii = 13 The nIf Not lsNumeric(Text1.Text The nText1.Text =""End IfEnd IfEnd SubB. 3Private Sub Comma nd1_Click(n = In t(Log(2 / Log(1.008 + 1Label1 = n & "年后人数超过26亿"End SubB.4Private Sub Comma nd1_Click(Dim x, dx, cdx = Text1.Textdx = UCase(xcd = Len(xPrint"大写字母为:";dxPrint"字符串长度为:";cdEnd SubB. 5Textl = In t(R nd * 900 + 100End SubPrivate Sub Comma nd2_Click(Dim x%, x1%, x2%, x3%x = V al(Text1x1 = x Mod 10 '分离出的个位数x2 = (x Mod 100 \ 10 '分离出的十位数x3 = x \ 100 '分离出的百位数Label1 = x1 * 100 + x2 * 10 + x3 End SubB.6Private Sub Form_Click(Label1 = Left(Text1, 11Label2 = Mid(Text1, 12, 6Label3 = Right(Text1,5End SubB.7Private Sub Comma nd1_Click(PrintFor i = 1 To 5Print Tab(15 - i * 2; String(2 * i - 1, " ★"; Spc(18 - 4 * (i - 1; String(2 * i - 1, " ★"Next iEnd SubPrivate Sub Comma nd2_Click(CisEnd Sub进一步要求:Private Sub Comma nd1_Click(PrintFor i = 1 To 5Print Tab(15 - i * 2; String(2 * i - 1, " ★"; String(10 - (2 * i - 1, " ☆"; String(2 * i - 1, "★"Next iEndSubprivateSubCommand2IC=ck(c_sEndSubB.8privateSubFo「mlc=ck(X H < a -(-n p u 65o x (二鸯>—日»達==斗«=pfH Formafx* X - =0-000= pfg H Fo 「maf(sq 「(><=0_fgH Folmafx> (1、3=0.000=Prinf=:=pf 八space(5八U H R :=pfg八 space(5八2二f八space©诺R 2二fgEndSub0--privateSubFo「mlc=ck(XH< a-(-n p u 65o x (二鸯> 妄血一fxA-0Elself x < 2000 Then y = 0.9 * x Elself x < 3000 Then y = 0.8 * x Else y = 0.7 * xEnd IfPrint yEnd SubC. 2Private Sub Form_Click(Dim x!, y!x = V al(lnputBox("输入上网时间"If x < 10 The n y = 30Elself x < 50 The n y = 30 + 2.5 * (x - 10Elsey = 30 + 2.5 * 40 + 2 * (x - 50End IfIf y > 150 The ny = 150End IfPrint yEnd SubC. 3Private Sub Comma nd1_Click(Dim x!, y!, z!x = In putBox("i nput x"y = In putBox("i nput y"z = In putBox("i nput z"Print " x y z"Print "排序前";x; " "; y; " ";zIf x < y The n t =x:x = y: y = tIf x < z The n t =x:x = z: z = tIf y < z The n t =y:y = z: z = tPrint "排序后"& x & " " & y & " " & z End SubPrivate Sub Comma nd2_Click(Dim x!, y!, z!x = In putBox("i nput x"y = In putBox("i nput y"z = In putBox("i nput z"Print " x y z"Print "排序前";x; " "; y; " "; zIf x < y The n t = x: x = y: y = tIf y < z The nt = y: y = z: z = tIf x < y The nt = x: x = y: y = tEnd IfEnd IfPrint "排序后"& x & " " & y & " " & z End Sub C.4Dim a(3 As In tegerPrivate Sub Comma nd1_Click(Picturel.CIsFor i = 0 To 2 a(i = Int(Rnd * 100 + 200 Picturel.Pri nt a(iNext iEnd SubPrivate Sub Comma nd2_Click( Picture2.ClsDim z As In tegerFor i = 0 To 1If a(i > a(i + 1 The nz = a(i + 1a(i + 1 = a(ia(i = zNext iPicture2.Pri nt a(0Picture2.Pri nt a(1Picture2.Pri nt a(2End SubC.5Private Sub Text2_LostFocus(Dim m%, n%, y%m = V al(Text1n = V al(Text2If n Mod 2 <> 0 The nMsgBox ("脚数必定为偶数"Text2 =""Text2.SetFocusElsey = n / 2 - mIf y < 0 The nMsgBox ("脚数必须倍的头数,请重新输入Text2 =""Text2.SetFocusElsex = n / 2 - mLabel2 = yLabel3 = m - yEnd IfEnd IfEnd SubC.6Private Sub Comma nd1_Click(Dim a!, b!, c!, x1!, x2!, de!a = Text1b = Text2c = Text3de = b * b - 4 * a * ct = 2 * aIf de = 0 The nText4 = Format(-b / t, "0.00"Text5 = Format(-b / t, "0.00"Elself de > 0 The nText4 = Format((-b + Sqr(de / t, "0.00"Text5 = Format((-b - Sqr(de / t, "0.00"Text4 = Format(-b / t, "0.00" & "+" & Format(Sqr(Abs(de / t, "0.00" & "i" Text5 = Format(-b / t, "0.00" & "-" & Format(Sqr(Abs(de / t, "0.00" & "i" E nd IfEnd SubPrivate Sub Comma nd2_Click( Textl =""Text2 =""Text3 =""Text4 =""Text5 =""End SubC.7Private Sub Text3_LostFocus( Select Case Trim(Text3Case "+"Text4 = V al(Text1 + V al(Text2 Case "-"Text4 = V al(Text1 - V al(Text2 Case "*"Text4 = V al(Text1 * V al(Text2 Case "/"If V al(Text2 = 0 Then MsgBox "分母为零,重新输入"Text2 =""Text2.SetFocusElseText4 = V al(Text1 / V al(Text2 End IfEnd SelectEnd SubC.8Private Sub Text1_LostFocus( Select Case Trim(Text1Case 1Text2 = "Mo nday"Case 2Text2 = "Tuesday"Case 3Text2 = "Wed nesday"Case 4Case 5Text2 = "Friday"Case 6Text2 = "Saturday"Case 7Text2 = "Su nday"Case Is > 7, Is < 1MsgBox "数字为1~7,重新输入" Textl =""Text1.SetFocusEnd SelectEnd Sub或者Private Sub Text1_LostFocus( If Text1 > 7 Or Textl < 1 The n MsgBox "数字为1~7,重新输入" Textl =""Textl.SetFocusElseText2 = Choose(Text1, "Mo nday", "Tuesday", "Wed nesday", "Thursday", "Friday", "Saturday", "Su nday"End IfEnd SubD.1Private Sub Form_Click(For i = 1 To 9Print Tab(10 - i; String(2 * i - 1, Trim(Str(iNext iEnd SubD.2Private Sub Form_Click(For i = 1 To 10 Step 1Print Tab(i; Stri ng((20 - 2 * i, Chr(64 + iNext iEnd SubD.3Private Sub Comma nd1_Click(Dim s!, t!, i&t = 1For i = 1 To 100000t = t + is = s + 1 / tIf 1 / t < 0.00001 Then Exit ForNext iPrin t "For 结构";s, i;"项"End SubD.4Private Sub Comma nd1_Click(Dim n&, pi#, i&n = InputBox("输入n 值"pi = 2For i = 1 To npi = pi * (2 * i / (2 * i - 1 * (2 * i / (2 * i + 1 Next i Print "当n=" & n & ” 时,pi="; piEnd SubD.5Private Sub Form_Click(Dim s!, t!, i!, a%, n%a = In t(R nd * 9 + 1n = In t(R nd * 6 + 5t = 0: s = 0Prin t "a="; a, " n二";nFor i = 1 To nt = t * 10 + as = s + tPrint t;Next iPrintPrin t "s="; sEnd SubD.6Private Sub Comma nd1_Click( Dim s As In tegers = 0For i = 1 To 9Forj = 0 To 9For k = 0 To 9s = i * 100 + j * 10 + kIf s = i A 3 + j A 3 + k A 3 The nPrint sEnd IfNext kNext jNext iEnd SubPrivate Sub Comma nd3_Click( formd6.Hide main .ShowEnd SubD.7Private Sub Comma nd1_Click(Dim a!, xO!, x1!Doi = i + 1x1 = 2 * x0 / 3 + a / (3 * x0 * x0If Abs(x1 - x0 < 0.00001 Then Exit Do x0 = x1 LoopPrint x1, iEnd SubD.8Private Sub Comma nd1_Click(s = 0x0 = 0.01For i = 1 To 30s = s + x0x0 = x0 * 2Next iEnd SubD.9Private Sub Comma nd4_Click(Picturel.CIsPicture1.Print "x 课安排在";"y 课安排在";"z 课安排在"Picturel.Print ""For z = 5 To 6For x = 1 To z - 2For Y = x + 1 To z - 1X1 = Choose(Weekday(x,'周一","周二","周三","周四","周五","周六","周日"Y1 = Choose(Weekday(Y,'周一","周二","周三","周四","周五","周六","周日"z1 = Choose(Weekday(z,周一","周二","周三","周四","周五","周六","周日" Picturel.Pri nt" "; X1; ""; Y1; " "; z1Next YNext xNext zEnd SubE.1Private Sub Form_Click(Dim a(1 To 10 As In tegerFor i = 1 To 10a(i = In t(R nd * 71 + 30Print a(i;"";Next iMax = a(1Min = a(1A vg = a(1For i = 2 To 10If a(i > Max The n Max = a(iIf a(i < Min Then Min = a(iA vg = A vg + a(iNext iA vg = A vg / 10PrintPrint "Max="; Max; " Min="; Min;" A vg="; A vg End SubE.2Private Sub Form_Click(Dim aa = Array(56, 78, 98, 88, 76, 78For i = 0 To 5Print Stri ng(a(i \ 5, " ♦"; a(iPrintNext iEnd SubE.3Dim a%(19Private Sub Comma nd1_Click( Picturel.CIsFor i = 0 To 19a(i = Int(Rnd * 101Picturel.Pri nt a(i;"";If (i + 1 Mod 4 = 0 The n Picturel.Pri nt Next iEnd SubPrivate Sub Comma nd2_Click( Picture2.CIsDim s(5 To 9For i = 0 To 19Select Case kCase 0 To 5s(5 = s(5 + 1Case 9 To 10 '90~10(分的人数s(9 = s(9 + 1Case 6 To 8 '存放其他三个分数段的下标有规律,根据K获得s(k = s(k + 1 End SelectNext iFor i = 5 To 9If s(i <> 0 Then Picture2.Print "s("; i;"的人数有";Format(s(i, "0";"个"Next i End SubE.4Private Sub Comma nd1_Click(Picture1.ClsDim d%(1 To 10For i3 = 1 To 10Ran domized(i3 = Int(Rnd * 91 + 10For i = 1 To 10For j = 1 To 10 - iIf d(j < d(j + 1 The nt = d(j: d(j = d(j + 1: d(j + 1 = t End IfNext jNext iFor i = 1 To 10: Picture1.Pri nt d(i; If i Mod 5 = 0 Then Picture1.Print Next iEnd SubE.5Dim a%(3, 3, b%(3, 3Private Sub Form_Load(For i = 0 To 3Forj = 0 To 3a(i, j = In t(R nd * 36 + 35b(i, j = Int(Rnd * 41 + 100Next iEnd SubPrivate Sub Comma nd1_Click( Picturel.CIsFor i = 0 To 3Forj = 0 To iPicture1.Pri nt a(i, j;"";Next jPicture1.Pri ntNext iEnd SubPrivate Sub Comma nd2_Click( Picture2.ClsFor i = 0 To 3For j = i To 3Picture2.Pri nt Tab(j * 6; b(i, j; Next jPicture2.Pri ntEnd SubPrivate Sub Comma nd3_Click( Picture3.Clssa = 0For i = 0 To 3sa = sa + a(i, iNext isb = 0For i = 0 To 3sb = sb + b(i, 3 - iNext iPicture3.Print "A数组主对角线元素和为:";sa Picture3.Print "B数组副对角线元素和为:";sb End SubE.6Private Sub Form_Click(n = InputBox("输入n 值"ReDim a6%(n + 1, n + 1a6(0, 0 = 1: a6(1, 1 = 1: a6(1, 0 = 1For i = 2 To n + 1Forj = 2 To ia6(i, j = a6(i - 1, j - 1 + a6(i - 1, j Picturel.Print a6(i, j;""Next jPicturel.Pri ntNextEnd SubE.7Private Sub Form_Load(List1.ClearList1.Addltem "大学计算机基础"List1.Addltem "C/C++ 程序设计"List1.AddItem "VB 程序设计"List1.AddItem "Web 程序设计" Listl.Addltem "多媒体技术与应用" Listl.Addltem "数据库技术与应用" Listl.Addltem "网络技术与应用" Listl.Addltem "硬件技术基础"Listl.Addltem "软件技术技术基础" Private Sub List1_Click(If List2丄istCount >= 5 Then MsgBox ("超过5门课程,不能再选"Exit SubElseList2.Addltem List1.TextList1.Removeltem List1.ListIndexEnd IfEnd SubE.8Sub Combo1_KeyPress(KeyAscii As In teger Select Case KeyAscii Case 48 To 57, 13Case ElseKeyAscii = 0End SelectIf KeyAscii = 13 The nCombo1.Addltem Combo1.TextEnd SubPrivate Sub Comma nd1_Click(Dim mi n%, max%min = V al(Combo1.List(0max=V al(Combo1.List(0=imin=0=imax =0Fori : =1 To Combol.ListCount - 1 If V al(Combo1 丄ist(i > max Then imax = i=Combol. List(imax=Elself V al(Combo1 .L ist(i < min Then imin = imin = C ombol. List(iEnd IfNext it = Combo1.List(0Combol. List(0 = Combo1.List(iminCombo1.List(imin = tt = Combol 丄ist(Combo1.ListCount - 1Combol.List(Combo1.ListCount - 1 = Combo1.List(imax Combo1.List(imax = t End SubE.9Private Sub Form_Click(For i = 0 To Scree n.Fo ntCou nt - 1If Asc(Left(Scree n.Fo nts(i, 1 < 0 The nPicture1.Pri nt Scree n.Fon ts(iPicture2.F on tName = Scree n.Fon ts(iPicture2.Print"商丘师范学院"End IfNext iEnd SubE.10Private Type clerknu mber As Stri ng * 3n ame As Stri ng * 5salary As In tegerDim a(0 To 4 As clerk, n%Private Sub Comma nd1_Click(If n >= 5 The nMsgBox ("输入人数超过数组声明的个数"ElseWith a(n.nu mber = Text1.n ame = Text2.salary = Text3Picture1.Print a(n.number, a(, a(n.salary Print End Withn = n + 1Text1 =""Text2 =""Text3 =""End IfEnd SubPrivate Sub Comma nd2_Click(Dim t As clerk, i%, j%For i = 0 To n - 1For j = i To n - 1If a(i.salary < a(j + l.salary Then t = a(i: a(i = a(j + 1: a(j + 1 = t End If Next jNext iPicture1.ClsPicture1.Print "工号姓名工资"For i = 0 To n - 1Picture1.Pri nt a(i .nu mber, a(i .n ame, a(i.salaryPrintNext iEnd SubF.1Private Sub Form_Click(Dim a(1 To 10, ami n, i%For i = 1 To 10a(i = -In t(R nd * 101 + 300Print a(i;Next iCall s(a(, aminPrintPrint "min="; aminEnd SubSub s(b(, minDim i%min = b(LBo un d(bFor i = LBou nd(b + 1 To UBou nd(bIf b(i < min Then min = b(iNext iEnd SubF.2Private Sub Comma nd1_Click(Dim mm%, nn%mm = V al(Text1nn = V al(Text2Picturel.Pri nt mm; Tab(6; nn; Tab(12; gcd(mm, nn End Sub Fun ction gcd%(ByV al m%, ByV al n%If m < n The n t = m: m = n: n = tr = m Mod nDo While (r <> 0m = n: n = r: r = m Mod nLoopgcd = nEnd FunctionF.3Dim x!Private Sub Comma nd1_Click(Print "调用标准函数Sin的结果";Sin(xEnd SubPrivate Sub Comma nd2_Click(Print "调用自定义函数MySin的结果";MySin(x End Sub Fu nction MySi n(x! As DoubleDim i%, t!, s!t = xs = tDo While Abs(t > 0.00001t = -1 * t * x * x / ((i + 1 * (i + 2s = s + ti = i + 2LoopMySin = sEnd FunctionPrivate Sub Comma nd3_Click(x = In putBox("输入要计算正弦函数的角度值x" x = x * 3.14 / 180End SubF.4Private Sub Text1_KeyPress(KeyAscii As In teger If KeyAscii = 13 Then If Not lsNumeric(Text1 The nMsgBox "输入非数字串,重新输入"Text1.Text =""Text1.SetFocusElsePicture1.Pri nt Text1; " ★"ElsePicturel.Pri nt TextlEnd IfTextl =""End IfEnd IfEnd SubFunction IsH(ss As Stri ng As Boolea n Dim i%, Ls%IsH = Truess = Trim(ssLs = Len(ssFor i = 1 To Ls \ 2If Mid(ss, i, 1 <> Mid(ss, Ls + 1 - i, 1 Then IsH = FalseExit FunctionEnd IfEnd FunctionF.5Function prime(ByV al m As In teger As Boolea nprime = TrueDim i%For i = 2 To m - 1If (m Mod i = 0 Then prime = False: Exit Function '注意冒号和exit 的范围Next i End FunctionPrivate Sub Comma nd1_Click(n = 0For i = 6 To 100 Step 2Forj = 3 To i\2If prime(j The nIf prime(i - j ThenList1.Addltem i & " =" & j & " +" & i - jn = n + 1End IfEnd IfNext iPicturel.Print" 6和100之间共有";n;"对素数和" End SubF.6Dim a%(Private Sub Form_Click(Print "1000以内的完数为:"For i = 1 To 1000If lsWs(i The nPrint i; "=1";For j = 1 To UBou nd(aPrin t "+"; a(j;Next jPrintEnd IfNext iEnd SubFunction lsWs(m As Boolea nDim s%ForiH _k Tom一2-f3Mod iHThenReDimPreserve異Hiu-j+1sHs +iEnd _fNexfiprivate SubDe-esf 「(slAs siring"ByVa-s2Asss.ngDimi%-S2HLen(s2 i H-nsf 「(s严s2Dowh=e iVosi HLeft(s 「i11+Mid(s严 i+-甘卅那『>End SubPrivate Sub Command1_Click('调用DeleStr 子过程Dim ss1 As String ss1 = Text1Call DeleStr(ss1, Text2Text3 = ss1End SubPrivate Sub Comma nd2_Click(End SubF.8Private Sub Comma nd1_Click(Dim maxw$maxle n Text1 & ” ", maxwText2 = maxwEnd SubSub maxle n( s$, maxw$Dim word$maxw =""Do While s <> "" i = In Str(s,""word = Left(s, i - 1If Len( word > Len( maxw Then maxw = word s = Mid(s, i + 1 LoopEnd SubG.1Private Sub Comma nd1_Click(List1.ClearList1.Addltem Combo1If Option1 Then List1.AddItem "Pentium II"If Option2 Then List1.AddItem "Pentium I"If Option3 Then List1.AddItem "Celeron"List1.AddItem Text1If Check1 Then List1.AddItem "声卡"If Check2 Then List1.AddItem "Modem"If Check3 Then List1.AddItem "网络适配器"End SubPrivate Sub Text1_LostFocus(st = UCase(Trim(Text1le = Len(stIf Not lsNumeric(Left(st, le - 2 Or Right(st, 2 <> "MB" Then MsgBox "有不合法字符!"Text1 =""Text1.SetFocusEnd IfEnd SubG.2Private Sub Check1_Click(Picture1.Fo nt.Bold = Not Picture1.Fo nt.BoldEnd SubPrivate Sub Check2_Click(Picture1.Fo nt.ltalic = Not Picture1.F on t.BoldEnd SubPrivate Sub Comma nd1_Click(Picture1.ClsIf Optio n1 The nPicture1.Print Sin(V al(Text1ElseIf Optio n2 ThenPicturel.Print Exp(V al(Text1Elself Optio n3 The nPicturel.Print Sqr(V al(Text1End IfEnd SubPrivate Sub return_Click(l ndex As In tegerForm6.ShowUn load Form2End SubG.3Private Sub HScroll1_Cha nge(Text1 = VScroll1.V alueText2 = HScroll1.V alueText3 = HScroll2.V alueText4 = Format(V al(Text1 * (Text3 / 100 * (Text2 / 12, "0.00" Text5 = Format(V al(Text4 + V al(Text1, "0.00"End SubPrivate Sub HScroll2_Cha nge(Textl = VScrolll.V alueText2 = HScrolll.V alueText3 = HScroll2.V alueText4 = Format(V al(Text1 * (Text3 / 100 * (Text2 / 12, "0.00" Text5 = Format(V al(Text4 + V al(Text1, "0.00"End SubPrivate Sub VScroll1_Cha nge(Textl = VScrolll.V alueText2 = HScrolll.V alueText3 = HScroll2.V alueText4 = Format(V al(Text1 * (Text3 / 100 * (Text2 / 12, "0.00" Text5 = Format(V al(Text4 + V al(Text1, "0.00"End SubG.4Dim t As Sin glePrivate Sub Comma nd1_Click(t = InputBox("输入倒计时分钟数"t = t * 60ProgressBar1.Min = 0ProgressBar1.Max = t。
最新VB程序设计课后习题答案资料
VB课后习题解答第一、二章:1、简述VB6.0的主要特点答:方便、直观的可视化设计工具;面向对象程序设计方法;事件驱动的编程机制;易学易用的应用程序集成开发环境;结构化程序设计语言;完备的联机帮助功能;强大的多媒体、数据库和网络功能。
2、当正常安装VB6.0后,误把Windows子目录删除。
当重新安装Windows后,是否需要再次安装VB6.0 ?答:要重新安装的。
因为安装VB6.0时,有些VB程序被系统自动安装在Windows目录下,所以一旦删除Windows子目录,就必须重新安装VB6.0。
3、Visual Basic 6.0分为学习版、专业版和企业版,如何知道所安装的是哪个版本?答:在VB6.0的启动界面上,能显示对应的版本。
4、叙述建立一个完整应用程序的过程答:首先建立用户界面的控件对象(简称控件);然后对控件属性进行设置;再对控件事件过程及编程;保存应用程序;程序调试和运行。
5、Visual Basic 6.0有多种类型窗口,若要在设计时看到代码窗口,应怎样操作?答:选择“视图”一>“代码窗口”命令或单击“工程资源管理器”窗口中的“查看代码”按钮。
6、当建立好一个简单的应用程序后,假定该工程仅有一个窗体模块。
试问该工程涉及多少个要保存的文件?若要保存该工程的所有文件,应先保存什么文件?再保存什么文件?若不这样做,系统会出现什么信息?答:涉及两个文件要保存。
先保存窗体文件(.frm),再保存工程文件(.vbp)。
若先保存工程文件,系统也会先弹出“文件另存为”对话框,要求先保存窗体文件。
7、保存文件时,若不改变目录名,则系统默认的目录是什么?答:系统默认的目录是VB98& 安装Visual Basic 6.0后,帮助系统是否也已安装?答:没有。
VB6.0的帮助系统在两张光盘上,即MSDN Library,其中还包含了VC、VFP等其他语言的帮助系统。
9、如何使用Visual Basic 6.0的帮助系统?答:最方便的方法是选定要帮助的内容,然后按F1功能键,这时系统打开MSDN Library查阅器,直接显示与选定内容有关的帮助信息。
大学计算机VB程序设计教程课后答案
第1章概述二.选择题:1.C2. B.3.C.4.C.5.A6.C7.D8.B9.B 10.B11.A12.C 13.D 14.C 15.D16.A17.C 18.A19.A20.D 21.B三.填空题:1.面向对象,事件驱动2.编译,解释3.设计,运行,中断4.F55.调试6.切换文件夹四.编程及上机调试:1.略2.Sub Form_Click( )Label1.Caption = “你单击了窗体”End SubSub Form_DblClick( )Label1.Caption = “你双击了窗体”End Sub第2章面向对象编程基础二.选择题:1.C2. C.3.B.4.B.5.D6.D7.B8.B9.C 10.D11.B 12.B 13.B 14.C 15.A16.B 17.B 18.B 19.C 20.B三.填空题:1.窗体,控件2.属性,事件,方法mand2_click4.picture5.中部,代码四.编程及上机调试:1.Private Sub Command1_Click()Form1.WindowState = 2End SubPrivate Sub Command2_Click()Form1.WindowState = 0Private Sub Command3_Click()Form1.WindowState = 1End Sub2.Private Sub Command1_Click()Form1.Picture = LoadPicture("d:\picture\flower.wmf")Command1.V isible = FalseCommand2.V isible = FalseEnd SubPrivate Sub Command2_Click()EndEnd SubPrivate Sub Form_DblClick()Form1.Picture = LoadPicture("")Command1.V isible = TrueCommand2.V isible = TrueEnd Sub第3章常用标准控件二.选择题:1.C2. B3.C.4.D5.B6.B7.A8.C9.B 10.C11.C 12.A13.C 14.B 15.D16.D 17.C 18.A19.D 20.A21.B三.编程及上机调试:1.Private Sub Check1_Click()If Check1.V alue = 1 ThenText1.FontBold = TrueElseText1.FontBold = FalseEnd IfEnd SubPrivate Sub Check2_Click()If Check2.V alue = 1 ThenText1.FontItalic = TrueElseText1.FontItalic = False End IfEnd SubPrivate Sub Check3_Click()If Check1.V alue = 1 ThenText1.FontUnderline = True ElseText1.FontUnderline = False End IfEnd SubPrivate Sub Command1_Click() Text1.Text = " "End Sub2.Private Sub Command1_Click() Text2.Text = List1.ListCount End SubPrivate Sub Command2_Click() List1.AddItem Text1.TextText1.Text = " "End SubPrivate Sub Command3_Click() Dim i As Integeri = List1.ListIndexList1.RemoveItem iCommand3.Enabled = FalseText1.SetFocusText2.Text = List1.ListCount End SubPrivate Sub Form_Load()Command3.Enabled = False End SubPrivate Sub List1_Click()Command3.Enabled = True End Sub第4章VB语言基础二.选择题:1.A2. D3.D.4.A5.A6.A7.C8.D9.C 10.B11.A 12.D 13.C 14.A15.A16.C 17.D 18.A19.B 20.D21.C 22.A23.B 24.C 25.C三.编程及上机调试:1.Private Sub Form_Load()Dim x As Integer, s As String, d As IntegerRandomizex = Int(Rnd * 9000 + 1000)s = Trim(CStr(x))d = V al(Right(s, 1) + Mid(s, 3, 1) + Mid(s, 2, 1) + Left(s, 1))ShowPrint "产生的数;"; x; "倒序数"; dEnd Sub2.Private Sub Form_KeyPress(KeyAscii As Integer)Print "输入字符:"; Chr(KeyAscii), "ASCII码为:"; KeyAsciiEnd SubPrivate Sub Form_DblClick()ClsEnd Sub3.Private Sub Form_Click()MsgBox "在这里显示提示" & vbCrLf & "提示信息", 2 + 16, "请确认"End Sub或Private Sub Form_Click()MsgBox "在这里显示提示" + Chr(13) + "提示信息", vbAbortRetryIgnore _ + vbCritical, "请确认"End Sub第5章程序控制结构二.单选题1.D2. C3.C.4.D.5.B6.C7.A8.A9.D 10.C11.C 12.C 13.B 14.B四.编程及上机调试1. Private Sub Form_Click()Dim x As Integer, y As Integerx = InputBox("请输入一个数值")If x > 20 Theny = x ^ 2 + 3 * x + 2ElseIf x >= 10 Theny = Sqr(3 * x) - 2ElseIf x > 0 Theny = 1 / x + Abs(x)End IfPrint "x="; x, "y="; yEnd Sub(2)Select Case实现:Private Sub Form_Click()Dim x As Integer, y As Integerx = InputBox("请输入一个数值")Select Case xCase Is > 20y = x ^ 2 + 3 * x + 2Case Is >=10y = Sqr(3 * x) - 2Case Is > 0y = 1 / x + Abs(x)End SelectPrint "x="; x, "y="; yEnd Sub2.Private Sub Form_Click()Dim a As Integer, b As Integer, c As IntegerFor i = 100 To 999a = i \ 100b = (i - a * 100) \ 10c = i Mod 10If a ^ 3 + b ^ 3 + c ^ 3 = i ThenPrint i;k = k + 1If k Mod 2 = 0 Then PrintEnd IfNext iEnd Sub3.Private Sub Command1_Click()p = 60: r = 0.014Dop = p * (1 + r)n = n + 1Loop Until p >= 70Print n; "年后世界人口达到"; p; "亿"End Sub4.Private Sub Command1_Click()Dim s As Single, x As Integer, t As Single, n As Integer x = V al(InputBox("请输入x的值", , 2))s = 1n = 1m = 1Don = n + 1m = -mt = m * n / x ^ (n - 1)If Abs(t) < 0.00001 Then Exit Dos = s + tLoopPrint sEnd Sub第6章数组二.单选题:1.A2.A.3.A4.C5.D6.D7.A8.D9.B 10.B四.编程及上机调试:1.Option Base 1Private Sub Form_Click()Dim a(10) As IntegerDim i As Integer, t As IntegerPrint "数组的原始数据为:";For i = 1 To 10a(i) = Int(11 * Rnd) + 10Print a(i);Next iPrintPrint "变化后数组数据为:";For i = 1 To 5t = a(i)a(i) = a(10 - i + 1)a(10 - i + 1) = tNext iFor i = 1 To 10Print a(i);Next iEnd Sub2.Option Base 1Private Sub Form_Click()Dim a(3, 4) As Integer, i As Integer, j As Integer, k As Integer, p As Integer RandomizeFor i = 1 To 3For j = 1 To 4a(i, j) = Int(90 * Rnd + 10)Print a(i, j);Next jPrintNext iMax = a(1, 1): k = 1: p = 1For i = 1 To 3For j = 1 To 4If a(i, j) > Max ThenMax = a(i, j)k = ip = jEnd IfNext jNext iPrint "最大的数为第" & k & "行,第" & p & "列的数:" & MaxEnd Sub3.Option Base 1Dim a(4, 5) As Integer '在窗体声明段声明数组Dim i As Integer, j As IntegerPrivate Sub cmdmatrix_Click() '"生成数组"按钮RandomizeFor i = 1 To 4For j = 1 To 5a(i, j) = Int(Rnd * 10) '一位的随机数Picture1.Print a(i, j); '输出元素Next jPicture1.PrintNext iEnd SubPrivate Sub cmdcol_Click() '"求列和"按钮Dim colsum As Integertxtcol.Text = ""For j = 1 To 5 '列变量先循环colsum = 0For i = 1 To 4colsum = colsum + a(i, j)Next itxtcol.Text = txtcol.Text & Str(colsum)Next jEnd SubPrivate Sub cmdrow_Click() '"求行和"按钮Dim rowsum As Integertxtrow.Text = ""For i = 1 To 4 '行变量先循环rowsum = 0For j = 1 To 5rowsum = rowsum + a(i, j)Next jtxtrow.Text = txtrow.Text & CStr(rowsum) & vbCrLf Next iEnd SubPrivate Sub cmdclear_Click() '"清除"按钮Picture1.Clstxtcol.Text = ""txtrow.Text = ""End SubPrivate Sub cmdexit_Click() '"结束"按钮EndEnd Sub4. Option Base 1Private Sub Form_Click()Dim a() As Integer, b() As Integer, i As Integer, j As Integer, x As Integer, y As Integer x = InputBox("第一维上界")Do While Not IsNumeric(x)x = Int(InputBox("第一维上界"))Loopy = InputBox("第二维上界")Do While Not IsNumeric(x)y = Int(InputBox("第二维上界"))LoopReDim a(x, y)Print "原数组元素为:"For i = 1 To xFor j = 1 To ya(i, j) = Int(90 * Rnd) + 10Print a(i, j);Next jPrintNext iPrint "转置后数组元素为:"For i = 1 To yFor j = 1 To xPrint a(j, i);Next jPrintNext iEnd Sub5. Option Base 1Private Sub Form_Click()Dim a(10, 10) As Integer, i As Integer, j As IntegerFor i = 1 To 10For j = 1 To 10If i = j Or i + j = 11 Thena(i, j) = 0Elsea(i, j) = 1End IfPrint a(i, j);Next jPrintNext iEnd Sub6. Option ExplicitOption Base 1Private Sub Command1_Click()Dim i As Integer, j As Integer, n As Integer, k As Integer, a(11) As Integerj = 1For i = 3 To 21 Step 2a(j) = iPrint a(j);j = j + 1Next iPrintn = InputBox("请输入一个数")For i = 1 To 10If n = a(i) ThenFor j = i To 10a(j) = a(j + 1)k = k + 1Next jEnd IfNext iFor i = 1 To 9Print a(i);Next iEnd Sub7. Option Base 1Private Sub Form_Click()Dim a As V ariant, k As Integer, i As Integer, j As IntegerDim b As V ariantb = Array(17, 35, 128, 235, 89, 121, 143, 189, 231, 94)a = Array(11.3, 12.3, 12#, 11.8, 12.6, 11.6, 12.8, 11.8, 12.4, 12.1)For i = 1 To 9 '对数组a的元素排序k = iFor j = i + 1 To 10If a(k) > a(j) Then k = jNext jIf k <> i Then '数组b的元素随数组a的元素一起变动t = a(i)a(i) = a(k)a(k) = tt = b(i)b(i) = b(k)b(k) = tEnd IfNext iPrint "按名字的排列顺序为:"For i = 1 To 10If Len(b(i)) = 2 Then b(i) = "0" & b(i) '补上数组b中长度为2的编号前的"0"Print "第" & i & "名的号码为:" & b(i) & ",成绩为:" & a(i)Next iEnd Sub第7章过程二、单选题1.C2. D3.C4.D5. B6.A7. B8.B9.C 10.D11.C 12.D 13.B 14.B 15.C16.A17.B 18.B三、填空题1.52 512.4 118 353.1 3 5四.编程及上机调试:1. Private Sub Command1_Click()Dim n As IntegerFor n = 100 To 1600 Step 500Print "n="; n; "时π的近似值是:"; pi(n)Next nEnd SubPrivate Function pi(x As Integer) As SingleDim s As Single, k As Integer, m As Integers = 0k = 1m = 1Dos = s + m / km = -mk = k + 2Loop While k <= xpi = 4 * sEnd FunctionPrivate Sub Command2_Click()EndEnd Sub2. Private Sub Command1_Click()Dim x As Integer, i As Integerx = V al(Text1)For i = 1 To xIf prime(i) And prime(x - i) ThenLabel2 = Str(x) & "是" & Str(i) & "和" & Str(x - i) & "两个素数之和"Exit SubEnd IfNext iEnd SubPrivate Function prime(x As Integer) As BooleanFor i = 2 To Int(Sqr(x))If x Mod i = 0 Thenprime = FalseExit FunctionEnd IfNext iprime = TrueEnd FunctionPrivate Sub Command2_Click()EndEnd Sub3. Option ExplicitOption Base 1Dim a(10) As IntegerPrivate Sub Command1_Click()RandomizeDim i As IntegerFor i = 1 To 10a(i) = Int(Rnd * 90) + 10Text1 = Text1 + Str(a(i))Next iCall sort(a)For i = 1 To 10Text2 = Text2 + Str(a(i))Next iEnd SubPrivate Sub sort(a() As Integer)Dim k As Integer, i As Integer, j As Integer, t As Integer k = UBound(a)For i = 1 To k - 1For j = i + 1 To kIf a(i) < a(j) Thent = a(i)a(i) = a(j)a(j) = tEnd IfNext jNext iEnd SubPrivate Sub Command2_Click()EndEnd Sub4. Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, j As Integer, s As IntegerFor i = 2 To 1000S=0For j=1 To i - 1If I mod j=0 Then s=s+jNext jIf s=i Then Print I,Next iEnd Sub5. Public a(10) As IntegerPublic Sub sort(a() As Integer)Dim i As Integer, j As Integer, t As IntegerFor i = 1 To UBound(a) - 1For j = i + 1 To UBound(a)If a(i) > a(j) Thent = a(i)a(i) = a(j)a(j) = tEnd IfNext jNext iEnd SubPublic Function max(a() As Integer) As Integermax = a(1)For i = 2 To UBound(a)If max < a(i) Thenmax = a(i)End IfNext iEnd Function窗体Form1代码Private Sub Command1_Click()Dim i As IntegerRandomizeFor i = 1 To UBound(a)a(i) = Int(Rnd * 90) + 11Text1 = Text1 & Str(a(i))Next iEnd SubPrivate Sub Command2_Click()Form1.HideForm2.ShowEnd SubPrivate Sub Command3_Click()Text2 = max(a)End SubPrivate Sub Command4_Click()EndEnd Sub窗体Form2代码Private Sub Command1_Click()Call sort(a)For i = 1 To UBound(a)Text1 = Text1 & Str(a(i))Next iEnd SubPrivate Sub Command2_Click()Form2.HideForm1.ShowEnd Sub第8章程序调试二.上机调试题1. Option ExplicitPrivate Sub Form_Click()Dim a() As Single, i As IntegerDim y As Singlei = 1DoReDim a(i) …改为ReDim Preserve A(I) a(i) = 1 / fib(i)If a(i) <= 0.0001 Then Exit Do …改为a(i) < 0.0001 y = y + a(i)i = i + 1LoopPrint "y="; yFor i = 1 To UBound(a)Print a(i);Next iEnd SubPrivate Function fib(i As Integer) As IntegerIf i = 1 Thenfib = 1ElseIf i = 2 Thenfib = 2ElseFib(i)= fib(i - 1) + fib(i - 2) …改为Fib=Fib(I-1)+Fib(I-2) End IfEnd Function2. Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, k As Integer, st As StringFor i = 10 To 500If wanshu(i) Thenst = CStr(i)Text1.Text = Text1.Text & stCall test(st)Text1.Text = Text1.Text & Chr(13) & Chr(10)End IfNext iEnd SubPrivate Function wanshu(n As Integer) As BooleanDim i As Integer, sum As IntegerFor i = 2 To n – 1 …改为i=1If n Mod i = 0 Thensum = sum + iEnd IfNext iIf sum = n Then wanshu = TrueEnd FunctionPrivate Sub test(s As String)Dim i As Integer, sum As Integersum = 0 …位置错,和for 语句位置调换Do While Len(s) > 1For i = 1 To Len(s)sum = sum + V al(Mid(s, i, 1))Next iText1.Text = Text1.Text & "->" & Str(sum)s = Str(sum) … 改为s = CStr(sum) LoopEnd Sub第9章数据文件一、单选题1.B 2.C 3.A 4.B 5.C6.B 7.C 8.B 9.10.A11. 12.A13. 14. 15.A16.B二、编程及上机调试1.Private Sub Form_Load()Open "d:\my\text2.txt" For Output As #1End SubPrivate Sub Text1_keyPress(KeyAscii As Integer)If KeyAscii = 13 ThenIf Trim(Text1) = "0000" ThenClose #1EndEnd IfWrite #1, Text1Text1.Text = ""End IfEnd Sub2.Option ExplicitPrivate Type Studentname As String * 10age As IntegerEnd TypePrivate Sub Command1_Click()Dim Stu As StudentOpen "d:\my\text2.txt" For Random As #1 Len = Len(Stu) = "WangY ing"Stu.age = 20Put #1, , StuClose #1Open "d:\my\text2.txt" For Random As #1 Len = Len(Stu)Get #1, , StuPrint "姓名:", Print "年龄:", Stu.ageClose #1End Sub第10章其它控件二、选择题1.B 2.B 3.B 4.C 5.6.A,C 7.A 8.9.10.11. 12.B 13.三、填空题1.菜单编辑器2.下拉式菜单弹出式3.顶4.PopupMenu5.多文档窗体6.MDIChild7.Private Sub HScroll1_Change()text1 = HScroll1.V alueEnd SubPrivate Sub HScroll1_Scroll()text1 = HScroll1.V alueEnd Sub8.Private Sub Toolbar1_ButtonClick(ByV al Button As MSComctlLib.Button) Select Case Button.IndexCase 1Form1.BackColor = vbRedCase 2Form1.BackColor = vbGreenCase 3Form1.BackColor = vbBlueEnd SelectEnd Sub四、编程及上机调试1.Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, _X As Single, Y As Single)If Button = 1 ThenPicture1.PSet (X, Y)StatusBar1.Panels(1) = "X=" & XStatusBar1.Panels.Item(2) = "Y=" & YEnd IfEnd Sub2.Private Sub Command1_Click()CommonDialog1.FileName = ""CommonDialog1.InitDir = "D:\"CommonDialog1.Filter = "Word Files|*.doc|文本文件|*.Txt" '设置过滤器CommonDialog1.DialogTitle = "打开文件" '设置打开对话框的标题CommonDialog1.Action = 1 '创建"打开"对话框If CommonDialog1.FileName = "" Then '判断文件名是否为空MsgBox "没有选择文件", 37, "检查" '若为空,则显示信息ElseOpen CommonDialog1.FileName For Input As #1 '打开选定的文件Do While Not EOF(1)Line Input #1, a$ '读文件的一行Text1 = Text1 & a$ & vbCrLf '输出所读的内容LoopEnd IfEnd SubPrivate Sub Command2_Click()CommonDialog1.Flags = 3 '列出打印机和屏幕字体CommonDialog1.Action = 4 '打开"字体"对话框Text1.FontName = CommonDialog1.FontName '改变文本框的字体Text1.FontSize = CommonDialog1.FontSizeText1.FontBold = CommonDialog1.FontBoldText1.FontItalic = CommonDialog1.FontItalicText1.FontUnderline = CommonDialog1.FontUnderline End SubPrivate Sub Command3_Click()EndEnd Sub11章略。
vb程序设计教程教材习题答案
同步练习1一、简答题略二、选择题题号 1 2 3 4 5 6 7 8 9 10 答案 C A D B B A C D A B 题号11 12 13 14 15答案 C B D B B同步练习2一、简答题略二、选择题题号 1 2 3 4 5 6 7 8 9 10 答案 A B D C A C A C B C 题号11 12 13 14 15 16 17 18 19 20 答案 D A D A D B D B B B三、填空题1.可视2.Left、Top;Height、Width3.按字母序4.查看代码5.工具|选项|编辑器6.Form窗体;Font7.MultiLine8.只能在设计状态下设置9.工程|工程属性|通用;Form.Show10.TabIndex;0同步练习3一、简答题略二、选择题题号 1 2 3 4 5 6 7 8 9 10 答案 B C A D B A D B B C 题号11 12 13 14 15 16 17 18 19 20 答案 D B C B A D A A B B三、填空题1.整型、长整型、单精度、双精度2.Sin(30*3.14/180)+sqr(x+exp(3))/abs(x-y)-log(3*x)3.①160;②今天是:10-94.false5.-4、3、-3、3、-4、46.CDEF7.(x mod 10)*10+x\108.(35\20)*20=20;( 35 \ 20 )* 20 = 209.x mod 3=0 or x mod 5=010.①27.6 ②8.2 ③8 ④ 1⑤100 ⑥397 ⑦True ⑧False同步练习4一、选择题题号 1 2 3 4 5 6 7 8 9 10 答案 D B C A D A B C A B 题号11 12 13 14 15 16 17 18 19 20 答案 D A B A C C B A C B 题号21 22 23 24 25答案 D A B B C二、填空题1.字符型;整型2.1 2 33.X=74.X<amin5.10246.117.128.6 i "*";9.0 100 i+110.2+I 6 "*";同步练习5一、选择题题号 1 2 3 4 5 6 7 8 9 10 答案 D C A C D D D C D C 题号11 12 13 14 15答案 B A D A D二、填空题1.Name; Index2.Preserve3.variant4.n(2)=2; n(3)=3;5.1 2 3 1 4 16.1 2 3 2 4 67.Max; max=arr1(i)同步练习6一、选择题题号 1 2 3 4 5 6 7 8 9 10答案 C D B A B D B C C C 题号11 12 13 14 15 16 17 18答案 A B C B D C D B二、填空题1.子过程;函数过程2.形式;实际3.存储单元4.MyF(a%, b%( )) As Boolean5.按值传递;按地址传递6.Lbound( );Ubound( )7.局部8.通用;所有过程9.2 5 910.2411.212.30;7013.5同步练习7一、选择题题号 1 2 3 4 5 6 7 8 9 10 答案 B C D D D D D B B D 题号11 12 13 14 15 16 17 18 19 20 答案 C A D A A C A D B D 题号21 22 23 24 25 26 27 28答案 D A A A B C A A二、填空题1.Load;Unload2.Show;Hide3.属性;方法;事件4.工程属性;工程|工程属性5.MDI窗口;子窗口6.Keypress;Combo1.List(i);AddItem7.0;List1.ListIndex;Str(List1.ListCount)8.1000;True;Time( )9.AA10.下拉式组合框;简单组合框;下拉式列表框同步练习9一、选择题题号 1 2 3 4 5 6 7 8 9 10 答案 B A D C B B B B A B二、填空题1.驱动器列表框;目录列表框;文件列表框2.Change3.File1.Path=Dir1.Path4.Name “d:\old.doc ” As “d:\new.doc”5.Dir1.Path= Drive1.Drive;File1.Path=Dir1.Path6.FileCopy “d:\text.doc ” , “e:\text.doc”7.EOF()8.For Input;Not EOF(1)9.For Input;For Output;Not EOF(1);str1;Close #1,#210.Pattern11.空12.字节。
VB 课后习题参考答案
第1章 习题参考答案一、思考题 略二、选择题1. C2. B第2章 习题参考答案一、判断题二、填空题1. 窗体font2. 不能在代码中设置 3. selstart 4. Locked5. TabIndex 、 0 6. vbModal 或 17. Activate 、 Deactivate 8.PictureBox 和 Frame -三、选择题第3章 习题参考答案一、思考题1、double2、 xyC@abc , 15eyd , Is , #END X8[P]3、变量有 (1) (4) (6) (8),常量有 (2)字符串型 (3)逻辑型 (5)字符串型 (7)字符串型 (9)日期型 (10)实型 4、 fe d cb a++5、 (1) 26 (2) 3.75 (3) 36、写出下列Visual Basic 表达式的值:(1) False (2) True (3) True (4) False (5) True(6) True (7) False (8) False7、将下列命题用Visual Basic布尔表达式表示:(1) z>x and z>y (2) abs(a)<=abs(b+2) or a > b+2(3) p mod q=0 (4) x<-5 or x>-2 and x<2 or x>5(5) x<z and y>z or x>z and y<z (6) a<b and a mod 2=08、写出下列函数的值:(1) -4 (2) 换行符(3) –3 (4) -1 (5) hello(6) ello (7) 16 (8) “-459.65” (9) 5二、填空题1.整型、长整型、双精度型、双精度型2.(X mod 10)*10+X\103.sin(1/4*3.14)+sqr(x+2*exp(y))/abs(x-y)4.(a+b)/(c*d-sqr(1-a^2))5.x mod 5=0 or x mod 9=06.False7.-3 、 2 、-2 、 28.CDEF9.x>0 and y>0 or x<0 and y<0 或x*y>010.s>=”A” and s<=”Z” or s>=”a” and s<=”z”三、选择题四、编程题1、Private Sub Form_Click()Dim x%, Ten%, hundred%x = Val(Text1.Text)Ten = (x \ 10) Mod 10hundred = x \ 100Print "百位数是: " & hundredPrint "十位数是: " & TenEnd Sub2Private Sub Form_Click()Dim char As String * 1Form1.CurrentX = Rnd * Form1.ScaleWidthForm1.CurrentY = Rnd * Form1.ScaleHeightchar = Chr(Int(Rnd * 16) + 65)Print charEnd Sub第4章习题参考答案一、判断题二、选择题三、程序阅读写出下列各段程序执行后的输出结果。
VB程序设计练习册参考答案
参考答案第1章Visual Basic 简介一、选择题1、B2、C3、A4、D5、C6、A7、D8、C9、D 10、B11、C 12、B二、填空题1 过程对象事件驱动2 学习版专业版企业版企业版3 Alt+F4 Alt+Q4 设计运行中断5 设置在应用程序运行时,各窗体在屏幕上的显示位置6 内部(标准)7 资源管理器8 编译方式解释方式9 选择“视图/工具箱”命令10 print 或?“大家都来学用Visual Basic”11按字母序按分类序12编辑代码三、思考题略第2章Visual Basic程序设计概述一、选择题1、A2、A3、D4、D5、D6、C7、A 8、C 9、A 10、C 11、B 12、D13、C 14、C 15、B 16、B 17、D 18、B三、编程题1、(1)建立应用程序用户界面。
选择”新建”工程,进入窗体设汁器,在窗体中增加一个标签控件Labe11和两个命令按钮 Commandl 、 Comlnand2。
(2)设置对象属性,见表。
(可自由设置)3编写代码private sub command1_clicklabel1.visible=false1 窗体 控件2 Left Top Width Height3 Ctrl 或shift4 Scrollbars Multiline True Passwordchar5 事件过程6 在属性窗口设置 在代码窗口设置7 对象名 下划线 事件名8 Form_Click9 Form1.Hide10 界面设计 属性设置 代码编写 保存运行11 窗体文件 工程文件12 部件13 窗体文件 模块文件 类模块文件private sub command2_clicklabel1.visible=trueend sub2、Private Sub Command1_ClickIf Text1.Text<>””And Text2.Text<>””Then ′组合条件判断文本框是否为空Form1.Caption=Text1.Text & ″,″& Label2.Caption & ″″& Text2.Text End IfEnd Sub第3章Visual Basic程序设计基础一选择题1.B2.C3.D4.B5.B6.B7.D8.D9.C10.C11.D 12.C 13.D 14.D 15.A 16.D 17.D 18.D 19.C 20.C21.A22.D23.B24.A 25.B 26.A二、填空题1 our name is2 13 True4 字母数字下划线2555 56 07 Logx/log10/0.5+x^2或者Logx/log10/0.5+x*x8 0,1,2,3,49 x>=0 and x<10010 511 false12 6三、编程题1.提示:Ucase、Lcase的使用2.提示:属性设置中,“计算”按钮的default属性设为True.“清除”按钮的Cancel属性设为True.第4章数据输入输出一、选择题1、D2、A3、A4、B5、D6、B7、C 8、C 9、D 10、D二、填空题1. 1+1= 22+2=42. 500.00%3.将当前字体放大两倍4. 20-11-025. 11 1三、编程题1.提示:(1)流程图。
VB程序设计课后习题答案
VB课后习题解答第一、二章:1、简述VB6.0的主要特点答:方便、直观的可视化设计工具;面向对象程序设计方法;事件驱动的编程机制;易学易用的应用程序集成开发环境;结构化程序设计语言;完备的联机帮助功能;强大的多媒体、数据库和网络功能。
2、当正常安装VB6。
0后,误把Windows子目录删除。
当重新安装Windows后,是否需要再次安装VB6。
0?答:要重新安装的。
因为安装VB6。
0时,有些VB程序被系统自动安装在Windows目录下,所以一旦删除Windows子目录,就必须重新安装VB6。
0。
3、Visual Basic 6。
0分为学习版、专业版和企业版,如何知道所安装的是哪个版本?答:在VB6.0的启动界面上,能显示对应的版本.4、叙述建立一个完整应用程序的过程答:首先建立用户界面的控件对象(简称控件);然后对控件属性进行设置;再对控件事件过程及编程;保存应用程序;程序调试和运行。
5、Visual Basic 6。
0有多种类型窗口,若要在设计时看到代码窗口,应怎样操作?答:选择“视图"—>“代码窗口”命令或单击“工程资源管理器”窗口中的“查看代码"按钮。
6、当建立好一个简单的应用程序后,假定该工程仅有一个窗体模块。
试问该工程涉及多少个要保存的文件?若要保存该工程的所有文件,应先保存什么文件?再保存什么文件?若不这样做,系统会出现什么信息?答:涉及两个文件要保存.先保存窗体文件(.frm),再保存工程文件(.vbp)。
若先保存工程文件,系统也会先弹出“文件另存为”对话框,要求先保存窗体文件。
7、保存文件时,若不改变目录名,则系统默认的目录是什么?答:系统默认的目录是VB988、安装Visual Basic 6。
0后,帮助系统是否也已安装?答:没有。
VB6.0的帮助系统在两张光盘上,即MSDN Library,其中还包含了VC、VFP等其他语言的帮助系统。
9、如何使用Visual Basic 6.0的帮助系统?答:最方便的方法是选定要帮助的内容,然后按F1功能键,这时系统打开MSDN Library查阅器,直接显示与选定内容有关的帮助信息。
vb程序设计课后习题答案
vb程序设计课后习题答案VB程序设计课后习题答案在学习VB程序设计课程的过程中,课后习题是巩固知识、提高能力的重要环节。
通过认真完成课后习题,我们不仅可以加深对知识点的理解,还可以提高编程能力和解决问题的能力。
下面我将为大家分享一些VB程序设计课后习题的答案,希望能够对大家的学习有所帮助。
1. 编写一个VB程序,实现输入两个数,计算它们的和并输出。
```Private Sub btnCalculate_Click()Dim num1 As IntegerDim num2 As IntegerDim sum As Integernum1 = Val(txtNum1.Text)num2 = Val(txtNum2.Text)sum = num1 + num2lblResult.Caption = "结果为:" & sumEnd Sub```2. 编写一个VB程序,实现输入一个数,判断它是奇数还是偶数并输出。
Private Sub btnJudge_Click()Dim num As Integernum = Val(txtNum.Text)If num Mod 2 = 0 ThenlblResult.Caption = "这是一个偶数"ElselblResult.Caption = "这是一个奇数"End IfEnd Sub```3. 编写一个VB程序,实现输入一个数,计算它的阶乘并输出。
```Private Sub btnFactorial_Click()Dim num As IntegerDim result As IntegerDim i As Integernum = Val(txtNum.Text)result = 1For i = 1 To numresult = result * iNextlblResult.Caption = "结果为:" & resultEnd Sub```通过以上几个例子,我们可以看到,VB程序设计课后习题涵盖了基本的输入输出、运算符的使用、条件判断和循环等知识点。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
同步练习1二、选择题01——05 CADAB06——10 ACDAB11——15 CBDBB同步练习2二、选择题01——05 ABDCA06——10 CACBC11——15 DADAD16——20 BDBBB三、填空题1.可视2.LEFT、TOP、WIDTH、HEIGHT3.按字母顺序4.查看代码5.工具、编辑器6.FORM窗体、FONT7.MULTILINE8.在运行时设计是无效的9.工程、工程属性、通用、FORM1.SHOW 10.TABINDEX、0同步练习3二、选择题01——05 BCADB06——10 ADBBC11——15 DBCBA16——20 BAABB三、填空题1.整型、长整型、单精度型、双精度型2.SIN(30*3.14/180)+SQR(X+EXP(3))/ABS(X-Y)-LOG(3*X) 3.164、今天是:3-194.FALSE5.-4、3、-3、3、-4、46.CDEF7.(X MOD 10)*10+X\108.(35\20)*20=20( 35 \ 20 )* 20 = 209.X MOD 3=0 OR X MOD 5=010.27.6、8.2、8、1、100、397、TRUE、FALSE同步练习4一、选择题01——05 DBCAD06——10 CBBAB11——15 D25BAC16——20 CBACB21——25 DAABC二、填空题1.正确性、有穷性、可行性、有0个或多个输入、有1个或多个输出2.1 2 33.X>=74.X<AMIN5.10246.117.128.6、I、”*”;9.0、100、I+110.2*I、6、”*”;三、编程题1.编程求n!,n从键盘输入。
Private Sub Form_Click()Dim n%, s%, i%n = Val(InputBox("请输入n的值:"))s = 1For i = 1 To ns = s * iNext iPrint n; "!="; sEnd Sub2.编程求100以内的全部质数。
Private Sub Form_Click()Dim i%, k%, n%, y$For n = 1 To 100k = Int(Sqr(n))For i = 2 To kIf n Mod i = 0 Then Exit ForNext iIf i > k Theny = y & Str(n)End IfNext nMsgBox y, , “显示质数"End Sub3.编写程序,计算1+2+…+100的值。
Private Sub Form_Click()Dim i%, s%s = 0For i = 1 To 100Next iPrint "1+2+3+…+100="; sEnd Sub4.百元买百鸡。
假定小鸡每只5角,公鸡每只2元,母鸡每只3元,编程求解购鸡方案。
(采用穷举法)假设母鸡、公鸡、小鸡各为x、y、z,列出方程为:x+y+z=1003x+2y+0.5z = 100Private Sub Form_Click()Dim x%, y%, z%Print "母鸡", "公鸡", "小鸡"For x = 0 To 33For y = 0 To 50z = 100 - x - yIf 3 * x + 2 * y + 0.5 * z = 100 ThenPrint x, y, zEnd IfNext yNext xEnd Sub5.给定三角形的3条边的边长,计算三角形的面积。
编写程序,首选判断的3条边能否构成三角形,如可以构成,则计算并输出该三角形的面积,否则要求重新输入。
当输入-1时结束程序。
Private Sub Form_Click()Dim a%, b%, c%, s!, p!Do Until a = -1 Or b = -1 Or c = -1a = Val(InputBox("a="))b = Val(InputBox("b="))c = Val(InputBox("c="))If a + b > c And a + c > b And b + c > a Thenp = (a + b + c) / 2s = Sqr(p * (p - a) * (p - b) * (p - c))Print "s="; sEnd IfLoopEnd Sub6.编程打印如下图所示的数字金字塔。
Private Sub Form_Click()Dim i%, j%For i = 1 To 8Print Tab(9 - i);For j = 1 To 2 * i - 1Print Trim(Str(i));PrintNext iEnd Sub7.勾股定理中3个数的关系是:a*a+b*b=c*c。
编写程序,输出30以内满足上述关系的整数组合,例如3、4、5就是一个整数组合。
Private Sub Form_Click()Dim i%, j%, k%For i = 1 To 30For j = 1 To 30For k = 1 To 30If i ^ 2 + j ^ 2 = k ^ 2 ThenPrint i, j, kEnd IfNext kNext jNext iEnd Sub8.如果一个三位数3个数字的立方和等于该数本身,称为水仙花数。
例如153就是一个水仙花数:13+53+33=153。
编写程序,显示所有三位的水仙花数。
Private Sub Form_Click()Dim x%, a%, b%, c%For x = 100 To 999a = x \ 100b = (x Mod 100) \ 10c = x Mod 10If a ^ 3 + b ^ 3 + c ^ 3 = x ThenPrint xEnd IfNext xEnd Sub9.税务部门征收所得税,规定如下:(1)收入200元以内,免征;(2)收入在200~400元内,超过200元的部分纳税3%;(3)收入超过400元的部分,纳税4%;(4)当收入达5000元或超过时,将4%改为5%。
编程实现上述操作。
Private Sub Form_Click()Dim x%, y!x = Val(InputBox("请输入收入额:"))Select Case xCase Is < 200y = 0Case 200 To 400y = (x - 200) * 0.03Case 400 To 4999y = (x - 400) * 0.04Case Is >= 5000y = (x - 400) * 0.05End SelectPrint "y="; yEnd Sub10.编写一程序根据上网时间计算上网费用,计算方法如下:50元(<10小时)网费= 每小时6元(10~60小时)每小时4元(>=60小时)同时为了鼓励多上网,每月收费最多不超过200元。
Private Sub Form_Click()Dim t!, s!t = Val(InputBox("请输入上网小时数"))Select Case tCase Is < 10s = 50Case 10 To 59s = 6 * tIf s > 200 Then s = 200Case Is >= 60s = 4 * tIf s > 200 Then s = 200End SelectPrint "上网费用为"; s; "元。
"End Sub11.编写一个程序,当输入月份时,输出季节的名称。
例如,当输入月份为12、1和2时,输出“冬季”;当输入月份为3、4、5时,输出“春季”;当输入月份为6、7、8时,输出“夏季”;当输入月份为9、10、11时,输出“秋季”;当输入其他数字时,输出“输入错误,请重新输入!”。
Private Sub Form_Click()Dim m%m = Val(InputBox("请输入月份:"))Select Case mCase 12, 1, 2Print "冬季"Case 3, 4, 5Print "春季"Case 6, 7, 8Print "夏季"Case 9, 10, 11Print "秋季"Case ElsePrint "输入错误,请重新输入!"End SelectEnd Sub12.分别利用If语句、Select Case语句,设计计算下列分段函数的程序。
2x-1 (x<0)f(x)= 4x (x=0)7x-5 (x>0)Private Sub Form_Click()Dim x!, f!x = Val(InputBox("请输入x的值:"))Select Case xCase Is < 0f = 2 * x - 1Case 0f = 4 * xCase Is > 0f = 7 * x - 5End SelectPrint fEnd Sub同步练习5一、选择题01——05 DCACD06——10 DBCDC11——15 BADAD二、填空题1.NAME、INDEX2.PRESERVE3.V ARIANT4.N(2)=2N(3)=35.1 2 3 1 4 16.1 2 3 2 4 67.MAX、MAX=ARR1(I)三、编程题1.从键盘上输入10整数,并放入一个一维数组中,然后将其前5个元素与后5个元素对换,即第1个元素与第10个元素互换,第2个元素与第9个元素互换,……,第5个元素与第6个元素互换。
输出数组为原来各元素的值和对换后各元素的值。
Private Sub Form_Click()Dim a(1 To 10)For i = 1 To 10a(i) = Val(InputBox("请输入第" & i & "个数"))Next iPrint "原来各元素的值:"For i = 1 To 10Print a(i);If i Mod 5 = 0 Then PrintNext iFor i = 1 To 5temp = a(i)a(i) = a(10 - i + 1)a(10 - i + 1) = tempNext iPrint "对换后各元素的值"For i = 1 To 10Print a(i);If i Mod 5 = 0 Then PrintNext iEnd Sub2.设有如下两组数据。