vb程序设计实验教程习题答案
VB程序设计教程(第3版)课后实验答案

'Caption = "窗体大小不变"
'Form1.Width = 260 * 16
' 260 是 Tongji-2.bmp 图的宽度,象素单位
'Form1.Height = 260 * 16 + 200 ' 260 是图的高度,象素单位,200 是窗体的标题栏高度
End Sub
A.5
Sub Command1_Click() Text1.FontName = "隶书" Text1.FontSize = 25
对全部高中资料试卷电气设备,在安装过程中以及安装结束后进行高中资料试卷调整试验;通电检查所有设备高中资料电试力卷保相护互装作置用调与试相技互术关,系电,力根保通据护过生高管产中线工资敷艺料设高试技中卷术资配0料不置试仅技卷可术要以是求解指,决机对吊组电顶在气层进设配行备置继进不电行规保空范护载高高与中中带资资负料料荷试试下卷卷高问总中题体资,配料而置试且时卷可,调保需控障要试各在验类最;管大对路限设习度备题内进到来行位确调。保整在机使管组其路高在敷中正设资常过料工程试况中卷下,安与要全过加,度强并工看且作护尽下关可都于能可管地以路缩正高小常中故工资障作料高;试中对卷资于连料继接试电管卷保口破护处坏进理范行高围整中,核资或对料者定试对值卷某,弯些审扁异核度常与固高校定中对盒资图位料纸置试,.卷保编工护写况层复进防杂行腐设自跨备动接与处地装理线置,弯高尤曲中其半资要径料避标试免高卷错等调误,试高要方中求案资技,料术编试交写5、卷底重电保。要气护管设设装线备备置敷4高、调动设中电试作技资气高,术料课中并中3试、件资且包卷管中料拒含试路调试绝线验敷试卷动槽方设技作、案技术,管以术来架及避等系免多统不项启必方动要式方高,案中为;资解对料决整试高套卷中启突语动然文过停电程机气中。课高因件中此中资,管料电壁试力薄卷高、电中接气资口设料不备试严进卷等行保问调护题试装,工置合作调理并试利且技用进术管行,线过要敷关求设运电技行力术高保。中护线资装缆料置敷试做设卷到原技准则术确:指灵在导活分。。线对对盒于于处调差,试动当过保不程护同中装电高置压中高回资中路料资交试料叉卷试时技卷,术调应问试采题技用,术金作是属为指隔调发板试电进人机行员一隔,变开需压处要器理在组;事在同前发一掌生线握内槽图部内纸故,资障强料时电、,回设需路备要须制进同造行时厂外切家部断出电习具源题高高电中中源资资,料料线试试缆卷卷敷试切设验除完报从毕告而,与采要相用进关高行技中检术资查资料和料试检,卷测并主处且要理了保。解护现装场置设。备高中资料试卷布置情况与有关高中资料试卷电气系统接线等情况,然后根据规范与规程规定,制定设备调试高中资料试卷方案。
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程序”。
VB程序设计习题及答案第2章VisualBasic语言基础知识

第2章 Visual Basic语言基础知识2.1 Visual Basic定义了几种数据类型,变量有哪几种数据类型,常量有哪几种数据类型。
【答】Visual Basic基本数据类型:1. 字符串型(String):字符串分为变长字符串和定长字符串两种。
2. 数值型:数值型数据分为整型数和浮点数两类。
3. 货币型(Currency)4. 变体型(Variant)5. 字节型(Byte)6. 布尔型(Boolean)7. 日期型(Date)8. 对象型(Object)Visual Basic中包含两种常量,即文字常量和符号常量。
变量的基本数据类型:Byte(字节型),Boolean(布尔型),Integer(整型),Long (长整型),Single(单精度型),Double(双精度型),Currency(货币型),Date(日期型),Object(对象型),String(变长字符串),String(定长字符串),Variant(变体型、数字),Variant(变体型、字符)2.2 符号常量和变量有什么不同点?【答】符号常量一经定义,就不能在程序中的其他位置改变其值。
变量的值在程序中可以改变。
2.3 指出下列正确的变量名:g(1-k) 6adhs *sss kL2.1 Printx+1 ahi π .ex3 j5h【答案】正确的变量名:ahi,j5h2.4 指出下列正确的数字形式-1.25 ±0.123 89E D2585 10^(2.7) 3^5【答案】2.5 下列表达式若有错误,请改正(1) ts+cos(300) (2) (x+y)^(25÷s)(3) [(X1+X2)*(X1-3)-6]*7 (4) (X÷-2)+sin(1.2+π)【答案】(1) ts+cos(30*3.141593/180)(2) (x+y)^(25/s)(3) ((X1+X2)*(X1-3)-6)*7(4) (X/(-2))+sin(1.2+3.141593)2.6 写出下列数学式的Visual Basic表达式(1) sin(a)[cos(b)+1.5](2) (x1+4)5(e2-a)(3) 36[(x1+π)(x1÷3.3)-b](4) x-2π)【答案】Visual Basic表达式:(1) sin(a)*(cos(b)+1.5)(2) (x1+4)^5*(Exp(2)-a)(3) 36*((X1+3.141593)*(x1/3.3)-b)(4) x^(-2)+5.8*sin(3.5*3.141593)第3章顺序结构程序设计3.1 下列语句是否有错?若有,请改正。
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.CDEF10.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 "第二个根是:", x2Else2Print "该方程有两个虚根:"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))If (a + b > c And Abs(a - b) < c) Or (a + c > b And Abs(a - c) < b) Or ((b + c) > a And Abs(b - c) < a) Thenp = (a + b + c) / 2s = Sqr(p * (p - a) * (p - b) * (p - c))Print "三角形的面积是:" & sElsePrint "很抱歉,不能构成合法的△三角形!"End IfEnd Sub6.Option ExplicitPrivate Sub Command1_Click()Dim ji%, tu%For ji = 1 To 27For tu = 1 To 27If ji * 2 + tu * 4 = 78 And ji + tu = 27 ThenPrint "鸡的个数是:" & jiPrint "兔的个数是:" & tuEnd IfNextNextEnd Sub7.Option ExplicitPrivate Sub Command1_Click()Dim i%Dim s#, t#s = 10t = 10For i = 1 To 7t = t * 0.4s = s + t * 2NextEnd Sub8.Option ExplicitPrivate Sub Command1_Click()Dim i%, fs%, max%, min%, s%Dim ave#fs = Val(InputBox("please input score:", "info", 90))s = fsmax = fsmin = fsFor i = 2 To 7fs = Val(InputBox("please input score:", "info", 90))If max < fs Thenmax = fsEnd IfIf min > fs Thenmin = fsEnd Ifs = s + fsNextave = (s - max - min) / 5Print "该运动员的平均成绩是:" & aveEnd Sub9. ‘同学们,这道题方法很多,主要考察你对选择结构的理解,我给出其中一种方法。
VB程序设计 习题及答案第4章 选择结构程序设计

第4章选择结构程序设计4.1 写出数学式|x|<2.5×10-2对应的Visual Basic表达式。
【答案】x<2.5e-2 and x>-2.5e-24.2 逻辑运算符And、Or和Not的优先级最高的是哪一个。
【答案】Not4.3 已知 W=10 X=9 Y=8 Z=7 ,求下列表达式的结果。
(1) W>X And Y<=Z OR X>Y(2) X>Z Or W=Y AND Y<X(3) Not (W>Y And X=Z)(4) Not (Y<>X Or W*3>Z)【答案】(1) True(2) True(3) True(4) False4.4 写出下列十进制整数逻辑运算的结果:(1) X = 23 And 14(2) X = 23 Or 14(3) X = -1 And 19(4) X = -1 Or 10(5) X = Not -1【答案】(1) 6(2) 31(3) 19(4) -1(5) 04.5 已知变量X和Y的值分别为5、6,编写程序,交换变量X和Y的值。
【参考答案】程序代码设计Private Sub Form_Click()x = 5: y = 6t = x: x = y: y = tForm1.Print "x="; x, "y="; yEnd SubPrivate Sub Form_Load()Form1.AutoRedraw = TrueForm1.Print "x = 5", "y = 6"Form1.Print "单击窗体交换x,y的值"图4-1 程序运行结果End Sub程序运行结果如图4-1所示:4.6 从键盘输入一个学生的三科成绩,计算总分,并找出最高分。
【参考答案】(1)用户界面设计(2)控件属性设置(略)(3)程序代码设计Private Sub Command1_Click()g1 = Val(Text1.Text)g2 = Val(Text2.Text)g3 = Val(Text3.Text)Var = (g1 + g2 + g3) / 3g = g1If g < g2 Then g = g2If g < g3 Then g = g3Text4.Text = VarText5.Text = gEnd Sub图4-2 程序运行结果程序运行结果如图4-2所示。
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程序设计教程试验指导与习题解答上机答案
自测1程序代码Private Sub Command1_Click() Labell .FontSize = Labell .FontSize + 3End SubPrivate Sub Command2_Click() Label1 .FontBold = TrueEnd SubPrivate Sub Command3_Click() Label1 .FontUnderline = TrueEnd SubPrivate Sub Command4_Click() Label1 .FontSize = 10Label1 .FontBold = False Label1 .FontUnderline = FalseEnd Sub初始窗口:单机放大之后窗口: 单机下划线之后窗口:单击加粗之后窗口: 单击还原之后窗口:自测2程序代码Private Sub Command1_Click() Labell = "visual basic"Textl ="程序设计题"End SubPrivate Sub Command2_Click() Text1 = "visual basic"Label1 ="程序设计题"End Sub初始窗口:交换显示 单击显示之后窗口:FormlFormlTestivi SU ^L L basic 程序设计题 显示单击交换之后的窗口:自测题3Private Sub Comma nd1_Click()Labell.Fo ntSize = Labell.Fo ntSize * (0.5)End SubPrivate Sub Comma nd2_Click() Label1.Top = Label1.Top + 30 Label1.Width = Label1.Width + 20Label1.Alig nment = 1 End Sub初始窗口:单击缩小两倍之后的窗口:单击向右下角移动之后的窗口:缩小两倍标签的属性设畳向右下角移动自测题4程序代码Private Sub Command1_Click() Forml.Caption = "VB 学习"Print "简单的VB程序设计"End SubPrivate Sub Command2_Click()乌FormlClsEnd SubPrivate Sub Command3_Click() EndEnd SubPrivate Sub Command3_Click() EndEnd Sub初始化窗口:单击显示之后的窗口:单击清除之后的窗口:单击退出之后的窗口:ih 191 - vHuiJ tMH :Hi*E! M1£| *凹 T»c.i ffisa:1 «2'耳11也 n^Li ftft? Ulil> 井回 ■一阖 耳储凹 £J - U- ' # ■ X ■甩腐 I G c I 卜 II ・对 EF 曲曽 41M41 0 Ifl] - Fermi (fern^ n 2 口Q -0Cl Pciml CI IS :-陶E 4 gdH撑 4 JT.KjS .兰I□ 30 B^1«L QftLj0 F GE L £T H II■It • Form 】«婀田判踽砸1>:■»?:>i*fF^iruch I - ]| 花Unftabav F faSiU F K K-L-T□ 卿值疏瞬 fc<r-Ur3«.ylB t - S LCI I I L H r-H h- pi^Capi.Tii-iTrwC-E^riLIra Ev«4.J. R •皿[T-U1IJI.I EulL.J FilK-L-r 皿口讣“ F L U• ■■FAfruBTr-irvCiLo- Trw 13 -亡■卄 Jui tf -矗Li 4T IM w'-mlrw自测题5 程序代码Private Sub Command1_Click()Textl .Text =""Text2 .Text =""End SubPrivate Sub Command2_Click()Text3 .Text = Val(Text1 .Text) + Val(Text2 .Text) End SubPrivate Sub Command3_Click()EndEnd Sub初始化窗口:单击运算之后窗口:单击清除之后的窗口:单击退出之后的窗口ItfHal -魯工cgn冋咅13MIE-當eH._*w 酉軽-A E Jlq -卑巨m ^BAD区,F «E -iK y >3L ■•■二・®C F 爭味*6£3|1ss-privaCDSubcommancHIC-ick()DimaSa HTexf ︱k.TexfLabe-︱k.capfion HLeft?2)EndSubprivaCDSubCommand2lc-ick()a HTexf ︱k.TexfLabe-2.capfion HRighf?2)EndSubprivaCDSub Command3lc-ick()H a- H a --F s IX-Textl.Text = Labell.Caption & Label2.Caption End Sub初始窗口界面输入字符串截取前两个字符Forml I =回]M7Kr wciainiwo漓鯉两平斗截哑診个付字符串连接截取后两个字符字符串连接Forml I = | 回]WT wornniwo截勢载疇个ps;自测练习2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f%, g%, h%, i%, j%, k%, l% a = 7349e = a Mod 10 '个位d = (a \ 10) Mod 10 ' 十位c = (a \ 100) Mod 10 ' 百位b = a \ 1000 ' 千位i = (e + 7) Mod 10 ' 个位h = (d + 7) Mod 10 ' 十位g = (c + 7) Mod 10 ' 百位f = (b + 7) Mod 10 ' 千位j = ii = f ' 交换后的个位f = j ' 交换后的千位k = hh = g '交换后的十位g = k '交换后的百位l = f * 1000 + g * 100 + h * 10 + i Text1.Visible = False加密后的结果是Print" 加密前的4位整数是7439"; (Chr(10));" ";lEnd Sub初始界面单击窗体运行后的界面自测练习1Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(lnputBox(" 输入第一个数","输入一个数",8))b = Val(InputBox(" 输入第一个数","输入一个数",7))c = a + bd = a - be = a * bf = a / bf = Fix(f * 100 + 0.5) / 100MsgBox "x+y=" & c & Chr(10) & "x-y=" & d & Chr(10) & "x*y=" & e & Chr(10) & "x/y=" & f,," 输出的结果"End Sub瑾出的结果塔x+y=15x-y=l x*y=56 如"4自测练习2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(lnputBox(" 输入第一个数的值"))b = Val(InputBox(" 输入第二个数的值"))c = Val(InputBox(" 输入第三个数的值"))d =Val(InputBox(" 输入第四个数的值")) e = a + b + c + dPrin t "和=";e Print" 平均值=";f End Sub0 Forml 口回I—SWT 和二10 平均值二2 5自测练习3Private Sub Form_Click()Dim h%, f%, x%, y%h = Val(lnputBox(" 输入总头数")) f = Val(InputBox(" 输入总脚数")) x = (4 * h - f) / 2y = (f - 2 * h) / 2Print "笼中鸡的头数为";x;" 只" Print"笼中兔的头数为";y;" 只"End Sub自测练习1:Private Sub Form_Click() Dim a%, b%, c%a = Val(lnputBox(" 请输入第一条边","边长"))b = Val(lnputBox(" 请输入第二条边","边长"))c = Val(lnputBox(" 请输入第三条边","边长")) If a + b > c And a + c > b And b + c > a The nIf a * a + b * b = c * c Or a * a + c * c = b * b Or b * b c * c = a * a The n Pri nt " 直角"ElseIf a =b And b = c The nPri nt " 等边三角形"ElseIf a =b Or a = c Or b = c The nPri nt " 等腰三角形"ElsePri nt " 般三角形"End IfElsePri nt " 不是三角形"End IfEnd Sub不是三角形运行结果: 初始窗口:输入三条边:运行结果:直角三角形运行结果:等边三角形运行结果如下: 等腰三角形:般三角形自测练习2:Private Sub Form_Click()Dim a%, b!a = Val(l nputBox(" 请输入"))If a Mod 2 = 0 And a Mod 3 = 0 And a Mod 5 = 0 Then b = Sqr(a) Pri nt a, bElseEndEnd IfEnd Sub初始化窗口:输入一个数:运行结果:自测练习3Private Sub Comma nd1_Click()Dim a%, b%a = Val(Text1.Text)Select Case a > 0Case a < 20MsgBox "行李费为0.2元/kg",," 行李费" Case a >= 20 And a < 50MsgBox "行李费为0.3元/kg",," 行李费" Case a >= 50 And a < 100MsgBox "行李费为0.4元/kg",," 行李费”Case Else元",,"行李费"End SelectEnd Sub 初始窗口:输入10: 输入25: 输入55:输入120:自测练习1Option Base 1Private Sub Form_Click() Dim i%, a(1 To 20) As In tegera(1) = 1: a(2) = 1Pri nt a(1);Pri nt a(2);Fori = 3 To 10a(i) = a(i - 1) + a(i - 2) Pri nt a(i);Next iPri ntFori = 11 To 16a(i) = a(i - 1) + a(i - 2) Pri nt a(i);Next iPri ntFor i = 17 To 20a(i) = a(i - 1) + a(i - 2) Pri nt a(i);Next i初始界面:运行结果界面:上Forml I = | 回IWT1 123 5 8 13 21 34 5539 144 233 377 610 9E7159TT 2504 4101 6765自测练习2Option Base 1Private Sub Form_Load()Forml.Width = 10000Form1.Height = 5000End SubPrivate Sub Comma nd1_Click()Dim i%, j%, t%, a(1 To 4, 1 To 4) As In teger For i = 1 To 4 Forj = 1 To 4a(i, j) = In t(R nd * 10) + 1Picturel.Pri nt a(i, j);Next jPicture1.Pri ntNext iPicture3.Print" 对角线的元素如下”For i = 1 To 4Picture3.Pri nt a(i, i);Next iPicture3.Pri ntFor i = 1 To 4Picture3.Pri nt a(i, 5 - i);Next iFor i = 1 To 4t = a(1, i) a(1, i) = a(4, i)a(4, i) = tNext iFor i = 1 To 4t = a(i, 2)a(i, 2) = a(i, 3)a(i, 3) = tNext iFor i = 1 To 4Forj = 1 To 4 Picture2.Pri nt a(i, j); Next jPicture2.Pri nt Next iEnd Sub运行初始界面:运行结果界面:自测练习1Sub itostr(a As In teger) Dim b%, c$a = Val(Textl.Text)While a >= 1c = Chr(a Mod 10 + 48) & ca = a \ 10WendText2.Text = cEnd SubPrivate Sub Comma nd1_Click() Dim a As In tegera = Val(Text1.Text)Call itostr(a)End Sub运行初始界面:运行结果界面:0 Forml 口虽验证其他数字:自测练习2:Public Fun cti on area( n) As Double Dim c#, d#, e#, s#n 二Val(Text2.Text)c = (1 - 0) / nWhile e <= 1d = I * c:e = (I + 1) * cs = s + (Si n(d) + Si n(e)) * c / 2I = I + 1Wendarea = sEnd Fun cti onPrivate Sub Comma nd1_Click() Dim s As DoubleCall area( n)Text1.Text = area (n)End Sub运行初始界面:运行结果:自测练习3Private Sub Form_click()n 二Val(lnputBox(" 请输入n 的值"))x = Val(lnputBox(" 请输入x 的值"))Pri nt "e 的值二";es( n, x)End SubPrivate Fun cti on es(n, x)Dim a As Double, b As Double, c As Double, i As In teger a = 1: b = 1: c = 1For i = 1 To na = x * a:b = b * i:c = c + a / bNext ies = cEnd Fun cti on运行初始界面:输入数据:。
VB实验教材的实验、习题答案
第一章VB开发环境与VB概述习题答案习题一、选择题第二章常用控件与界面设计习题答案习题一、选择题第三章实验与习题实验实验3_1…算术运算Private Sub Command1_Click()Const a As Single = 3, b As Single = 2, c As Single = -1, d As Single = 6Dim x As Single, y As Single, z As Single, m As Singlex = 2: y = 1: z = 1: m = 1List1.ClearList1.AddItem a / (b + c / b)List1.AddItem (x + Sqr(x ^ 2 + 1)) ^ (1 / 3)List1.AddItem ((2 * y) / (a * x + b * y) * (a * x - b * y))List1.AddItem 1 + 1 / (1 + 1 / m)List1.AddItem 1 / 2 * (d / 3) ^ (2 * x)List1.AddItem Log(y + Cos(x) ^ 2)List1.AddItem Abs((Exp(x) + Sin(x) ^ 3) / (x + y))List1.AddItem Log((Exp(x * y) + Abs(1 / Tan(z) + Cos(x) ^ 3)) / (x + y - z))List1.AddItem Sin(45 * 3.1415 / 180) + (Exp(10) + Log(10)) / Sqr(x + y + 1) List1.AddItem Log(a) / Log(b)End Sub…关系运算Private Sub Command2_Click()List1.ClearList1.AddItem Mid("Visual Basic", 1, 12) = Right("Language Visual Basic", 12) List1.AddItem "ABCRG" >= "abcde"List1.AddItem Int(134.69) >= CInt(134.9)List1.AddItem 78.9 / 32.77 <= 97.5 / 43.87 And -45.4 > -4.98List1.AddItem Str(32.345) = CStr(32.345)End Sub…逻辑运算Private Sub Command3_Click()Dim x As Integer, y As IntegerDim C1 As Integer, C2 As Integer, C3 As IntegerC1 = 70: C2 = 80: C3 = 90x = 9: y = -2List1.ClearList1.AddItem x + y < 10 And x - y > 0List1.AddItem (x% >= 0 And y% >= 0) Or (x% < 0 And y% < 0)List1.AddItem x = 0 Xor y = 0List1.AddItem C1 + C2 + C3 >= 255 Or C1 > 90 And C2 > 90 And C3 > 80End Sub实验3_2略实验3_3略实验3_4…零售结算Private Sub Command1_Click()Dim dj As Single, sl As Single, je As Single, n As IntegerLabel1.Caption = "金额:"dj = InputBox("请输入商品的单价:", "单价框")sl = InputBox("请输入商品的数量:", "数量框", 1)je = dj * sln = MsgBox("共计金额=" & je, vbOKCancel + vbInformation, "结果") If n = vbOK Then Label1.Caption = "金额:" & Str(je) & "元"End Sub…产生随机数Private Sub Command2_Click()Dim m As Integer, n As IntegerDim x1 As Integer, x2 As Integer, x3 As Integerm = V al(Text1.Text): n = Text2.TextRandomizex1 = Int(Rnd * (n - m + 1) + m)x2 = Int(Rnd * (n - m + 1) + m)x3 = Int(Rnd * (n - m + 1) + m)Label4.Caption = "结果为:" & Str(x1) & Str(x2) & Str(x3)End Sub…求逆序数Private Sub Command3_Click()Dim a As Integer, h As Integer, t As Integer, n As IntegerRandomizea = Int(Rnd * (999 - 100 + 1) + 100)h = Mid(CStr(a), 1, 1)t = Mid(CStr(a), 2, 1)n = Right(CStr(a), 1)Label5.Caption = a & "-->" & Format(n * 100 + t * 10 + h, "000")End Sub实验3_5略习题选择题填空题1、2 -32768~327672、整型长整型单精度双精度3、0 False “”4、Chr(Int(Rnd*(Asc(“L”)-Asc(“C”))+Asc(“C”)))x>0 And y>0 Or x<0 And y<0c>=”a” And c<=”z” Or c>=”A” And c<=”Z”x>=10 And x<20x<z Xor y<z5、False2TrueFalseTrueTrueTrueTrue6、18820010068.568765547、a=1 b=1a=2 b=1a=3 b=1a=4 b=18、Y Mod 4=0 And Y Mod 100<>0 Or Y Mod 400 =09、He Said, “Good morning”.10、EDEF11、(A>0 And A<>Int(A)) And (B<0 And B<>Int(B))12、a+b+c+d(a+b+c+d)/4sumaver13、(f-2*h)/2(4*h-f)/2简答题1、略2、Private Sub Form_Click()Const g = 9.8Dim V0 As Single, t As SingleDim S As SingleV0 = InputBox("请输入V0的值:")t = InputBox("请输入时间t的值:")S = (1 / 2) * g * t ^ 2 + V0 * tMsgBox ("位移量为:" & S)End Sub3、Private Sub Command1_Click()Dim l As Single, w As Single, h As SingleDim s As Singlel = Text1.Textw = Text2.Texth = Text3.Texts = (l * w + l * h + w * h) * 2Label1.Caption = sEnd Sub第四章选择分支与循环实验答案实验4-1方法一:x<=5 ; y方法二:Is<=2 ;Case Else实验4-2Shape1.BackColor=vbRed;Inter=15;Inter=Inter-1;Inter;实验4-3b<cb=aa=k实验4-4方法二:s*n ; t/s<10^-5实验4-5方法一:m>=10^-4 ; (-1)^(n+1)*m实验4-6x2=x3 ; <10^-6实验4-7实验4-8i+2*j+5*k=10 ; n实验4-9题目一:a) 5b)i=16 p=12 n=5c)i=9 p=8 n=1题目二:120 10实验4-10N=1 ;S=N& "*3 " & "+1 "实验4-11Len(st); Ch=Lcase(ch) ; Case Else ; Mid(Char,I,1)&St实验4-12i\100 ; (i Mod 100)\10习题一、选择题二、填空题1.Is=0 ; 1 To 10 ; Is >102. 93. 3 ; 4 154. this is a book ;This Is A Book5. 3 ; 3 ; 3 56. 32 07. 48. 15 19. 1 ; 401 ;10410. 1 2 3 ;1 3; 111. (3)12. 2 0 2413. 10 1414. BAABC CBAABC15. X Mod P=0 ; X=X+1 ;Find=False16. abs(t)<10^(-7) ; s+t17. Mid(n,1,1)=Mid(n,2,1) And Mid(n,3,1)=Mid(n,4,1)S=S+118. Mid(n,i,1)>Mid(n,i+1,1)19. "输入n";N/I=0 ;Print I第五章数组实验5_1Int(90 * Rnd) + 10a(i) = a(21 - i)a(21 - i) = t5_2k = x Mod 10i = i + 15_3s5_4max < a(i, j)row = Icol = j5_51ReDim Preserve prime(m)prime(j)5_6d Mod 25_7Exit Fora(j + 1) = a(j)5_8N – IA(j) = A(j + 1)5_9A(i, 1)JMin = MaxNot Flag5_10ch >= "0" And ch <= "9"P = P & chReDim Preserve C(k)5_11Private Sub Form_Click()Dim x As Integer, i As Integer, k As Integer, j As Integer Dim a() As Integerx = InputBox("输入正整数x=")i = 2Print x; "的质因子为:";Do While x >= iIf x Mod i = 0 Thenk = k + 1ReDim Preserve a(k)a(k) = ix = x \ iElsei = i + 1End IfLoopFor j = 1 To UBound(a)Print a(j);Next jEnd Sub习题一选择题二填空题1.V ariant2.ReDim A(N)A(1)If M < A(I) Then M = A(I)3.Int(26 * Rnd) + 65Chr(t)i + 1 To 10A(i) > A(j)4.InStr(s, ",")Right(s, Len(s) - n)s5. 4 5 66 5 43 2 16.T – 1I + 17.k = 6 - i – jmax = m8.j = aj = j - 39.i + 1i = i + 110. 237三编程题1.Option ExplicitOption Base 1Private Sub Command1_Click()Dim a(10) As IntegerDim i As Integer, max As IntegerFor i = 1 To 10a(i) = Int(90 * Rnd) + 10Print a(i);Next iPrinti = 1max = 0Do While i <= 10If a(i) Mod 3 = 0 ThenIf a(i) > max Thenmax = a(i)End IfEnd Ifi = i + 1LoopIf max = 0 ThenPrint "无要找的数"ElsePrint max & "是最大的能被3整除的数"End IfEnd Sub2.Option ExplicitOption Base 1Private Sub Command1_Click()Dim A() As IntegerDim I As Integer, m As IntegerDim K As IntegerReDim A(10)For I = 1 To 10A(I) = IPrint A(I);Next IPrintm = InputBox("ÊäÈëm")K = 9 + mReDim Preserve A(K)For I = 11 To KA(I) = A(I - 10)Next IFor I = 1 To 10A(I) = A(I + m - 1)Next IFor I = 1 To 10Print A(I);Next IPrintEnd Sub3.Option ExplicitPrivate Sub Command1_Click()Dim I As Integer, J As Integer, K As IntegerDim a() As Integer, n As Integer, p As IntegerDim s As String, Flag As Booleanp = 1For K = 10 To 100I = 1Do While I <= 10 And Not FlagJ = 1Do While J <= 10 And Not Flagn = I ^ 2 + J ^ 2If n = K ThenFlag = TrueReDim Preserve a(p)a(p) = Kp = p + 1s = I & Str(J) & Str(K)List1.AddItem sEnd IfJ = J + 1LoopI = I + 1LoopFlag = FalseNext KEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim A(10) As IntegerDim B(10) As Integer, S As StringDim I As Integer, J As Integer, X As IntegerA(1) = Int(90 * Rnd) + 10S = A(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = A(J) Then Exit ForNext JIf J = I ThenA(I) = XS = S & " " & A(I)Exit DoEnd IfLoopNext IText1.Text = SB(1) = Int(90 * Rnd) + 10S = B(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = B(J) Then Exit ForNext JIf J = I ThenB(I) = XS = S & " " & B(I)Exit DoEnd IfLoopNext IText2.Text = SS = ""For I = 1 To 10For J = 1 To 10If A(I) = B(J) ThenS = S & " " & A(I)End IfNext JNext IText3.Text = SEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim I As Integer, J As IntegerDim a() As Integer, K As Integer, Sum As Integer K = V al(Text1.Text)I = 1DoJ = K Mod 10ReDim Preserve a(I)a(I) = JSum = Sum + JK = K \ 10I = I + 1Loop Until K = 0Text2.Text = SumEnd Sub6.Option ExplicitPrivate Sub Command1_Click()Dim a(100, 2) As Integer, K As IntegerDim I As Integer, J As IntegerDim M As Integer, N As IntegerK = 1For I = 1 To 99For J = 1 To 99If I > J ThenM = I - JN = I + JIf Sqr(M) = Int(Sqr(M)) And Sqr(N) = Int(Sqr(N)) ThenList1.AddItem I & " " & Ja(K, 1) = Ia(K, 2) = JK = K + 1End IfEnd IfNext JNext IEnd Sub第六章参考答案实验实验6-11、Exit Do2、Y(X)3、X >= -1实验6-2【题目二】42 、26、8实验6-31、s1, key2、s As String3、ch >= "a" And ch <= "z"4、Mid(s, i, 1) = Chr(Asc(ch) + k - 26)思考:解密函数Private Sub dec(s As String, k As Integer) '解密过程Dim i As Integer, ch As String * 1For i = 1 To Len(s)ch = Mid(s, i, 1)If "A" <= ch And ch <= "Z" ThenIf Asc(ch) - k < Asc("A") ThenMid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于A的ASCII值则加上26 ElseMid(s, i, 1) = Chr(Asc(ch) - k)End IfElseIf ch >= "a" And ch <= "z" Then '多分支格式,ch介于小写a与z之间If Asc(ch) - k < Asc("a") ThenMid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于a的ASCII值则加上26ElseMid(s, i, 1) = Chr(Asc(ch) - k)End IfEnd IfNext iEnd Sub实验6-41、b() As Integer, st As String2、L <= R3、ReDim Preserve b(R)4、L = L + 1辗转相除法求最大公约数函数Private Function Gcd(ByV al p As Integer, ByV al q As Integer) As IntegerDim r As Integerr = p Mod qDo While r <> 0p = qq = rr = p Mod qLoopGcd = qEnd Function实验6-5【题目一】age = age(n - 1) - 3【题目二】1、(Left + Right) / 22、Left = Mid + 1实验6-61、3 -12、7 43、3 -14、7 0实验6-7【题目一】1、Sqr(2 + t)2、Abs(a - 1) < eps【题目二】1、Dim X As Integer2、"S(" & I & ")=" & S(I)3、(j * i + 1)习题参考答案一选择题二、填空1(1)形式、(2)实在2(1)按地址传递、(2)ByV al3(1)窗体模块、(2)标准模块、(3)类模块4(1) 65(1)4 20 1016(1) 6 26 、(2)-2 987(1)10 6 、(2) 5 -58(1) 6 5 、(2)8 79(1)11 、(2)710(1)Fun(i) 、(2)Fun=p11(1) 4 、(2)20.712(1)29 、(2)28.713(1)k = j 、(2)b() As Integer14(1)gec 、(2)ge 、(3) 315(1)p1 = True And p2 = True 或p1 And p2 、(2)p1 = p2 – 2 、(3)Isp = True 、(4)m Mod i = 016(1)Convert(st) 、(2)Len(s) 、(3)"A" To "F" 、(4)k = k + p * h17(1)isualVi 、(2)sualV isu18(1)s + a 、(2)n + 1 、(3)x As Single, n As Integer 、(4)p * (x + i) / ((2 * i - 1) * i * x) 三、改错题1、Option Base 1Private Sub Command1_Click()Dim A() As Integer, I As Integer, J As Integer, Logic As BooleanDim K As IntegerReDim A(1)A(1) = 50————————'K=1For I = 51 To 149K = 1 '位置错Logic = FalseCall Sub1(A, I, Logic)If Logic ThenK = K + 1ReDim A(K) 'ReDim Preserve A(K)A(K) = IEnd IfNext IFor I = 1 To UBound(A)Text1 = Text1 & Str$(A(I))If I Mod 5 = 0 Then Text1 = Text1 & vbCrLfNext IEnd SubPrivate Sub Sub1(A() As Integer, N As Integer, F As Boolean)Dim I As Integer, J As Integer, Ub As IntegerUb = UBound(A)For I = 1 To UbFor J = 2 To A(I)If A(I) Mod J = 0 And N Mod J = 0 ThenExit For 'Exit SubEnd IfNext JF = TrueNext IEnd Sub2、Option ExplicitOption Base 1Private Sub Command1_Click()Dim I As Integer, Flg As Boolean, S1 As Integer, S2 As IntegerDim J As Integer, K As Integer, P() As IntegerReDim P(1)P(1) = 2For I = 3 To 150 Step 2For J = 2 To Sqr(I)If I Mod J = 0 Then Exit ForNext JIf J > Sqr(I) ThenReDim Preserve P(UBound(P) + 1)P(UBound(P) + 1) = I 'P(UBound(P)) = IEnd IfNext IFor I = 80 To 125If fun(I, P, S1, S2) Then 'If fun(I, P, S1, S2)Text1 = Text1 & Str$(I) & "=" & Str(S1) & "*" & Str$(S2) & vbCrLf End IfNext IEnd SubPrivate Function fun(N As Integer, P() As Integer, S1 As Integer, S2 As Integer) As Boolean Dim I As Integer, J As IntegerFor I = 1 To UBound(P)For J = 1 To UBound(P) - 1If N = P(I) * P(J) ThenS1 = P(I)S2 = P(J)'fun = TrueExit Functionfun = True '位置错End IfNext JNext IEnd Function3、Option ExplicitPrivate Sub Get_Chess(Chess() As Integer, idx As Integer, Over As Integer) 'ByV al idx As IntegerDim Ub As Integer, Counter As Integer, K As IntegerUb = UBound(Chess)Chess(idx) = 0Counter = 1K = 0 '位置错Do Until Counter = Ub - 1Do Until K = 2idx = idx + 1If idx > Ub Then idx = 1K = K + Chess(idx)LoopChess(idx) = 0Counter = Counter + 1LoopFor Over = 1 To UbIf Chess(Over) <> 0 Then Exit ForNext OverEnd SubPrivate Sub Command1_Click()Dim Chess(32) As Integer, I As Integer, J As IntegerDim K As Integer, idx As IntegerFor I = 1 To 32For J = 1 To 32Chess(J) = 1Next JCall Get_Chess(Chess, I, K)If K = 23 ThenText1 = "从第" & Str$(I) & "号棋子开始取"Exit ForEnd IfNext IEnd Sub5、Option ExplicitPrivate Sub Form_Click()Dim S As String, Flg As BooleanDoS = InputBox("输入一个自然数")If S = "" Or Not IsNumeric(S) ThenMsgBox "请重新输入", 48 + vbOKOnlyElseExit DoEnd IfLoopjudge(S, Flg) ' Call judge(S, Flg) 或judge S, Flg If Flg ThenPrint S; "是回文数"ElsePrint S; "不是回文数"End IfEnd SubPrivate Sub judge(Ch As String, F As Boolean)Dim L As Integer, I As IntegerL = Len(Ch)F = True ' F = FalseFor I = 1 To LIf Mid$(Ch, I, 1) <> Mid$(Ch, L + 1 - I, 1) Then Exit Sub Next IF = False ' F = TrueEnd Sub四、编程题1、编程验证任一大于2的偶数可以表示成两个素数之和。
(完整版)VB程序设计教程(第3版)课后实验完整答案
A.1Private Sub Command1_Click()Label3 = Text1End SubA.2Private Sub Form_Load()Timer1.Interval = 0End SubPrivate Sub Command1_Click() '自动Timer1.Interval = 200End SubPrivate Sub Command2_Click() '手动Timer1.Interval = 0Call MyMoveEnd SubPrivate Sub Timer1_Timer()Call MyMoveEnd SubSub MyMove()Label1.Move Label1.Left - 50If Label1.Left < 0 Then Label1.Left = Form1.Width End SubA.3Private Sub Form_Click()Text1 = Val(Text1) + 1End SubPrivate Sub Form_Load()Text1 = 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 图的宽度,象素单位'Form1.Height = 260 * 16 + 200 ' 260 是图的高度,象素单位,200 是窗体的标题栏高度End SubA.5Sub Command1_Click()Text1.FontName = "隶书"Text1.FontSize = 25End SubSub Command2_Click()Text2.Text = Text1.SelTextText2.FontName = Text1.FontNameText2.FontSize = Text1.FontSizeEnd SubB.1Private Sub Command1_Click()Text2 = Format(5 / 9 * (Val(Text1) - 32), "0.00")End SubPrivate Sub Command2_Click()Text1 = Format(9 / 5 * Val(Text2) + 32, "0.00")End Sub或Private Sub Command1_Click()Dim f!, c! ' 声明两个变量f = Val(Text1)c = 5 / 9 * (f - 32)Text2 = Format(c, "0.00") ' 保留两位小数End SubPrivate Sub Command2_Click()Dim ff!, cc! ' 声明两个变量cc = Val(Text2)ff = 9 / 5 * cc + 32Text1 = Format(ff, "0.00") ' 保留两位小数End SubB.2Label2 = Format(Val(Text1) * Val(Text1) * 3.14, "0.00") End SubPrivate Sub Command2_Click()Label3 = Format(Val(Text1) * 3.14 * 2, "0.00")End SubPrivate Sub Text1_LostFocus()If Not IsNumeric(Text1.Text) ThenMsgBox "输入有非数字字符,请重新输入", , "警告"Text1.Text = ""Text1.SetFocusEnd IfEnd Sub或Private Sub Command1_Click()Label2 = Format(Val(Text1) * Val(Text1) * 3.14, "0.00") End SubPrivate Sub Command2_Click()Label3 = Format(Val(Text1) * 3.14 * 2, "0.00")End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii = 13 ThenIf Not IsNumeric(Text1.Text) ThenText1.Text = ""End IfEnd IfEnd SubB.3Private Sub Command1_Click()n = Int(Log(2) / Log(1.008) + 1)Label1 = n & "年后人数超过26 亿"End SubB.4Private Sub Command1_Click()Dim x, dx, cdx = Text1.Textdx = UCase(x)cd = Len(x)Print "大写字母为:"; dxPrint "字符串长度为:"; cdEnd SubB.5Text1 = Int(Rnd * 900 + 100)End SubPrivate Sub Command2_Click()Dim x%, x1%, x2%, x3%x = Val(Text1)x1 = x Mod 10 ' 分离出的个位数x2 = (x Mod 100) \ 10 ' 分离出的十位数x3 = x \ 100 ' 分离出的百位数Label1 = x1 * 100 + x2 * 10 + x3End SubB.6Private Sub Form_Click()Label1 = Left(Text1, 11)Label2 = Mid(Text1, 12, 6)Label3 = Right(Text1, 5)End SubB.7Private Sub Command1_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 Command2_Click()ClsEnd Sub进一步要求:Private Sub Command1_Click()PrintFor i = 1 To 5Print Tab(15 - i * 2); String(2 * i - 1, "★"); String(10 - (2 * i - 1), "☆"); String(2 * i - 1, "★") Next iEnd SubPrivate Sub Command2_Click()ClsEnd SubB.8Private Sub Form_Click()x = Val(InputBox("输入一正实数", "计算", 0))pf = Format(x * x, "0.000")pfg = Format(Sqr(x), "0.000")lf = Format(x * x * x, "0.000")lfg = Format(x ^ (1 / 3), "0.000")Print "平方为:"; pf; Space(5); "平方根为:"; pfg; Space(5); "立方为:"; lf; Space(5); "立方根为:"; lfgEnd SubC.1Private Sub Form_Click()Dim x!, y!x = Val(InputBox("输入x 的值"))If x < 1000 Theny = xElseIf x < 2000 Theny = 0.9 * xElseIf x < 3000 Theny = 0.8 * xElsey = 0.7 * xEnd IfPrint yEnd SubC.2Private Sub Form_Click()Dim x!, y!x = Val(InputBox("输入上网时间"))If x < 10 Theny = 30ElseIf x < 50 Theny = 30 + 2.5 * (x - 10)Elsey = 30 + 2.5 * 40 + 2 * (x - 50)End IfIf y > 150 Theny = 150End IfPrint yEnd SubC.3Private Sub Command1_Click()Dim x!, y!, z!x = InputBox("input x")y = InputBox("input y")z = InputBox("input z")Print " x y z"Print " 排序前"; x; " "; y; " "; z Ifx < y Then t = x: x = y: y = tIf x < z Then t = x: x = z: z = tIf y < z Then t = y: y = z: z = tPrint " 排序后" & x & " " & y & " " & z End SubPrivate Sub Command2_Click()Dim x!, y!, z!x = InputBox("input x")y = InputBox("input y")z = InputBox("input z")Print " x y z"Print " 排序前"; x; " "; y; " "; z Ifx < y Then t = x: x = y: y = tIf y < z Thent = y: y = z: z = tIf x < y Thent = x: x = y: y = tEnd IfEnd IfPrint " 排序后" & x & " " & y & " " & z End SubC.4Dim a(3) As IntegerPrivate Sub Command1_Click()Picture1.ClsFor i = 0 To 2a(i) = Int(Rnd * 100 + 200)Picture1.Print a(i)Next iEnd SubPrivate Sub Command2_Click()Picture2.ClsDim z As IntegerFor i = 0 To 1If a(i) > a(i + 1) Thenz = a(i + 1)a(i + 1) = a(i)a(i) = zEnd IfNext iPicture2.Print a(0)Picture2.Print a(1)Picture2.Print a(2)End SubC.5Private Sub Text2_LostFocus()Dim m%, n%, y%m = Val(Text1)n = Val(Text2)If n Mod 2 <> 0 ThenMsgBox ("脚数必定为偶数")Text2 = ""Text2.SetFocusElsey = n / 2 - mIf y < 0 ThenMsgBox ("脚数必须≥2 倍的头数,请重新输入")Text2 = ""Text2.SetFocusElsex = n / 2 - mLabel2 = yLabel3 = m - yEnd IfEnd IfEnd SubC.6Private Sub Command1_Click()Dim a!, b!, c!, x1!, x2!, de!a = Text1b = Text2c = Text3de = b * b - 4 * a * ct = 2 * aIf de = 0 ThenText4 = Format(-b / t, "0.00")Text5 = Format(-b / t, "0.00")ElseIf de > 0 ThenText4 = Format((-b + Sqr(de)) / t, "0.00")Text5 = Format((-b - Sqr(de)) / t, "0.00")ElseText4 = 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" End IfEnd SubPrivate Sub Command2_Click()Text1 = ""Text2 = ""Text3 = ""Text4 = ""Text5 = ""End SubC.7Private Sub Text3_LostFocus()Select Case Trim(Text3)Case "+"Text4 = Val(Text1) + Val(Text2)Case "-"Text4 = Val(Text1) - Val(Text2)Case "*"Text4 = Val(Text1) * Val(Text2)Case "/"If Val(Text2) = 0 ThenMsgBox "分母为零,重新输入"Text2 = ""Text2.SetFocusElseText4 = Val(Text1) / Val(Text2)End IfEnd SelectEnd SubC.8Private Sub Text1_LostFocus()Select Case Trim(Text1)Case 1Text2 = "Monday"Case 2Text2 = "Tuesday"Case 3Text2 = "Wednesday"Case 4Text2 = "Thursday"Case 5Text2 = "Friday"Case 6Text2 = "Saturday"Case 7Text2 = "Sunday"Case Is > 7, Is < 1MsgBox "数字为1~7,重新输入"Text1 = ""Text1.SetFocusEnd SelectEnd Sub或者Private Sub Text1_LostFocus()If Text1 > 7 Or Text1 < 1 ThenMsgBox "数字为1~7,重新输入"Text1 = ""Text1.SetFocusElseText2 = Choose(Text1, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")End IfEnd SubD.1Private Sub Form_Click()For i = 1 To 9Print Tab(10 - i); String(2 * i - 1, Trim(Str(i)))Next iEnd SubD.2Private Sub Form_Click()For i = 1 To 10 Step 1Print Tab(i); String((20 - 2 * i), Chr(64 + i))Next iEnd SubD.3Private Sub Command1_Click()Dim s!, t!, i&s = 1t = 1For i = 1 To 100000t = t + is = s + 1 / tIf 1 / t < 0.00001 Then Exit ForNext iPrint "For 结构"; s, i; "项"End SubD.4Private Sub Command1_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 iPrint "当n=" & n & "时,pi="; piEnd SubD.5Private Sub Form_Click()Dim s!, t!, i!, a%, n%a = Int(Rnd * 9 + 1)n = Int(Rnd * 6 + 5)t = 0: s = 0Print "a="; a, "n="; nFor i = 1 To nt = t * 10 + as = s + tPrint t;Next iPrintPrint "s="; sEnd SubD.6Private Sub Command1_Click()Dim s As Integers = 0For i = 1 To 9For j = 0 To 9For k = 0 To 9s = i * 100 + j * 10 + kIf s = i ^ 3 + j ^ 3 + k ^ 3 ThenPrint sEnd IfNext kNext jNext iEnd SubPrivate Sub Command3_Click()formd6.Hidemain.ShowEnd SubD.7Private Sub Command1_Click()Dim a!, x0!, x1!a = 27x0 = 2i = 0Doi = i + 1x1 = 2 * x0 / 3 + a / (3 * x0 * x0)If Abs(x1 - x0) < 0.00001 Then Exit Dox0 = x1LoopPrint x1, iEnd SubD.8Private Sub Command1_Click()s = 0x0 = 0.01For i = 1 To 30s = s + x0x0 = x0 * 2Next iPrint sEnd SubD.9Private Sub Command4_Click()Picture1.ClsPicture1.Print "x 课安排在"; "y 课安排在"; "z 课安排在"Picture1.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), "周一", "周二", "周三", "周四", "周五", "周六", "周日") Picture1.Print " "; X1; " "; Y1; " "; z1Next YNext xNext zEnd SubE.1Private Sub Form_Click()Dim a(1 To 10) As IntegerFor i = 1 To 10a(i) = Int(Rnd * 71 + 30)Print a(i); " ";Next iMax = a(1)Min = a(1)Avg = a(1)For i = 2 To 10If a(i) > Max Then Max = a(i)If a(i) < Min Then Min = a(i)Avg = Avg + a(i)Next iAvg = Avg / 10PrintPrint "Max="; Max; " Min="; Min; " Avg="; AvgEnd SubE.2Private Sub Form_Click()Dim aa = Array(56, 78, 98, 88, 76, 78)For i = 0 To 5Print String(a(i) \ 5, "◆"); a(i)PrintNext iEnd SubE.3Dim a%(19)Private Sub Command1_Click()Picture1.ClsFor i = 0 To 19a(i) = Int(Rnd * 101)Picture1.Print a(i); " ";If (i + 1) Mod 4 = 0 Then Picture1.PrintNext iEnd SubPrivate Sub Command2_Click()Picture2.ClsDim s(5 To 9)For i = 0 To 19k = a(i) \ 10Select Case kCase 0 To 5s(5) = s(5) + 1Case 9 To 10 '90~100 分的人数s(9) = s(9) + 1Case 6 To 8 ' 存放其他三个分数段的下标有规律,根据K 获得s(k) = s(k) + 1End SelectNext iFor i = 5 To 9If s(i) <> 0 Then Picture2.Print "s("; i; ")的人数有"; Format(s(i), "0"); "个" Next iEnd SubE.4Private Sub Command1_Click()Picture1.ClsDim d%(1 To 10)For i3 = 1 To 10Randomized(i3) = Int(Rnd * 91 + 10)Next i3For i = 1 To 10For j = 1 To 10 - iIf d(j) < d(j + 1) Thent = d(j): d(j) = d(j + 1): d(j + 1) = tEnd IfNext jNext iFor i = 1 To 10: Picture1.Print d(i);If i Mod 5 = 0 Then Picture1.PrintNext iEnd SubE.5Dim a%(3, 3), b%(3, 3)Private Sub Form_Load()For i = 0 To 3For j = 0 To 3a(i, j) = Int(Rnd * 36 + 35)b(i, j) = Int(Rnd * 41 + 100)Next jNext iEnd SubPrivate Sub Command1_Click()Picture1.ClsFor i = 0 To 3For j = 0 To iPicture1.Print a(i, j); " ";Next jPicture1.PrintNext iEnd SubPrivate Sub Command2_Click()Picture2.ClsFor i = 0 To 3For j = i To 3Picture2.Print Tab(j * 6); b(i, j);Next jPicture2.PrintNext iEnd SubPrivate Sub Command3_Click()Picture3.Clssa = 0For i = 0 To 3sa = sa + a(i, i)Next isb = 0For i = 0 To 3sb = sb + b(i, 3 - i)Next iPicture3.Print "A 数组主对角线元素和为:"; sa Picture3.Print "B 数组副对角线元素和为:"; sb End SubE.6Private Sub Form_Click()n = InputBox("输入n 值")ReDim a6%(n + 1, n + 1)a6(0, 0) = 1: a6(1, 1) = 1: a6(1, 0) = 1For i = 2 To n + 1For j = 2 To ia6(i, j) = a6(i - 1, j - 1) + a6(i - 1, j) Picture1.Print a6(i, j); "";Next jPicture1.PrintNextEnd SubE.7Private Sub Form_Load()List1.ClearList1.AddItem "大学计算机基础"List1.AddItem "C/C++程序设计"List1.AddItem "VB 程序设计"List1.AddItem "Web 程序设计"List1.AddItem "多媒体技术与应用"List1.AddItem "数据库技术与应用"List1.AddItem "网络技术与应用"List1.AddItem "硬件技术基础"List1.AddItem "软件技术技术基础"End SubPrivate Sub List1_Click()If List2.ListCount >= 5 ThenMsgBox ("超过5 门课程,不能再选")Exit SubElseList2.AddItem List1.TextList1.RemoveItem List1.ListIndexEnd IfEnd SubE.8Sub Combo1_KeyPress(KeyAscii As Integer) Select Case KeyAsciiCase 48 To 57, 13Case ElseKeyAscii = 0End SelectIf KeyAscii = 13 ThenCombo1.AddItem Combo1.TextCombo1.Text = ""End IfEnd SubPrivate Sub Command1_Click()Dim min%, max%min = Val(Combo1.List(0))max = Val(Combo1.List(0))imin = 0imax = 0For i = 1 To Combo1.ListCount - 1If Val(Combo1.List(i)) > max Thenimax = imax = Combo1.List(i)ElseIf Val(Combo1.List(i)) < min Thenimin = imin = Combo1.List(i)End IfNext it = Combo1.List(0)Combo1.List(0) = Combo1.List(imin)Combo1.List(imin) = tt = Combo1.List(Combo1.ListCount - 1)Combo1.List(Combo1.ListCount - 1) = Combo1.List(imax) Combo1.List(imax) = tEnd SubE.9Private Sub Form_Click()For i = 0 To Screen.FontCount - 1If Asc(Left(Screen.Fonts(i), 1)) < 0 ThenPicture1.Print Screen.Fonts(i)Picture2.FontName = Screen.Fonts(i)Picture2.Print "商丘师范学院"End IfNext iEnd SubE.10Private Type clerknumber As String * 3name As String * 5salary As IntegerEnd TypeDim a(0 To 4) As clerk, n%Private Sub Command1_Click()If n >= 5 ThenMsgBox ("输入人数超过数组声明的个数")ElseWith a(n).number = Text1.name = Text2.salary = Text3Picture1.Print a(n).number, a(n).name, a(n).salary PrintEnd Withn = n + 1Text1 = ""Text2 = ""Text3 = ""End IfEnd SubPrivate Sub Command2_Click()Dim t As clerk, i%, j%For i = 0 To n - 1For j = i To n - 1If a(i).salary < a(j + 1).salary Thent = a(i): a(i) = a(j + 1): a(j + 1) = tEnd IfNext jNext iPicture1.ClsPicture1.Print "工号姓名工资" For i = 0 To n - 1Picture1.Print a(i).number, a(i).name, a(i).salaryPrintNext iEnd SubF.1Private Sub Form_Click()Dim a(1 To 10), amin, i%For i = 1 To 10a(i) = -Int(Rnd * 101 + 300)Print a(i);Next iCall s(a(), amin)PrintPrint "min="; aminEnd SubSub s(b(), min)Dim i%min = b(LBound(b))For i = LBound(b) + 1 To UBound(b)If b(i) < min Then min = b(i)Next iEnd SubF.2Private Sub Command1_Click()Dim mm%, nn%mm = Val(Text1)nn = Val(Text2)Picture1.Print mm; Tab(6); nn; Tab(12); gcd(mm, nn) End SubFunction gcd%(ByVal m%, ByVal n%)If m < n Then t = m: m = n: n = tr = m Mod nDo While (r <> 0)m = n: n = r: r = m Mod nLoopgcd = nEnd FunctionF.3Dim x!Private Sub Command1_Click()Print "调用标准函数Sin 的结果"; Sin(x)End SubPrivate Sub Command2_Click()Print "调用自定义函数MySin 的结果"; MySin(x) End SubFunction MySin(x!) As DoubleDim i%, t!, s!t = xs = ti = 1Do While Abs(t) > 0.00001t = -1 * t * x * x / ((i + 1) * (i + 2))s = s + ti = i + 2LoopMySin = sEnd FunctionPrivate Sub Command3_Click()x = InputBox("输入要计算正弦函数的角度值x") x = x * 3.14 / 180End SubF.4Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 ThenIf Not IsNumeric(Text1) ThenMsgBox "输入非数字串,重新输入"Text1.Text = ""Text1.SetFocusElseIf IsH(Text1) ThenPicture1.Print Text1; " ★"ElsePicture1.Print Text1End IfText1 = ""End IfEnd IfEnd SubFunction IsH(ss As String) As BooleanDim i%, Ls%IsH = Truess = Trim(ss)Ls = Len(ss)For i = 1 To Ls \ 2If Mid(ss, i, 1) <> Mid(ss, Ls + 1 - i, 1) ThenIsH = FalseExit FunctionEnd IfNext iEnd FunctionF.5Function prime(ByVal m As Integer) As Booleanprime = TrueDim i%For i = 2 To m - 1If (m Mod i) = 0 Then prime = False: Exit Function '注意冒号和exit 的范围Next iEnd FunctionPrivate Sub Command1_Click()n = 0For i = 6 To 100 Step 2For j = 3 To i \ 2If prime(j) ThenIf prime(i - j) ThenList1.AddItem i & " =" & j & " +" & i - jn = n + 1End IfEnd IfNext jNext iPicture1.Print " 6 和100 之间共有"; n; "对素数和"End SubF.6Dim a%()Private Sub Form_Click()Print "1000 以内的完数为:"For i = 1 To 1000If IsWs(i) ThenPrint i; "=1";For j = 1 To UBound(a)Print "+"; a(j);Next jPrintEnd IfNext iEnd SubFunction IsWs(m) As BooleanDim s%s = 0For i = 1 To m \ 2If m Mod i = 0 ThenReDim Preserve a(j)a(j) = ij = j + 1s = s + iEnd IfNext iIf m = s Then IsWs = TrueEnd FunctionF.7Private Sub DeleStr(s1 As String, ByVal s2 As String)Dim i%ls2 = Len(s2)i = InStr(s1, s2)Do While i > 0s1 = Left(s1, i - 1) + Mid(s1, i + ls2) ' 在s1 中去除s2 子串i = InStr(s1, s2)LoopEnd SubPrivate Sub Command1_Click() ' 调用DeleStr 子过程Dim ss1 As Stringss1 = Text1Call DeleStr(ss1, Text2)Text3 = ss1End SubPrivate Sub Command2_Click()End SubF.8Private Sub Command1_Click()Dim maxw$maxlen Text1 & " ", maxwText2 = maxwEnd SubSub maxlen(s$, maxw$)Dimword$ maxw = ""Do While s <> ""i = InStr(s, " ")word = Left(s, i - 1)If Len(word) > Len(maxw) Then maxw = words = Mid(s, i + 1)LoopEnd SubG.1Private Sub Command1_Click()List1.ClearList1.AddItem 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(Text1))le = Len(st)If Not IsNumeric(Left(st, le - 2)) Or Right(st, 2) <> "MB" Then MsgBox "有不合法字符!"Text1 = ""Text1.SetFocusEnd IfEnd SubG.2Private Sub Check1_Click()Picture1.Font.Bold = Not Picture1.Font.BoldEnd SubPrivate Sub Check2_Click()Picture1.Font.Italic = Not Picture1.Font.BoldEnd SubPrivate Sub Command1_Click()Picture1.ClsIf Option1 ThenPicture1.Print Sin(Val(Text1))ElseIf Option2 ThenPicture1.Print Exp(Val(Text1))ElseIf Option3 ThenPicture1.Print Sqr(Val(Text1))End IfEnd SubPrivate Sub return_Click(Index As Integer)Form6.ShowUnload Form2End SubG.3Private Sub HScroll1_Change()Text1 = VScroll1.ValueText2 = HScroll1.ValueText3 = HScroll2.ValueText4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), "0.00") Text5 = Format(Val(Text4) + Val(Text1), "0.00")End SubPrivate Sub HScroll2_Change()Text1 = VScroll1.ValueText2 = HScroll1.ValueText3 = HScroll2.ValueText4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), "0.00") Text5 = Format(Val(Text4) + Val(Text1), "0.00")End SubPrivate Sub VScroll1_Change()Text1 = VScroll1.ValueText2 = HScroll1.ValueText3 = HScroll2.ValueText4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), "0.00") Text5 = Format(Val(Text4) + Val(Text1), "0.00")End SubG.4Dim t As SinglePrivate Sub Command1_Click()t = InputBox("输入倒计时分钟数")t = t * 60ProgressBar1.Min = 0ProgressBar1.Max = tProgressBar1.Value = tEnd SubPrivate Sub Command2_Click()Timer1.Interval = 1000ProgressBar1.Visible = TrueEnd SubPrivate Sub Timer1_Timer()Dim m%, s%t = t - 1ProgressBar1.Value = tm = t \ 60s = t Mod 60Label1 = m & "分" & s & "秒"If t = 0 ThenMsgBox " 时间到!"Timer1.Interval = 0ProgressBar1.Visible = FalseEnd IfEnd SubG.5Private Sub Command1_Click()CommonDialog1.ShowColorLabel1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Command2_Click()CommonDialog1.ShowOpeni = Shell("C:\WINDOWS\NOTEPAD.exe " + CommonDialog1.FileName, vbNormalFocus) End SubG.6rivate Sub bold_Click()Text1.FontBold = Not Text1.FontBoldbold.Checked = Not bold.CheckedEnd SubPrivate Sub del_Click()Text1 = ""End SubPrivate Sub end_Click()EndEnd SubPrivate Sub font12_Click()Text1.FontSize = 12End SubPrivate Sub font16_Click()Text1.FontSize = 16End SubPrivate Sub Form_Load()bold.Checked = Falseitalic.Checked = FalseEnd SubPrivate Sub italic_Click()Text1.FontItalic = Not Text1.FontItalicitalic.Checked = Not italic.CheckedEnd SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then PopupMenu menu2End SubG.7Private Sub Command1_Click()CommonDialog1.ShowColorLabel1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Command2_Click()CommonDialog1.ShowOpeni = Shell("C:\WINDOWS\NOTEPAD.exe " + CommonDialog1.FileName, vbNormalFocus) End SubPrivate Sub return_Click(Index As Integer)Form6.ShowUnload Form5End SubG.8G.9Private Sub 结束_Click()EndEnd SubPrivate Sub 删除最大值_Click()max = List1.List(0)For i = 1 To List1.ListCount - 1If max < List1.List(i) Then max = List1.List(i): j = i Next iList1.RemoveItem jEnd SubPrivate Sub 删除最小值_Click()min = List1.List(0)For i = 1 To List1.ListCount - 1If min > List1.List(i) Then min = List1.List(i): j = i Next iList1.RemoveItem jEnd SubPrivate Sub 随机产生_Click()RandomizeFor i = 0 To 9List1.List(i) = Int(Rnd * 30 + 70)Next iEnd SubPrivate Sub 添加数据_Click()List1.AddItem Int(Rnd * 30 + 70)End SubPrivate Sub 统计_Click()Dim max%, min%, ave!, m%, n%max = List1.List(0)min = List1.List(0)ave = List1.List(0)m = 0n = 0For i = 1 To List1.ListCount - 1If max < List1.List(i) Then max = List1.List(i): m = i If min > List1.List(i) Then min = List1.List(i): n = i ave = ave + List1.List(i)Next iForm2.Text1 = List1.List(n)Form2.Text2 = List1.List(m)Form2.Text3 = Format(ave / List1.ListCount, "0.00") Form2.ShowEnd SubG.10Private Sub experimentG2_Click()Form2.ShowEnd SubPrivate Sub experimentG3_Click()Form3.ShowEnd SubPrivate Sub experimentG4_Click()Form4.ShowEnd SubPrivate Sub experimentG5_Click()Form5.ShowEnd SubPrivate Sub font_12_Click()Text1.FontSize = 12End SubPrivate Sub font_16_Click()Text1.FontSize = 16End SubPrivate Sub rnd10_Click()RandomizeFor i = 0 To 9List1.List(i) = Int(Rnd * 30 + 70)Next iEnd SubPrivate Sub stat_Click()Dim max%, min%, ave!, m%, n%max = List1.List(0)min = List1.List(0)ave = List1.List(0)m = 0n = 0For i = 1 To List1.ListCount - 1If max < List1.List(i) Then max = List1.List(i): m = i If min > List1.List(i) Then min = List1.List(i): n = i ave = ave + List1.List(i)Next istat2.Text1 = List1.List(n)stat2.Text2 = List1.List(m)stat2.Text3 = Format(ave / List1.ListCount, "0.00")stat2.ShowEnd SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then PopupMenu caidan2, vbPopupMenuCenterAlignEnd SubPrivate Sub xie_Click()Text1.Font.Italic = Not Text1.Font.BoldEnd SubH.1Private Sub Command1_Click()Open "c:\score" For Output As #1Print #1, "051023", "王海涛", 66Print #1, "052498", "周文英", 88Print #1, "050992", "陈建东", 77Open "c:\score1" For Output As #2Write #2, "051023", "王海涛", 66Write #2, "052498", "周文英", 88Write #2, "050992", "陈建东", 77Closei1 = Shell("NOTEPAD.exe" + " c:\score", vbNormalNoFocus)i2 = Shell("NOTEPAD.exe" + " c:\score1", vbNormalNoFocus)End SubPrivate Sub Command2_Click()Dim no As String, name As String, s As IntegerOpen "c:\score" For Input As #1Do While Not EOF(1)Line Input #1, linedataList1.AddItem linedataLoopOpen "c:\score1" For Input As #2Do While Not EOF(2)Input #2, no, name, sList2.AddItem no & name & sLoopCloseEnd SubH.2Private Sub Command1_Click()Dim fib%(0 To 9), i%Open "c:\fb.dat" For Output As #1For i = 0 To 9If i = 0 Or i = 1 Thenfib(i) = iElsefib(i) = fib(i - 1) + fib(i - 2)End IfPrint #1, """Fib(" & i & ")""," & fib(i)Next iClose #1i = Shell("NOTEPAD.exe" + " c:\fb.dat", vbNormalNoFocus) End SubPrivate Sub Command2_Click()Dim st$, n%, sum%Open "c:\fb.dat" For Input As #1Do While Not EOF(1)Input #1, st, nsum = sum + nList1.AddItem st & "=" & nLoopClose #1List1.AddItem " 合计:" & sumList1.AddItem "平均:" & sum / 10End SubH.3H.4Private Type studtypeno As String * 4name As String * 6mark As SingleEnd TypeDim student As studtype, stud(1 To 5) As studtype, t As studtypePrivate Sub Command1_Click()Open "d:\score.dat" For Random As #1 Len = Len(student) With student.no = "0001".name = "星期一"。
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编程的常用命令。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验教材实验一
1:单项选择题:
A A C C C D C
B B C
2:填空题:
(1).bas
(2).vbp,.frm
(3)视图工具箱
(4)对象
(5)属性对象事件方法
(6)Windows
(7)事件行为
(8)窗体模块
实验二
1:单项选择题:
A D C C A
B A B D
C B B C B C B A B
D C 2:基本运算题:
(1)27
(2)3.33333333333333
(3)3
(4)0
(5)-3
(6)2
(7)ab33
(8)类型不匹配
(9)3
(10)AB3
实验三
1:单项选择题:
B C B D C
2:填空题:
(1)300
(2)321456
(3)Shanghai
(4)6 7 6
(5)True
(6)2+3=5
(7)”area=” 12.56
(8)VISUAL
实验四
1:单项选择题:
C A A C A
2:填空题:
(1)7
(2)3 5
(3)输入的数小于0
(4)3
(5)False
(6)2010 is not leap year.
试验五
1:单项选择题:
A C C A
B A
C C C B
2:填空题:
(1)9
(2)①n ②1
(3)①Len(a) ②n\2 ③Mid(a,(n-i+1),1) ④Mid(a,(n-i+1),1)
(4)①n Mod 3=1 And n Mod 5=1 And n Mod 7=1 ②While CountN<5
(5)Mid(c1,1,i)
实验六
1:单项选择题:
D B D C D A C A D D
2:填空题:
(1)30
(2)3
(3)①a(2) ②a(3) ③a(1)
(4)①1 ②2 ③a(i)=a(6-i)
(5)①i+j ②0 ③a(i,j)
(6)①Print ②k ③a(k,j)=a(j,k) ④a(k,j);
实验七
1:单项选择题:
A B B A C B
2:填空题:
(1)15
(2)①Preserve a(n+1) ②a(i+1)=a(i) ③Exit For ④a(i+1)=m⑤0 to n+1 (或LBound(a) to UBound(a))
(3)d,c,b,a
实验八
1:单项选择题:
C A
D B D C A C B
2:填空题:
(1)a=9 b=4
(2)
36
25
16
9
4
1
(3)①a ②UBound(b) ③
实验九
1:单项选择题:
D D D B B C A B C A D
2:填空题:
(1)①p=p*n ②Fac(n) ③10^-6
(2)①Max=x ②Max=y ③p ④Max(x,a(n))
(3)①number(i) ②n as integer ③number=number+7*10^(i-1)
实验十
1:单项选择题:
D C B A B C
实验十一
1:单项选择题:
D A D B B B B D D
实验十二
1:单项选择题:
C B C B C C B
D A D D B C
2:填空题:
(1)①Label1.FondName=Combo1.Text
②Combo2.Text ③Label1.FontBold=True ④Label1.FondItalic=True
⑤Label1.FondSize=Combo3.Text
(2)①List1.Text ②List1.RemoveItem List1.ListIndex
③List1.AddItem List2.Text ④List2.RemoveItem
实验十三
实验十四
1:单项选择题:
D A C D A A B C
2:填空题:
(1)ShowFont
(2)打开另存为颜色字体打印机帮助
(3)工程部件Microsoft Common Dialog Control 6.0
(4)ShowColor Action=3
实验十五
1:单项选择题:
C B B C B B B A D
2:填空题:
(1)内建菜单弹出菜单
(2)Click
(3)工具
(4)代码窗口Click
(5)相同不同
实验十六
1:单项选择题:
B C A A C A C D D B D C C
2:填空题:
(1)①Open “c:\stud1.txt” For Output As #1
②Text1.Text=”End”
③White #1,Text1.Text
(2)①For Input ②For Output As #2 ③Not Eof(1)
④Input #1,str1 ⑤Close #1,#2 ⑥Kill(“c:\old.txt”(3)①For Output ②For Input As #2。