VB程序设计教程实验指导与习题解答上机答案

合集下载

【参考文档】vb实验指导书答案-范文word版 (10页)

【参考文档】vb实验指导书答案-范文word版 (10页)
1. BCADCCABCA AADDC BCABB 2.(1)3 (2)X mod 5 x (3)randomize (4)9 j mod 3=0(5)66 (6)5 (7)顺序分支(或选择) 循环 (8)33(9)484(10) 退出子过程 (11)1 (12)提示信息标题默认值
第6章 过程
一、单选题
二、填空题 2.5 5. 工具 7. &,Click 8. Enabled 9. 窗体
10. 模式,无模式
11. Action
12. CommonDialog1.FileName 13. cdlCCRGBInit 14. Unload,Show 15. 所在窗体的名称 16. 打开 17. Visible 18. 当前 19. 255 20. Show
(6)强制显式声明变量 (7)类 P35 第三章
1. CBAAABCDAD ABBBC ADDBD 2.(1)integer (2)???? (3)text (4)a=0 or b=0 (5)(x+y)*sin(30*3.14/180) (6)int(rnd*100+1)(7)# (8)0
1
C
(9)int(rnd*30+70)(10) CDEF P53 第四章
本文部分内容来自网络整理,本司不为其真实性负责,如有异议或侵权请及时联系,本司将立即删除!
== 本文为word格式,下载后可方便编辑和修改! ==
vb实验指导书答案
篇一:VB程序设计学习与实验指导书答案(包含实验答案)
VB学习与实验指导测试题
参考答案
第一章
第二章
第三章
第四章
第五章
第六章
第七章
第八章
篇二:VB实验指导书答案

vb程序设计实验教程习题答案(精品).doc

vb程序设计实验教程习题答案(精品).doc

实验教材实验-1:单项选择题:AACCC DCBBC2:填空题:(1).bas(2).vbp, ,frm(3)视图工具箱(4)对象(5)属性对象事件方法(6)Windows(7)事件行为(8)窗体模块实验二1:单项选择题:ADCCA BAB DC BBCBC BAB DC 2:基本运算题:(1)27(2) 3.33333333333333(3) 3(4)0(5)-3(6) 2(7)ab33(8)类型不匹配(9) 3(10)AB3实验三1:单项选择题:BCBDC2:填空题:(1)300(2)321456(3)Shanghai(4) 6 7 6(5)True(6)2+3=5(7)”area=” 12.56(8)VISUAL实验四1:单项选择题:CAACA2:填空题:(1)7(2) 3 5(3)输入的数小于0(4) 3(5)False(6)2010 is not leap year.试验五1:单项选择题:ACCAB ACCCB2:填空题:(1)9(2)@n ② 1(3)®Len(a)②n\2 ③Mid(a,(n-i+l),l)④Mid(a,(n-i+l),l)(4)@n Mod 3=1 And n Mod 5=1 And n Mod 7=1 ©While CountN<5(5)Mid(cl,l,i)实验六1:单项选择题:DB DCD ACADD2:填空题:(1)30(2) 3(3)①a(2)②a(3)③a(l)(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:单项选择题:ABBACB2:填空题:(1)15(2)①Preserve a(n+l) ②a(i+l)=a(i) ③Exit For ④a(i+l)=m⑤0 to n+1 (或LBound(a) to UBound(a))(3)d,c,b,a实验八1:单项选择题:CADBD CACB2:填空题:(1)a=9 b=4(2)362516941(2)①a (2)UBound(b)③实验九1:单项选择题:DDDBB CAB CAD2:填空题:(1)①p=p*n ②Fac(n) ③ 10人-6(2)①Max=x ②Max=y ③p ④Max(x,a(n))(3)①number(i) ②n as integer (3)number=number+7* 10A(i-1)实验十1:单项选择题:DC BAB C实验十一1:单项选择题:DADBBB BDD实验十二1:单项选择题:CBCBC CBDAD DBC2:填空题:(1)①Label 1. FondName=Combo 1 .TextCombo2.Text ③ Label 1 .FontBold=True ④ Label 1 .FondItalic=True⑤ Label 1 .FondSize=Combo3.Text(2)①Listl.Text ©List 1 .RemoveitemListl.ListindexListl .Additem List2.Text ④ List2.RemoveItem实验十三实验十四1:单项选择题:DACDAABC2:填空题:(1)ShowFont(2)打开另存为颜色字体打印机帮助(3)工程部件Microsoft Common Dialog Control 6.0(4 ) ShowColor Action=3实验十五1:单项选择题:CB BCB B BAD2:填空题:(1)内建菜单弹出菜单(2)Click(3)工具(4)代码窗口Click(5)相同不同实验十六1:单项选择题:B CAAC ACDDB DCC2:填空题:(1)①Open "c:\studl.txt” For Output As #1Textl.Text=”End”White #l,Textl.Text(2)①For Input ②For Output As #2 ③Not Eof(l)Input #l,strl ⑤ Close #1,#2 ⑥Kill(“c:\old.txt”(3)①For Output ②For Input As #2。

VB程序设计教程实验指导与习题解答上机答案

VB程序设计教程实验指导与习题解答上机答案

程序代码Private Sub Command1_Click()End SubPrivate Sub Command2_Click() = TrueEnd SubPrivate Sub Command3_Click() = TrueEnd SubPrivate Sub Command4_Click() = 10 = False = FalseEnd Sub初始窗口:单机放大之后窗口:单机下划线之后窗口:单击加粗之后窗口:自测2单击还原之后窗口:Private Sub Command1_Click()Label1 = "visual basic"Text1 = " 程序设计题"End SubPrivate Sub Command2_Click()Text1 = "visual basic"Label1 = " 程序设计题"End Sub初始窗口:单击显示之后窗口:单击交换之后的窗口:自测题3Private Sub Command1_Click()End SubPrivate Sub Command2_Click() = + 30End Sub= + 20= 1初始窗口:单击缩小两倍之后的窗口:单击向右下角移动之后的窗口:自测题4程序代码Private Sub Command1_Click() = "VB 学习"Print"简单的VB程序设计"End SubPrivate Sub Command2_Click()ClsEnd SubPrivate Sub Command3_Click()EndEnd SubPrivate Sub Command3_Click()EndEnd Sub初始化窗口:单击显示之后的窗口:单击清除之后的窗口:自测题5单击退出之后的窗口:Private Sub Comma nd1_Click()HHEnd SubPrivate Sub Comma nd2_Click() =Val + Val End SubPrivate Sub Comma nd3_Click() End End Sub初始化窗口: 单击运算之后窗口: 单击清除之后的窗口:也 I 绘I lirr-:輕 g砖屮 ZBPL H J ^E 霸赴 BAy 噹晔了 ZILT. 相0 ■tap乜=1 业 '-JS-J Q -•ST F■ I” _l ■■ B 事电r 兴/涉审叭暂背巧応科1I gMd I T B ' A bJ El -; F 」 )-1 a □瓷 a QB aitr 硕八— y -I Su日 r>M| PLi.l CnhwJ x> 蚀-7 -■nJ肝 k4・Jii.— Tr«:h^.L 33 -:呻p Ju IpL*口- i-JN h —vid.]F TM IHFLlMv ■ -UKncnm-'|LUIPI> r■41•成 &.■ B WOQULL,:■—PMd P GPrivate Sub Command1_Click()Dim a$= Left(a, 2)End SubPrivate Sub Command2_Click()= Right(a, 2)End SubPrivate Sub Command3_Click()End Sub初始窗口界面输入字符串截取前两个字符截取后两个字符字符串连接自测练习2 Private 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 ' 千位交换后的个位交换后的千位交换后的十位交换后的百位l = f * 1000 + g * 100 + h * 10 + i = FalsePrint " 加密前的4位整数是7439"; (Chr(10)); " 加密后的结果是"; l End Sub初始界面单击窗体运行后的界面自测练习1Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox(" 输入第一个数", "b = Val(InputBox(" 输入第一个数", "f = Fix(f * 100 + / 100& "x/y=" & f, , " 输出的结果"End Sub自测练习2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!Print " 和="; ePrint " 平均值="; f 输入一个数", 8)) 输入一个数", 7))MsgBox"x+y=" & c & Chr(10) & "x-y=" & d & Chr(10) & "x*y=" & e & Chr(10)a = Val(InputBox(" 输入第一个数的值"))b = Val(InputBox(" 输入第二个数的值"))c = Val(InputBox(" 输入第三个数的值"))d = Val(InputBox(" 输入第四个数的值"))End Sub自测练习3Private Sub Form_Click()Dim h%, f%, x%, y%h = Val(InputBox(" 输入总头数"))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(InputBox(" 请输入第一条边", " 边长"))b = Val(InputBox(" 请输入第二条边", " 边长"))c = Val(InputBox(" 请输入第三条边", " 边长"))If a + b > c And a + c > b And b + c > a ThenIf a * a + b * b = c * c Or a * a + c * c = b * b Or b * b = c * c = a * a ThenPrint " 直角"ElseIf a = b And b = c ThenPrint " 等边三角形"ElseIf a = b Or a = c Or b = c ThenPrint " 等腰三角形"ElsePrint " 一般三角形"End IfElsePrint " 不是三角形"End IfEnd Sub不是三角形运行结果:初始窗口:输入三条边:运行结果:直角三角形运行结果:等边三角形运行结果如下:等腰三角形:般三角形自测练习2:Private Sub Form_Click()Dim a%, b!a = Val(InputBox(" 请输入"))If a Mod 2 = 0 And a Mod 3 = 0 And a Mod 5 = 0 Then b = Sqr(a)Print a, bElseEndEnd IfEnd Sub初始化窗口: 输入一个数: 运行结果: 自测练习3Private Sub Comma nd1_Click()Dim a%, b% a = ValSelect Case a > 0Case a < 20MsgBox "行李费为元/kg",," 行李费Case a >= 20 And a < 50MsgBox "行李费为元/kg",," 行李费Case a >= 50 And a < 100MsgBox "行李费为元/kg",," 行李费Case Elseb = * 100 + (a - 100) * : MsgBox " 行李费为"& b & "元",,"行李费End SelectEnd Sub初始窗口: 输入10: 输入25: 输入55: 输入120: 自测练习1Op tio n Base 1Private Sub Form_Click()Dim i%, a(1 To 20) As In teger a(1) = 1: a(2) = 1Print a(1);Print a(2);For i = 3 To 10 a(i) = a(i - 1) + a(i - 2)Print a(i);Next iPrintFori = 11 To 16a(i) = a(i - 1) + a(i - 2)Print a(i);Next iPrintFor i = 17 To 20 a(i) = a(i - 1) + a(i - 2) Print a(i);Next i初始界面:运行结果界面:自测练习2Option Base 1Private Sub Form_Load()= 10000= 5000End SubPrivate Sub Command1_Click()Dim i%, j%, t%, a(1 To 4, 1 To 4) As Integer For i = 1 To 4For j = 1 To 4 a(i, j) = Int(Rnd * 10) + 1a(i, j);Next jNext i " 对角线的元素如下"For i = 1 To 4 a(i, i);Next iFor i = 1 To 4 a(i, 5 - i);Next iFor i = 1 To 4 t = a(1, i) a(1, i) = a(4, i) a(4, i) = t Next iFor i = 1 To 4 t = a(i, 2) a(i, 2) = a(i, 3) a(i, 3) = t Next iFor i = 1 To 4Forj = 1 To 4 a(i, j);Next jNext iEnd Sub运行初始界面:运行结果界面: 自测练习1Sub itostr(a As In teger)Dim b%, c$ a = VaiWhile a >= 1 c = Chr(a Mod 10+ 48) & c0 Fornnl施机;^生的拒畔相应处運输入矩阵茹处理般曲越$a = a \ 10WendEnd SubPrivate Sub Command1_Click()Dim a As Integer a = ValCall itostr(a)End Sub运行初始界面:运行结果界面:验证其他数字:自测练习2:Public Function area(n) As DoubleDim c#, d#, e#, s# n = Val c = (1 - 0) / nWhile e <= 1 d = I * c: e = (I + 1) * c s = s + (Sin(d) + Sin(e)) * c / 2 area = s WendEnd FunctionPrivate Sub Command1_Click()Dim s As DoubleCall area(n) = area(n)End Sub运行初始界面:运行结果:自测练习3Private Sub Form_click() n =Val(InputBox(" 请输入n 的值")) x = Val(InputBox(" 请输入x 的值"))Print "e 的值="; es(n, x)End SubPrivate Function es(n, x)Dim a As Double, b As Double, c As Double, i As Integer a = 1: b = 1: c = 1For i = 1 To n a = x * a: b = b * i: c = c + a / bNext i es = cEnd Function运行初始界面:输入数据:运行结果:自测练习4:For i = 1 To 4For j = i + 1 To 5If a(i) > a(j) Thent = a(i): a(i) = a(j): a(j) = tEnd IfNext jNext iFor i = 1 To 5Print a(i); " ";Next iFor i = 1 To 5If Y < a(i) Thent = a(i): a(i) = Y: Y = tEnd IfNext iFor i = 1 To 6a(6) = tNext iEnd FunctionPrivate Sub Command1_Click()Dim i#, a%(1 To 6), Y%Y = Val(InputBox(" 输入y 的值", " 输入数据"))Insertfun a%(), YPrintFor i = 1 To 6Print a(i); " ";Next iEnd Sub运行初始界面:插入数据:运行结果:自测练习1:Private Sub Command1_Click()If = 1 Then = " 报名参加羽毛球比赛" End IfIf = 1 Then = " 报名参加乒乓球比赛"If = 1 And = 1 ThenEnd If= " 报名参加羽毛球,乒乓球比赛"End IfEnd Sub运行初始界面:运行结果:自测练习4:Private Sub Form_Load()= 24 = " 黑体" = &HFF&End SubPrivate Sub Option1_Click() = " 我是学生"End SubPrivate Sub Option2_Click() = " 我是教师"End SubPrivate Sub Option3_Click() = " 我是工人"Private Sub Option4_Click()End Sub= " 我是农民"End Sub运行初始界面:运行结果:自测练习6:Private Sub Command1_Click()For i = 0 To - 1If (i) = ThenExit ForEnd IfNext iIf i > - 1 ThenEnd IfEnd SubPrivate Sub Command2_Click()If <> -1 ThenFor i = 0 To - 1If (i) = ThenEnd IfExit ForNext iEnd IfEnd SubPrivate Sub Command3_Click()End Sub运行初始界面:自测练习7:Private Sub Command1_Click()= TrueEnd SubPrivate Sub Form_Load()= 20= 20= 20= 20End SubPrivate Sub Timer1_Timer() lbltem = = + 10If VSbwd >= 100 Then lbltishi = " 水开了" = FalseEnd IfEnd Sub运行初始界面:运行结果:自测练习1:Private Sub myhelp_Click()End SubPrivate Sub mymenu1_Click() = " 百货大楼"End SubPrivate Sub mymenu2_Click() = " 利客隆"End SubPrivate Sub mymenu3_Click() = " 稻香村"End Sub运行初始界面:运行结果界面:自测练习2:Private Sub Dis_Click() = " 菜单程序设计" = 20 = " 黑体"End SubPrivate Sub Hid_Click() = FalseEnd Sub运行初始界面:运行结果界面:自测练习3:Private Sub vbhelp_Click() r = MsgBox(" 帮助", , " 程序设计题")End SubPrivate Sub Vbnew_Click() r = MsgBox(" 新建", , " 程序设计题")End SubPrivate Sub vbopen_Click() r = MsgBox(" 打开", , " 程序设计题")End SubPrivate Sub vbsave_Click()自测练习1: r = MsgBox ("存盘”,," 程序设计题")End Sub运行初始界面: 运行结果: 自测练习4:Private Sub Comma nd1_Click()End Sub运行初始界面:打开萱我菊園(1):文件名oa ) ; I立件类型电》:Ir 以只读方式打开區IPrivate Sub Command1_Click()Dim a As String, n%, i%, j%我最近皈由 O ■ \ 27 我的文趋 岡上嘟居^41121(1£S □141130110041145029 口 411旳[)13_辛诒_经济L1D1 亡J jag 己1« iT^ Temp 匚PySoEt 巴第五次实脸要貳文楼 □新建文件夹g2O074£3LS294SS£4 总听ni咫S ! O S6u_p L nyi n J& 1tfySystem已義单SCX倉第五欢实脸要求丈档四寫件基^操作测试內容回数据1国數据1®数据l.dbc0掏门鄱爰甘濒SllfU 实甜直评d Hl 取消Open "E:\" For Input As #1Input #1, a n = Len(a)For i = 1 To nIf Mid(a, i, 1) = "%" Then j = j + 1 Next iClose #1Open "E:\" For Output As #1Print #1, jClose #1End Sub运行初始界面:运行结果:自测练习3:Private Sub Form_Click()Dim x$Open "e:\" For Input As #1Do While Not EOF(1)LoopClose #1Open "e:\" For Append As #1Print #1, x$Close #1Line Input #1, x$运行初始界面:自测练习4Private Sub Form_load()Print " 26 个英文字母"PrintPrint " a b c d e f g h i j k l m n o p q r s t u v w x y z" Print " 字母个数分别为"End SubPrivate Sub Form_Click()Open "E:\" For Output As #1文本$ = InputBox(" 请输入文本") n = UCase( 文本$)Print #1, nOpen "E:\" For Output As #1For i = 1 To Len(n)ReDim Preserve a(1 To 26) j = Asc(Mid(n, i, 1)) - 64 a(j) = a(j) + 1Next iClose #1For j = LBound(a) To UBound(a)Print a(j);Next jClose #1Dim a%()。

vb程序设计教程课后答案与实验题答案-(第三版)资料

vb程序设计教程课后答案与实验题答案-(第三版)资料

答案习题一答案在教材上找。

习题二1.对象指现实世界中的实体。

每个对象有自己的特征(属性)、行为(方法)和发生在该对象上的活动(事件)。

类是对同一种对象的集合与抽象。

类包含所创建对象的属性数据,以及对这些数据进行操作的方法。

封装和隐藏是类的重要特性,将数据结构和对数据的操作封装在一起,类的内部实现细节对用户来说是透明的。

VB工具箱中的可视图标是VB系统设计好的标准控件类。

通过将控件类实例化,得到真正的控件对象。

在窗体上画一个控件,就将类转换为对象,创建了一个控件对象。

VB中常用的对象是控件。

此外,VB还提供了系统对象。

窗体是个特例,它既是类也是对象。

当向一个工程添加一个新窗体时,实质就由窗体类创建了一个窗体对象。

对象的三要素:属性、事件和方法。

属性:存放对象的数据(决定对象外观及功能)对象属性的设置方法:在设计阶段,利用属性窗口直接设置属性值;程序运行时,通过语句[对象名.]属性名=属性值。

若属性只能在设计阶段设置,在程序运行阶段不可改变,称为只读属性。

事件:发生在对象上的事情。

同一事件,对不同的对象,会引发不同的反应。

事件过程:应用程序处理事件的步骤。

应用程序设计的主要工作就是为对象编写事件过程的代码。

方法:面向对象的程序设计语言,为程序设计人员提供了一种特殊的过程和函数。

方法是面向对象的,调用时一定要指明对象。

2.窗体和控件具有的基本属性“(1) Name属性:名称所创建的对象名称,在程序中引用。

(2) Caption属性:标题该属性决定了对象上显示的内容。

(3) Height、Width、Top和Left属性决定对象的大小和位置。

(4) Enabled 属性:对象是否允许操作(5) Visible 属性:对象是否可见(6) Font 属性组:文本的外观FontName字体、FontSize大小FontBold粗体、FontItalic斜体FontStrikethru 删除线FontUnderline 下划线(7) ForeColor属性:前景颜色(8) BackColor属性:背景颜色(9) MousePointer属性:鼠标指针类型, 设置值范围0~15,由系统指定。

中职VB程序设计(第5版)学习指导与练习参考答案

中职VB程序设计(第5版)学习指导与练习参考答案

附录A 习题参考答案第1章Visual Basic概述一、选择题二、填空题1.可视化2.对象,事件驱动3.立即4.学习版,专业版,企业版5.文件,退出6.Alt+Q7.文件,新建工程,Ctrl+N8.视图,工具箱9.外观10.“查看对象”,“查看代码”三、简述题(略)第2章Visual Basic程序设计概述一、选择题36D37C38B39B40D 41B42D43C44D45A 46D47D48A49D50C二、填空题1.类,对象2.类或控件类3.属性,方法,事件4.属性,方法,事件5.属性名,属性值6.设计,运行7.窗体,文本框,命令按钮8.Click事件,DbClick事件,Load事件,多,由事件来驱动应用程序执行一段Visual Basic代码,cmd1,Click9.属性, 代码,对象名.属性名=属性值, FF. BackColor=vbRed,C1.Caption="显示"10.Form1.Show , Picture1. Cls11.Top,Left,Width,Height,方法,事件12.vbp,frm13.Click14.Label1.Caption="Hello!"15.AutoSize,True16.StartUpPosition17.“工具”,“选项”,“选项”,“自动语法检测”18.Form,C1,T1,事件19.“退出(&X)”,Alt+X20.Style三、编程题(略)第3章常量与变量一、选择题1B2C3C4C5A 6B7D8C9A10C 11D12D13C14D15B 16C17A18D19C20B 21B22A23B24A25B 26A,D27D28C29D30D二、填空题1.字符2.定长字符串,变长字符串3.双精度4.2,4,4,85.定点,浮点6.单精度浮点数,双精度浮点数7.True,False8.#,"9.直接常量,符号常量10.Const11.字母,数字,下画线,25512.%,&,!,#,$13.Dim x%,y %14.Variant15.双精度三、简述题1~3 (略)4.合法的直接常量:100.0(单精),1E1(单精),123D3(双精),0100(整型),"ASDF"(字符),"1234.5"(字符),#2017/10/7#(日期),100#(双精),True(布尔),-1123!(单精),345.54#(双精)5.变量:Name,ff,cj,n常量:"name"(字符),False(布尔),"11/16/99"(字符),"120"(字符),#11/12/2017#(日期),12.345(单精)6.合法变量名:A123,a12_3,XYZ7.(1)4字节,0.01(2)4字节,7600(3)8字节,-1.23×10-32(4)8字节,123456789.54321(5)4字节,-29(6)8字节,3000第4章函数与表达式一、选择题1A2D3D4B5B 6B7A8B9C10B 11A12A13B14D15D 16B17D18D19C20B 21C22B23A24A25C 26C27A28C29B30C二、填空题1.空格+“_”2.:3.34.-15.-96.67.“visual basic”8.319.110.511.“1234”12.-5713.214.“CDEF”15.1234.5616.True17.Y Mod 4=0 And Y Mod 100<>0 Or Y Mod 400=018.X<100 And X>=019.a< > 0 And b*b-4*a*c>=020.X Mod 5=0 And X Mod 2=0三、写出下列函数的值1.10.562.23.44.-15.-146.-157.0.58.19."exercise"10."erci"11."Exerci"12.23.5513."-543.89"14.1315.7四、把下列数学表达式改写为Visual Basic表达式1.(x^3+y^3+z^3)/Sqr(x+y+z)2.a^2+3*a*b+b^23.Sqr(abs(x*y-z^3))4.((x+12)/(2*y-x))^25.1/3*3.14*h*r^36.((x-1)^2+(x+1)^2)/(2*x^2+1)7.(x+y+z)/(x^3+y^3+z^3)8.2*x^2+3*y^3+(x-y)^3/(x+y)^29.(a-b)*(a+2*b-5*(3*c+2))10.2*sin((x+y)/2)*cos((x-y)/2)五、写出下列表达式的值1.-22.1103.44."xyz456"5."579789"6.07.18.19.False10.(1)False(2)True六、用关系表达式或布尔表达式表示下列条件1.i Mod j=02.1<=x And x<103.n<k And n Mod 2=04.x<z Or y<z5.a+b>c And b+c>a And c+a>b第5章顺序结构程序设计一、选择题1C2C3A4D5B 6 A 7 D 8A9C10C 11A12D13D14A15A,B 16B17C18D19C20D 21B22B23A24B25C 26A27D28D29D30A二、填空题1.Let2.计算3.txtshow.Text="GOOD WORK !"4.Text1.Text=" Visual Basic 你好!",5.Rem,’6.End7.字符型8."12345"9.计算,输出10.窗体,图片框,打印机11.结果数值,原样输出12.(逗号),(分号)13.27 -914.2 115.Tab,Spc16.500.00%17.123.4618.919.ABCD,Visual Basic Programming20.-100 200 -300-100 200 -30021.x=3y=3x=4y=322.5 4a=5 b=423.1 23 524.1 23 58 1325.s=3.14*r*r26.n=Val(InputBox("请输入一个求阶乘的数:","求数的阶乘"))27.n=MsgBox("退出本系统?", 4+32,"提示信息")28.n=MsgBox("文件未找到!", 0+48,"文件查找")29.Val(InputBox("请输入b")),a,b,c30.9,18,37,56,7三、编程题(略)第6章选择结构程序设计一、选择题1C2B3D4C5D 6 A 7 B 8B9A10C 11B12B13C14B15B 16C17C18A19B20C二、填空题1.关系表达式,布尔表达式,True,False2.if…Then…Else,if…Then…Elseif,Select…Case3.一4.If x>0 Then s1=s1+x Else s2=s2+x5.806.True7.bcdcde8.19.210.311.812.你应该缴纳599.8元税金13.numx Mod 2=0 And numx Mod 5=0 And numx Mod 7=0,numx,,numx^2。

VB语言程序设计课后编程和上机调试参考答案

VB语言程序设计课后编程和上机调试参考答案

VB语言程序设计课后编程及上机调试参考答案ex0101Private Sub Label1_Click()Caption = "练习"Command1.Caption = "确定"Label1.FontBold = TrueLabel1.AutoSize = TrueLabel1.Caption = "Visual Basic程序设计教程"End Subex0102Private Sub Command1_Click()Txt.Text = "我有电脑"End SubPrivate Sub Command2_Click()Txt.Text = "我没有电脑"End SubPrivate Sub Command3_Click()Txt.Text = "" '一对双撇号,中间不留空End Subex0104Private Sub Command1_Click()Dim x As Singlex = Val(Text1.Text)Text2.Text = 15 * xEnd Subex0202Private Sub Form_Click()Dim r As Single, s As Singler = 4.6s = 3.14159 * r ^ 2Text1.Text = "圆的面积为" & sEnd Subex0204Private Sub Command1_Click() '"最大化"按钮Form1.WindowState = 2 '最大化End SubPrivate Sub Command2_Click() '"还原"按钮Form1.WindowState = 0 '还原Private Sub Command3_Click() '"最小化"按钮Form1.WindowState = 1 '最小化End Subex0205Private Sub command1_click()Dim x As SingleDim y As Singlex = Val(Text1.Text)y = Val(Text2.Text)Text3.Text = x * x + y * yEnd Subex0206Private Sub command1_click()Dim x As Stringx = Text1.TextText2.Text = Left(x, 1) + Right(x, 1)End Subex0301Private Sub Form_Load()Dim x As Integer, y As IntegerDim a As Integer, b As Integer, c As Integerx = Val(InputBox("请输入一个三位数"))a = Int(x / 100) '求百位数b = Int(x / 10) - a * 10 '求十位数c = x Mod 10 '求个位数 Showy = c * 100 + b * 10 + a '生成倒序数 Print x; "倒序数为:"; y '显示倒序数End Subex0302Private Sub Command1_Click()n = Val(Text1.Text)Randomizex = Int(1 + n * Rnd)Label1.Caption = "第一个随机数" + Str(x)x = Int(1 + n * Rnd)Label2.Caption = "第二个随机数" + Str(x)x = Int(1 + n * Rnd)Label3.Caption = "第三个随机数" + Str(x)ex0303Private Sub Cmd1_Click()Lab1.Visible = TrueLab1.Caption = "您已下达显示命令"End SubPrivate Sub Form_Click()Cmd1.Visible = TrueEnd Subex0304Private Sub Form_KeyPress(KeyAscii As Integer)ShowPrint "输入字符:"; Chr(KeyAscii), "ASCII码为;"; KeyAsciiEnd SubPrivate Sub Form_DblClick()ClsEnd Subex0305Private Sub Form_Load()x = MsgBox("在这里显示提示信息", 4 + 0, "请确认")x = MsgBox("在这里显示" + Chr(13) + "提示信息", 3 + 0, "请确认")x = MsgBox("在这里显示" + Chr(13) + "提示信息", 2 + 16 + 0, "请确认") End Subex0401Private Sub Form_Load()Dim x As Long, s As Stringx = InputBox("输入一个整数(1~35000)")s = "奇数"If x Mod 2 = 0 Then s = "偶数"MsgBox sEnd Subex0402Private Sub Command1_Click()Dim a As Single, b As SingleDim c As Single, d As SingleDim m As Single, n As Single, x As SingleShowa = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)d = Val(Text4.Text)If a > b Then '求a、b中的较大数m = aElsem = bEnd IfIf c > d Then '求c、d中的较大数n = cElsen = dEnd IfIf m > n Then '求m、n中的较大数x = mElsex = nEnd IfText5.Text = xEnd Subex0403Private Sub Command1_Click()Dim t As String, p As Stringt = Mid(Text1.Text, 5, 1)Select Case tCase "2"p = "博士生"Case "3"p = "硕士生"Case "4"p = "本科生"Case "5"p = "专科生"Case Elsep = "无效学号"End SelectText2.Text = Left(Text1.Text, 2) + "级" Text3.Text = pEnd Subex0404Private Sub Command1_Click()r = 0: g = 0: b = 0If Check1.Value = 1 Thenr = 255End IfIf Check2.Value = 1 Theng = 255End IfIf Check3.Value = 1 Thenb = 255End IfLabel1.BackColor = RGB(r, g, b)End SubPrivate Sub Command2_Click()EndEnd Subex0405Private Sub Form_Load()LabClk.Caption = "0"LabClk.Alignment = 1LabClk.BorderStyle = 1LabClk.FontSize = 22LabClk.FontName = "黑体"TimClk.Interval = 1000End SubPrivate Sub TimClk_Timer()LabClk.Caption = Val(LabClk.Caption) + 1End Subex0406Private Sub Form_Load()Command1.Enabled = FalseCommand2.Enabled = FalseEnd SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Text1.SelLength > 0 ThenCommand1.Enabled = TrueEnd IfEnd SubPrivate Sub Command1_Click()Command1.Enabled = TrueCommand2.Enabled = TrueEnd SubPrivate Sub Command2_Click()Text2.Text = Text1.SelTextCommand1.Enabled = FalseCommand2.Enabled = FalseEnd Subex0501Private Sub Form_Load()Dim k As Integer, s As Integer, t As Integer s = 0For k = 1 To 100 Step 2s = s + kNext kShowPrint "1~100范围内的奇数和:"; sEnd Subex0502Private Sub Form_Load()Dim s As SingleShows = 0For k = 1 To 200s = s + k / (1 + k * k)Next kPrint Int(s * 10 + 0.5) / 10End Subex0503Private Sub Form_Load()Showk = 2s = 0Do While k < 101s = s + k * (k - 1)k = k + 2LoopPrint sEnd Subex0504Private Sub Form_Load()Dim k As Integer, a As Integer, b As Integer Dim c As Integer, n As IntegerShown = 0Print "三位数的水仙花数是:"For k = 100 To 999a = Int(k / 100)b = Int((k - 100 * a) / 10)c = k Mod 10If a * a * a + b * b * b + c * c * c = k Then Print kn = n + 1End IfNext kPrint "一共有" & n & "个水仙花数"End Subex0505Private Sub Form_Load()ShowFor k = 1000 To 9999If k Mod 78 = 0 Thena = Int(k / 1000)b = Int(k / 100) - 10 * ac = Int(k / 10) - 100 * a - 10 * bd = k Mod 10If a = b And c = d ThenPrint kEnd IfEnd IfNext kEnd Subex0506Private Sub Command1_Click()Dim s As String, y As StringDim x As String, t As Strings = Text1.Text: y = ""For k = 1 To Len(s)x = Mid(s, k, 1)t = UCase(x)If t >= "A" And t <= "Z" Theny = y + xEnd IfNext kText2.Text = yEnd Subex0507Private Sub Command1_click() '"显示"按钮单击事件FontSize = 12ClsFor i = 0 To List1.ListCount - 1 '逐项判断If List1.Selected(i) Then '真时为选定Print List1.List(i)End IfNext iEnd Subex0508Private Sub Form_Load()ShowFor a = 1 To 9For b = 1 To 9For c = 1 To 9For d = 1 To 9x = a * 1000 + b * 100 + c * 10 + dy = b * 1000 + a * 100 + a * 10 + cz = d * 100 + d * 10 + aIf x - y = z ThenPrint "A=" & a & ",B=" & b & ",C=" & c & ",D=" & d End IfNext dNext cNext bNext aEnd Subex0601Private Sub Command1_Click()Dim a(10) As Integer, min As Integer, pos As IntegerRandomizeFor i = 1 To 10a(i) = Int(Rnd * 90 + 10)Print a(i);Next iPrintmin = a(1)pos = 1For k = 2 To 10If a(k) < min Thenmin = a(k)pos = kEnd IfNext kPrint "最小数:"; min, "位置:"; posEnd Subex0602Private Sub Form_Load()Dim a As Variant, b As VariantDim c(8) As Integera = Array(3, 4, 2, 1, 5, 7, 8, 11, 13)b = Array(10, 6, 12, 9, 13, 8, 8, 1, 16)For k = 0 To 8c(k) = a(k) + b(k)Next kShowFor k = 0 To 8Print c(k)Next kEnd Subex0603Private Sub Form_Load()Dim d() As IntegerDim k As Integer, t As Integer, m As Integer Dim h As Integer, n As Integern = Val(InputBox("请输入数组个数n:"))ReDim d(n)ShowPrint "处理前数据 :"RandomizeFor k = 1 To nd(k) = Int((101 * Rnd - 50))Print d(k);Next kPrintm = Int(n / 2)For k = 1 To mh = n - k + 1t = d(h): d(h) = d(k): d(k) = tNext kPrint "处理的结果 :"For k = 1 To nPrint d(k);Next kEnd Subex0604Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim s As Long, i As Integer, j As IntegerShowRandomizen = 8For i = 1 To nFor j = 1 To nx = Int(90 * Rnd + 10) '产生一个随机数 a(i, j) = xNext jNext is = 0For i = 1 To nFor j = 1 To ns = s + a(i, j)Next jNext iPrint "所有元素之和;"; sPrintFor i = 1 To ns = 0For j = 1 To ns = s + a(i, j)Next jPrint "第"; i; "行元素之和;"; sNext iPrints = 0For i = 1 To ns = s + a(i, i)Next iPrint "主对角线元素之和;"; sPrints = 0For i = 1 To nFor j = 1 To nIf i = 1 Or i = n Or j = 1 Or j = n Thens = s + a(i, j)End IfNext jNext iPrint "所有靠边元素之和;"; sEnd Subex0605Option Base 1Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim max As Integer, r As Integer, c As IntegerShowRandomizen = 8For i = 1 To nFor j = 1 To nx = Int(900 * Rnd + 100) '产生一个随机数 a(i, j) = xPrint x;Next jPrintNext imax = 0: r = 1: c = 1PrintFor i = 1 To nFor j = 1 To nIf a(i, j) > max Then '判断有无更大数 max = a(i, j): r = i: c = jEnd IfNext j, iPrint "最大值为:"; maxPrint "位于行:"; r, "列:"; cEnd Subex0606Dim n As IntegerPrivate Sub Cmd1_Click()n = n + 1If n = 3 Then n = 0Opt1(n).Value = TrueEnd SubPrivate Sub Form_Load()End Subex0607Private Sub Form_Load()Dim a(20) As IntegerRandomizea(1) = Int(10 + 90 * Rnd) k = 1Do While k < 20x = Int(10 + 90 * Rnd) f = 0For j = 1 To kIf x = a(j) Then f = 1Exit ForEnd IfNext jIf f = 0 Thenk = k + 1a(k) = xEnd IfLoopShowFor j = 1 To 20Print a(j)Next jEnd Subex0701Private Sub Form_Click()Dim s As Longs = 0For k = 1 To 10s = s + jc(k)Next kPrint sEnd SubFunction jc(n) As LongDim t As Longt = 1For k = 1 To nt = t * kNext kEnd Functionex0702Private Sub Form_Load()Dim a As Single, b As Single, c As SingleDim d As Single, m As Single, n As SingleShowa = Val(InputBox("输入第1个数"))b = Val(InputBox("输入第2个数"))c = Val(InputBox("输入第3个数"))d = Val(InputBox("输入第4个数"))m = max(a, b) '求a、b中的较大数 n = max(c, d) '求c、d中的较大数 Print "最大数为:" & max(m, n) '求m、n中的较大数End SubFunction max(x, y) As SingleIf x > y Thenmax = xElsemax = yEnd IfEnd Functionex0703Private Sub Command1_Click()Dim d(5) As Single, m As SingleFor k = 0 To 5d(k) = Val(Text1(k).Text)Next kCall Max(d(0), d(1), d(2), m)Call Max(m, d(3), d(4), m)Call Max(m, m, d(5), m)Text2.Text = mEnd Subex0704Private Sub Form_Load()Dim x As LongShowx = Val(InputBox("输入一个数"))Print x; "的位数为:"; fnws(x)End SubFunction fnws(x As Long) As IntegerDim n As Integern = 1Do While x \ 10 > 0n = n + 1x = x \ 10Loopfnws = nEnd Functionex0705Private Sub C1_Click()Form1.HideEnd Subex0705APrivate Sub C2_Click()Form1.ShowEnd Subex0706Dim n As IntegerPrivate Sub Command1_Click()usern = Trim(Text1.Text)passw = Trim(Text2.Text)If usern = "username" And passw = "password" Then Form1.HideForm2.ShowElsen = n + 1Text1.SetFocusIf n = 3 ThenForm1.HideForm3.ShowEnd IfEnd IfText1.Text = ""Text2.Text = ""End Subex0706APrivate Sub Command1_Click()Form2.HideForm1.ShowEnd Subex0906BPrivate Sub Command1_Click()Unload Form1Unload Form2Unload Form3EndEnd Subex0802Private Sub Form_Load()Dim i As Integer, j As IntegerShowFor i = 1 To 12Print String(20 - i, 32); '输出当前行左边的空格,分号表示下一输出项紧接输出 For j = 1 To 2 * i - 1 '输出2*i-1个字符If j <= i Then '按左、右两边指定输出字符k = j '左边输出的字符Elsek = 2 * i - j '右边输出的字符End IfIf k > 9 Then k = k + 7 '字母的ASCII码比数字大7Print Chr(k + 48); '以字符格式输出Next jPrint '换行Next iEnd Subex0803Dim t As Single, f As IntegerPrivate Sub Command1_Click() '“产生原稿文”按钮Randomizes = ""For k = 1 To 30x = Chr(Int(Rnd * 26) + 97) '随机产生小写字母s = s + xNext kText1.Text = s '显示在文本框中Text2.Text = ""Text2.Locked = False '允许录入Text2.SetFocus '设置焦点Text3.Text = ""Text4.Text = ""f = 0 '第1次按键标记,0表示未按键End SubPrivate Sub Command2_Click() '“结束”按钮EndEnd SubPrivate Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)Dim c As Integer, k As IntegerIf f = 0 Then '第1次按键时,开始计时t = Timer '用t保存第1次按键的时间 f = 1 '1表示已按键和进入录入过程 End IfIf Len(Text2.Text) < 30 ThenText3.Text = Round(Timer - t, 1) & "秒" '显示用户当前所用时间Elsec = 0For k = 1 To 30 '统计录入正确的字母个数If Mid(Text1.Text, k, 1) = Mid(Text2.Text, k, 1) Thenc = c + 1End IfNext kText2.Locked = True '禁止录入Text4.Text = Round(c / 30 * 100, 2) & "%" '显示准确率End IfEnd Subex0901Private Sub Command1_Click()Open "静夜思.txt" For Input As #1Do While Not EOF(1) '文件未结束时,循环Input #1, xList1.AddItem xLoopClose #1End Subex0902Dim d(1 To 20) As IntegerPrivate Sub Command1_Click() '"产生随机数"For i = 1 To 20d(i) = Int(1 + 99 * Rnd)List1.AddItem d(i)Next iEnd SubPrivate Sub Command2_Click() '"保存"Open "MyFile4.txt" For Output As #1For i = 1 To 20Write #1, d(i)Next iClose #1End SubPrivate Sub Command3_Click() '"读出"Open "MyFile4.txt" For Input As #1Do While Not EOF(1)Input #1, xList2.AddItem xLoopClose #1End SubPrivate Sub Command4_Click() '"结束"EndEnd Subex0903Private Sub Form_Load()ShowFor k = 1 To 6fn = "..\第7章\ex070" & k & ".vbp"If Dir(fn) = "" ThenPrint Mid(fn, 4) & "未编写!!"ElsePrint Mid(fn, 4) & "已编写!!"End IfNext kEnd Subex0904Private Sub Form_Load()chedir = "C:\Documents and Settings\Lin\My Documents\fsodir" If Dir(chedir, 16) = "" ThenMkDir chedirEnd Ifchefile = "C:\Windows\notepad.exe"If Dir(chefile) <> "" ThenFileCopy chefile, chedir & "\mynotepad.exe"End IfMsgBox "操作完毕!"End Subex1002Private Sub A1_Click()Label1.ForeColor = vbRedEnd SubPrivate Sub A2_Click()Label1.ForeColor = vbBlueEnd SubPrivate Sub A3_Click()Label1.ForeColor = vbGreenEnd SubPrivate Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 ThenPopupMenu mun0End IfEnd Subex1003Private Sub Command1_Click()CommonDialog1.DialogTitle = "选择文件"CommonDialog1.Filter = "文本文件|*.txt"CommonDialog1.InitDir = "C:\"CommonDialog1.ShowOpenText1.Text = CommonDialog1.FileNameEnd SubPrivate Sub Command2_Click()Unload MeEndEnd Subex1101Private Sub calzc(x As Integer)Text2.Text = Round(2 * 3.14159 * x, 2)End SubPrivate Sub HV_Scroll()Dim r As Integerr = HV.ValueText1.Text = "=" & rCall calzc(r)End SubPrivate Sub Form_Load()HV.Max = 300End Subex1102Private Sub Form_Load()For k = 0 To 3Image1(k).Stretch = TrueImage1(k).Picture = LoadPicture("箭头" & k + 1 & ".bmp") Next kEnd SubPrivate Sub Image1_Click(Index As Integer)Picture1.Font.Size = 20Picture1.ClsSelect Case IndexCase 0Picture1.Print "箭头向上"Case 1Picture1.Print "箭头向左"Case 2Picture1.Print "箭头向右"Case 3Picture1.Print "箭头向下"End SelectEnd Sub。

VB程序设计学习与实验指导答案-推荐下载

VB程序设计学习与实验指导答案-推荐下载

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

VB程序设计指导实验指导与习题解答上机答案

VB程序设计指导实验指导与习题解答上机答案

自测1程序代码Private Sub Command1_Click() Label1.FontSize = Label1.FontSize + 3End SubPrivate Sub Command2_Click() Label1.FontBold = TrueEnd SubPrivate Sub Command3_Click() Label1.FontUnderline = TrueEnd SubPrivate Sub Command4_Click() Label1.FontSize = 10Label1.FontBold = FalseLabel1.FontUnderline = FalseEnd Sub初始窗口:单机放大之后窗口:单机下划线之后窗口:单击加粗之后窗口:单击还原之后窗口:自测2程序代码Private Sub Command1_Click() Label1 = "visual basic"Text1 = "程序设计题"End SubPrivate Sub Command2_Click() Text1 = "visual basic"Label1 = "程序设计题"End Sub初始窗口:单击显示之后窗口:单击交换之后的窗口:自测题3Private Sub Command1_Click()Label1.FontSize = Label1.FontSize * (0.5) End SubPrivate Sub Command2_Click()Label1.Top = Label1.Top + 30Label1.Width = Label1.Width + 20Label1.Alignment = 1End Sub初始窗口:单击缩小两倍之后的窗口:单击向右下角移动之后的窗口:自测题4程序代码Private Sub Command1_Click() Form1.Caption = "VB学习" Print "简单的VB程序设计"End SubPrivate Sub Command2_Click() ClsEnd SubPrivate Sub Command3_Click() EndEnd SubPrivate Sub Command3_Click() EndEnd Sub初始化窗口:单击显示之后的窗口:单击清除之后的窗口:单击退出之后的窗口:自测题5程序代码Private Sub Command1_Click()Text1.Text = ""Text2.Text = ""End SubPrivate Sub Command2_Click()Text3.Text = Val(Text1.Text) + Val(Text2.Text) End SubPrivate Sub Command3_Click()EndEnd Sub初始化窗口:单击运算之后窗口:单击清除之后的窗口:单击退出之后的窗口:自测练习1Private Sub Command1_Click() Dim a$a = Text1.TextLabel1.Caption = Left(a, 2) End SubPrivate Sub Command2_Click() a = Text1.TextLabel2.Caption = Right(a, 2) End SubPrivate Sub Command3_Click()Text1.Text = Label1.Caption & Label2.Caption End Sub初始窗口界面输入字符串截取前两个字符截取后两个字符字符串连接自测练习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 + iText1.Visible = FalsePrint "加密前的4位整数是7439"; (Chr(10)); "加密后的结果是"; lEnd Sub初始界面单击窗体运行后的界面自测练习1Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox("输入第一个数", "输入一个数", 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自测练习2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox("输入第一个数的值"))b = Val(InputBox("输入第二个数的值"))c = Val(InputBox("输入第三个数的值"))d = Val(InputBox("输入第四个数的值"))e = a + b + c + df = e / 4Print "和="; e Print "平均值="; f End Sub自测练习3Private Sub Form_Click()Dim h%, f%, x%, y%h = Val(InputBox("输入总头数")) 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(InputBox("请输入第一条边", "边长"))b = Val(InputBox("请输入第二条边", "边长"))c = Val(InputBox("请输入第三条边", "边长"))If a + b > c And a + c > b And b + c > a ThenIf a * a + b * b = c * c Or a * a + c * c = b * b Or b * b = c * c = a * a ThenPrint "直角"ElseIf a = b And b = c ThenPrint "等边三角形"ElseIf a = b Or a = c Or b = c ThenPrint "等腰三角形"ElsePrint "一般三角形"End IfElsePrint "不是三角形"End IfEnd Sub不是三角形运行结果:初始窗口:输入三条边:运行结果:直角三角形运行结果:等边三角形运行结果如下:等腰三角形:一般三角形自测练习2:Private Sub Form_Click()Dim a%, b!a = Val(InputBox("请输入"))If a Mod 2 = 0 And a Mod 3 = 0 And a Mod 5 = 0 Then b = Sqr(a)Print a, bElseEndEnd IfEnd Sub初始化窗口:输入一个数:运行结果:自测练习3Private Sub Command1_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 Elseb = 0.2 * 100 + (a - 100) * 0.5: MsgBox "行李费为" & b & "元", , "行李费"End SelectEnd Sub初始窗口:输入10:输入25:输入55:输入120:自测练习1Option Base 1Private Sub Form_Click()Dim i%, a(1 To 20) As Integera(1) = 1: a(2) = 1Print a(1);Print a(2);For i = 3 To 10a(i) = a(i - 1) + a(i - 2) Print a(i);Next iPrintFor i = 11 To 16a(i) = a(i - 1) + a(i - 2) Print a(i);Next iPrintFor i = 17 To 20a(i) = a(i - 1) + a(i - 2) Print a(i);Next i初始界面:运行结果界面:自测练习2Option Base 1Private Sub Form_Load() Form1.Width = 10000 Form1.Height = 5000 End SubPrivate Sub Command1_Click()Dim i%, j%, t%, a(1 To 4, 1 To 4) As Integer For i = 1 To 4For j = 1 To 4a(i, j) = Int(Rnd * 10) + 1Picture1.Print a(i, j);Next jPicture1.PrintNext iPicture3.Print "对角线的元素如下"For i = 1 To 4Picture3.Print a(i, i);Next iPicture3.PrintFor i = 1 To 4Picture3.Print 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 4For j = 1 To 4Picture2.Print a(i, j); Next jPicture2.PrintNext iEnd Sub运行初始界面:运运行结果界面:自测练习1Sub itostr(a As Integer) Dim b%, c$a = Val(Text1.Text)While a >= 1c = Chr(a Mod 10 + 48) & ca = a \ 10WendText2.Text = c End SubPrivate Sub Command1_Click()Dim a As Integera = Val(Text1.Text)Call itostr(a)End Sub运行初始界面:运行结果界面:验证其他数字:自测练习2:Public Function 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 + (Sin(d) + Sin(e)) * c / 2 I = I + 1Wendarea = sEnd FunctionPrivate Sub Command1_Click() Dim s As DoubleCall area(n)Text1.Text = area(n)End Sub运行初始界面:运行结果:自测练习3Private Sub Form_click()n = Val(InputBox("请输入n的值"))x = Val(InputBox("请输入x的值"))Print "e的值="; es(n, x)End SubPrivate Function es(n, x)Dim a As Double, b As Double, c As Double, i As Integer a = 1: b = 1: c = 1For i = 1 To na = x * a:b = b * i:c = c + a / bNext ies = cEnd Function运行初始界面:输入数据:运行结果:自测练习4:For i = 1 To 4For j = i + 1 To 5If a(i) > a(j) Thent = a(i): a(i) = a(j): a(j) = tEnd IfNext jNext iFor i = 1 To 5Print a(i); " ";Next iFor i = 1 To 5If Y < a(i) Thent = a(i): a(i) = Y: Y = tEnd IfNext iFor i = 1 To 6a(6) = tNext iEnd FunctionPrivate Sub Command1_Click()Dim i#, a%(1 To 6), Y%Y = Val(InputBox("输入y的值", "输入数据")) Insertfun a%(), YPrintFor i = 1 To 6Print a(i); " "; Next iEnd Sub运行初始界面:插入数据:运行结果:41011060蓝志鹏资源1102 实验8自测练习1:Private Sub Command1_Click()If Ch1.Value = 1 ThenText1.Text = "报名参加羽毛球比赛"End IfIf Ch2.Value = 1 ThenText1.Text = "报名参加乒乓球比赛"End IfIf Ch1.Value = 1 And Ch2.Value = 1 Then Text1.Text = "报名参加羽毛球,乒乓球比赛" End IfEnd Sub运行初始界面:运行结果:自测练习4:Private Sub Form_Load() Label1.Alignment = 2 Label1.FontSize = 24 Label1.FontName = "黑体" Label1.ForeColor = &HFF&End SubPrivate Sub Option1_Click() Label1.Caption = "我是学生" End SubPrivate Sub Option2_Click() Label1.Caption = "我是教师" End SubPrivate Sub Option3_Click() Label1.Caption = "我是工人" End SubPrivate Sub Option4_Click() Label1.Caption = "我是农民" End Sub运行初始界面:运行结果:。

VB语言程序设计课后编程及上机调试参考答案

VB语言程序设计课后编程及上机调试参考答案

V B语言程序设计课后编程及上机调试参考答案ex0101Private Sub Label1_Click()Caption = "练习"= "确定"= True= True= "Visual Basic程序设计教程"End Subex0102Private Sub Command1_Click()= "我有电脑"End SubPrivate Sub Command2_Click()= "我没有电脑"End SubPrivate Sub Command3_Click()= "" '一对双撇号,中间不留空End Subex0104Private Sub Command1_Click()Dim x As Singlex = Val= 15 * xEnd Subex0202Private Sub Form_Click()Dim r As Single, s As Singler =s = * r ^ 2= "圆的面积为" & sEnd Subex0204Private Sub Command1_Click() '"最大化"按钮= 2 '最大化End SubPrivate Sub Command2_Click() '"还原"按钮= 0 '还原Private Sub Command3_Click() '"最小化"按钮= 1 '最小化End Subex0205Private Sub command1_click()Dim x As SingleDim y As Singlex = Valy = Val= x * x + y * yEnd Subex0206Private Sub command1_click()Dim x As Stringx == Left(x, 1) + Right(x, 1)End Subex0301Private Sub Form_Load()Dim x As Integer, y As IntegerDim a As Integer, b As Integer, c As Integerx = Val(InputBox("请输入一个三位数"))a = Int(x / 100) '求百位数b = Int(x / 10) - a * 10 '求十位数c = x Mod 10 '求个位数 Showy = c * 100 + b * 10 + a '生成倒序数 Print x; "倒序数为:"; y '显示倒序数End Subex0302Private Sub Command1_Click()n = ValRandomizex = Int(1 + n * Rnd)= "第一个随机数" + Str(x)x = Int(1 + n * Rnd)= "第二个随机数" + Str(x)x = Int(1 + n * Rnd)= "第三个随机数" + Str(x)ex0303Private Sub Cmd1_Click()= True= "您已下达显示命令"End SubPrivate Sub Form_Click()= TrueEnd Subex0304Private Sub Form_KeyPress(KeyAscii As Integer)ShowPrint "输入字符:"; Chr(KeyAscii), "ASCII码为;"; KeyAsciiEnd SubPrivate Sub Form_DblClick()ClsEnd Subex0305Private Sub Form_Load()x = MsgBox("在这里显示提示信息", 4 + 0, "请确认")x = MsgBox("在这里显示" + Chr(13) + "提示信息", 3 + 0, "请确认")x = MsgBox("在这里显示" + Chr(13) + "提示信息", 2 + 16 + 0, "请确认") End Subex0401Private Sub Form_Load()Dim x As Long, s As Stringx = InputBox("输入一个整数(1~35000)")s = "奇数"If x Mod 2 = 0 Then s = "偶数"MsgBox sEnd Subex0402Private Sub Command1_Click()Dim a As Single, b As SingleDim c As Single, d As SingleDim m As Single, n As Single, x As SingleShowa = Valb = Valc = Vald = ValIf a > b Then '求a、b中的较大数 m = aElsem = bEnd IfIf c > d Then '求c、d中的较大数 n = cElsen = dEnd IfIf m > n Then '求m、n中的较大数 x = mElsex = nEnd If= xEnd Subex0403Private Sub Command1_Click()Dim t As String, p As Stringt = Mid, 5, 1)Select Case tCase "2"p = "博士生"Case "3"p = "硕士生"Case "4"p = "本科生"Case "5"p = "专科生"Case Elsep = "无效学号"End Select= Left, 2) + "级"= pEnd Subex0404Private Sub Command1_Click()r = 0: g = 0: b = 0If = 1 Thenr = 255End IfIf = 1 Theng = 255End IfIf = 1 Thenb = 255End If= RGB(r, g, b)End SubPrivate Sub Command2_Click()EndEnd Subex0405Private Sub Form_Load()= "0"= 1= 1= 22= "黑体"= 1000End SubPrivate Sub TimClk_Timer()= Val + 1End Subex0406Private Sub Form_Load()= False= FalseEnd SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If > 0 Then= TrueEnd IfEnd SubPrivate Sub Command1_Click()= True= TrueEnd SubPrivate Sub Command2_Click()== False= FalseEnd Subex0501Private Sub Form_Load()Dim k As Integer, s As Integer, t As Integer s = 0For k = 1 To 100 Step 2s = s + kNext kShowPrint "1~100范围内的奇数和:"; sEnd Subex0502Private Sub Form_Load()Dim s As SingleShows = 0For k = 1 To 200s = s + k / (1 + k * k)Next kPrint Int(s * 10 + / 10End Subex0503Private Sub Form_Load()Showk = 2s = 0Do While k < 101s = s + k * (k - 1)k = k + 2LoopPrint sEnd Subex0504Private Sub Form_Load()Dim k As Integer, a As Integer, b As Integer Dim c As Integer, n As IntegerShown = 0Print "三位数的水仙花数是:"For k = 100 To 999a = Int(k / 100)b = Int((k - 100 * a) / 10)c = k Mod 10If a * a * a + b * b * b + c * c * c = k Then Print kn = n + 1End IfNext kPrint "一共有" & n & "个水仙花数"End Subex0505Private Sub Form_Load()ShowFor k = 1000 To 9999If k Mod 78 = 0 Thena = Int(k / 1000)b = Int(k / 100) - 10 * ac = Int(k / 10) - 100 * a - 10 * bd = k Mod 10If a = b And c = d ThenPrint kEnd IfEnd IfNext kEnd Subex0506Private Sub Command1_Click()Dim s As String, y As StringDim x As String, t As Strings = : y = ""For k = 1 To Len(s)x = Mid(s, k, 1)t = UCase(x)If t >= "A" And t <= "Z" Theny = y + xEnd IfNext k= yEnd Subex0507Private Sub Command1_click() '"显示"按钮单击事件FontSize = 12ClsFor i = 0 To - 1 '逐项判断If (i) Then '真时为选定Print (i)End IfNext iEnd Subex0508Private Sub Form_Load()ShowFor a = 1 To 9For b = 1 To 9For c = 1 To 9For d = 1 To 9x = a * 1000 + b * 100 + c * 10 + dy = b * 1000 + a * 100 + a * 10 + cz = d * 100 + d * 10 + aIf x - y = z ThenPrint "A=" & a & ",B=" & b & ",C=" & c & ",D=" & d End IfNext dNext cNext bNext aEnd Subex0601Private Sub Command1_Click()Dim a(10) As Integer, min As Integer, pos As IntegerRandomizeFor i = 1 To 10a(i) = Int(Rnd * 90 + 10)Print a(i);Next iPrintmin = a(1)pos = 1For k = 2 To 10If a(k) < min Thenmin = a(k)pos = kEnd IfNext kPrint "最小数:"; min, "位置:"; posEnd Subex0602Private Sub Form_Load()Dim a As Variant, b As VariantDim c(8) As Integera = Array(3, 4, 2, 1, 5, 7, 8, 11, 13)b = Array(10, 6, 12, 9, 13, 8, 8, 1, 16)For k = 0 To 8c(k) = a(k) + b(k)Next kShowFor k = 0 To 8Print c(k)Next kEnd Subex0603Private Sub Form_Load()Dim d() As IntegerDim k As Integer, t As Integer, m As Integer Dim h As Integer, n As Integern = Val(InputBox("请输入数组个数n:"))ReDim d(n)ShowPrint "处理前数据 :"RandomizeFor k = 1 To nd(k) = Int((101 * Rnd - 50))Print d(k);Next kPrintm = Int(n / 2)For k = 1 To mh = n - k + 1t = d(h): d(h) = d(k): d(k) = tNext kPrint "处理的结果 :"For k = 1 To nPrint d(k);Next kEnd Subex0604Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim s As Long, i As Integer, j As IntegerShowRandomizen = 8For i = 1 To nFor j = 1 To nx = Int(90 * Rnd + 10) '产生一个随机数 a(i, j) = xNext jNext is = 0For i = 1 To nFor j = 1 To ns = s + a(i, j)Next jNext iPrint "所有元素之和;"; sPrintFor i = 1 To ns = 0For j = 1 To ns = s + a(i, j)Next jPrint "第"; i; "行元素之和;"; sNext iPrints = 0For i = 1 To ns = s + a(i, i)Next iPrint "主对角线元素之和;"; sPrints = 0For i = 1 To nFor j = 1 To nIf i = 1 Or i = n Or j = 1 Or j = n Thens = s + a(i, j)End IfNext jNext iPrint "所有靠边元素之和;"; sEnd Subex0605Option Base 1Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim max As Integer, r As Integer, c As IntegerShowRandomizen = 8For i = 1 To nFor j = 1 To nx = Int(900 * Rnd + 100) '产生一个随机数 a(i, j) = xPrint x;Next jPrintNext imax = 0: r = 1: c = 1PrintFor i = 1 To nFor j = 1 To nIf a(i, j) > max Then '判断有无更大数 max = a(i, j): r = i: c = jEnd IfNext j, iPrint "最大值为:"; maxPrint "位于行:"; r, "列:"; cEnd Subex0606Dim n As IntegerPrivate Sub Cmd1_Click()n = n + 1If n = 3 Then n = 0Opt1(n).Value = TrueEnd SubPrivate Sub Form_Load()End Subex0607Private Sub Form_Load()Dim a(20) As IntegerRandomizea(1) = Int(10 + 90 * Rnd) k = 1Do While k < 20x = Int(10 + 90 * Rnd) f = 0For j = 1 To kIf x = a(j) Then f = 1Exit ForEnd IfNext jIf f = 0 Thenk = k + 1a(k) = xEnd IfLoopShowFor j = 1 To 20Print a(j)Next jEnd Subex0701Private Sub Form_Click()Dim s As Longs = 0For k = 1 To 10s = s + jc(k)Next kPrint sEnd SubFunction jc(n) As LongDim t As Longt = 1For k = 1 To nt = t * kNext kEnd Functionex0702Private Sub Form_Load()Dim a As Single, b As Single, c As SingleDim d As Single, m As Single, n As SingleShowa = Val(InputBox("输入第1个数"))b = Val(InputBox("输入第2个数"))c = Val(InputBox("输入第3个数"))d = Val(InputBox("输入第4个数"))m = max(a, b) '求a、b中的较大数 n = max(c, d) '求c、d中的较大数 Print "最大数为:" & max(m, n) '求m、n中的较大数End SubFunction max(x, y) As SingleIf x > y Thenmax = xElsemax = yEnd IfEnd Functionex0703Private Sub Command1_Click()Dim d(5) As Single, m As SingleFor k = 0 To 5d(k) = Val(Text1(k).Text)Next kCall Max(d(0), d(1), d(2), m)Call Max(m, d(3), d(4), m)Call Max(m, m, d(5), m)= mEnd Subex0704Private Sub Form_Load()Dim x As LongShowx = Val(InputBox("输入一个数"))Print x; "的位数为:"; fnws(x)End SubFunction fnws(x As Long) As IntegerDim n As Integern = 1Do While x \ 10 > 0n = n + 1x = x \ 10Loopfnws = nEnd Functionex0705Private Sub C1_Click()End Subex0705APrivate Sub C2_Click()End Subex0706Dim n As IntegerPrivate Sub Command1_Click()usern = Trimpassw = TrimIf usern = "username" And passw = "password" ThenElsen = n + 1If n = 3 ThenEnd IfEnd If= ""= ""End Subex0706APrivate Sub Command1_Click()End Subex0906BPrivate Sub Command1_Click()Unload Form1Unload Form2Unload Form3EndEnd Subex0802Private Sub Form_Load()Dim i As Integer, j As IntegerShowFor i = 1 To 12Print String(20 - i, 32); '输出当前行左边的空格,分号表示下一输出项紧接输出 For j = 1 To 2 * i - 1 '输出2*i-1个字符If j <= i Then '按左、右两边指定输出字符k = j '左边输出的字符Elsek = 2 * i - j '右边输出的字符End IfIf k > 9 Then k = k + 7 '字母的ASCII码比数字大7Print Chr(k + 48); '以字符格式输出Next jPrint '换行Next iEnd Subex0803Dim t As Single, f As IntegerPrivate Sub Command1_Click() '“产生原稿文”按钮Randomizes = ""For k = 1 To 30x = Chr(Int(Rnd * 26) + 97) '随机产生小写字母s = s + xNext k= s '显示在文本框中= ""= False '允许录入'设置焦点= ""= ""f = 0 '第1次按键标记,0表示未按键End SubPrivate Sub Command2_Click() '“结束”按钮EndEnd SubPrivate Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)Dim c As Integer, k As IntegerIf f = 0 Then '第1次按键时,开始计时t = Timer '用t保存第1次按键的时间 f = 1 '1表示已按键和进入录入过程 End IfIf Len < 30 Then= Round(Timer - t, 1) & "秒" '显示用户当前所用时间Elsec = 0For k = 1 To 30 '统计录入正确的字母个数If Mid, k, 1) = Mid, k, 1) Thenc = c + 1End IfNext k= True '禁止录入= Round(c / 30 * 100, 2) & "%" '显示准确率End IfEnd Subex0901Private Sub Command1_Click()Open "静夜思.txt" For Input As #1Do While Not EOF(1) '文件未结束时,循环Input #1, xxLoopClose #1End Subex0902Dim d(1 To 20) As IntegerPrivate Sub Command1_Click() '"产生随机数"For i = 1 To 20d(i) = Int(1 + 99 * Rnd)d(i)Next iEnd SubPrivate Sub Command2_Click() '"保存"Open "" For Output As #1For i = 1 To 20Write #1, d(i)Next iClose #1End SubPrivate Sub Command3_Click() '"读出"Open "" For Input As #1Do While Not EOF(1)Input #1, xxLoopClose #1End SubPrivate Sub Command4_Click() '"结束"EndEnd Subex0903Private Sub Form_Load()ShowFor k = 1 To 6fn = "..\第7章\ex070" & k & ".vbp"If Dir(fn) = "" ThenPrint Mid(fn, 4) & "未编写!!"ElsePrint Mid(fn, 4) & "已编写!!"End IfNext kEnd Subex0904Private Sub Form_Load()chedir = "C:\Documents and Settings\Lin\My Documents\fsodir" If Dir(chedir, 16) = "" ThenMkDir chedirEnd Ifchefile = "C:\Windows\"If Dir(chefile) <> "" ThenFileCopy chefile, chedir & "\"End IfMsgBox "操作完毕!"End Subex1002Private Sub A1_Click()= vbRedEnd SubPrivate Sub A2_Click()= vbBlueEnd SubPrivate Sub A3_Click()= vbGreenEnd SubPrivate Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 ThenPopupMenu mun0End IfEnd Subex1003Private Sub Command1_Click()= "选择文件"= "文本文件|*.txt"= "C:\"=End SubPrivate Sub Command2_Click()Unload MeEndEnd Subex1101Private Sub calzc(x As Integer)= Round(2 * * x, 2)End SubPrivate Sub HV_Scroll()Dim r As Integerr == "=" & rCall calzc(r)End SubPrivate Sub Form_Load()= 300End Subex1102Private Sub Form_Load()For k = 0 To 3Image1(k).Stretch = TrueImage1(k).Picture = LoadPicture("箭头" & k + 1 & ".bmp") Next kEnd SubPrivate Sub Image1_Click(Index As Integer)= 20Select Case IndexCase 0"箭头向上"Case 1"箭头向左"Case 2"箭头向右"Case 3"箭头向下"End SelectEnd Sub。

VB语言程序设计课后编程及上机调试参考答案

VB语言程序设计课后编程及上机调试参考答案

V B 语言程序设计课后编程及上机调试参考答案ex0101Private Sub Label1_Click()Caption = " 练习 "Command1.Caption = " 确定 "Label1.FontBold = TrueLabel1.AutoSize = TrueLabel1.Caption = "Visual BasicEnd Sub ex0102Private Sub Command1_Click()Txt.Text = " 我有电脑 "End SubPrivate Sub Command2_Click()Txt.Text = " 我没有电脑 " EndSub程序设计教程Private Sub Command3_Click()Txt.Text = "" ' 一对双撇号,中间不留空 End Subex0104Private Sub Command1_Click()Dim x As Singlex = Val(Text1.Text)Text2.Text = 15 * xEnd Sub ex0202Private Sub Form_Click()Dim r As Single, s As Singler = 4.6s = 3.14159 * r A 2Text1.Text = " 圆的面积为 " & sEnd Subex0204Private Sub Command1_Click() '"Form1.WindowState = 2 ' End Sub最大化 " 按钮最大化Private Sub Command2_Click() '"Form1.WindowState = 0 '还原 "按钮还原End SubPrivate Sub Command3_Click() '"Form1.WindowState = 1 '最小化 " 按钮最小化End Sub ex0205Private Sub command1_click()Dim x As SingleDim y As Singlex = Val(Text1.Text)y = Val(Text2.Text)Text3.Text = x * x + y * y End Sub ex0206Private Sub command1_click()Dim x As Stringx = Text1.TextText2.Text = Left(x, 1) + Right(x, 1)End Sub ex0301 Private Sub Form_Load()Dim x As Integer, y As IntegerDim a As Integer, b As Integer, c As Integer x = Val(InputBox(" 请输入一个三位数 "))a = Int(x / 100) ' 求百位数b = Int(x / 10) - a * 10 ' 求十位数c = x Mod 10 ' 求个位数Showy = c * 100 + b * 10 + a ' 生成倒序数Print x; " 倒序数为: "; y ' 显示倒序数End Sub ex0302Private Sub Command1_Click()n = Val(Text1.Text)Randomizex = Int(1 + n *Rnd) Label1.Caption 第一个随机数" + Str(x)x = Int(1 + n *Rnd)Label2.Caption = " 第二个随机数" +Str(x)x = Int(1 + n *Rnd)Label3.Caption = " 第三个随机数" +Str(x)End Sub ex0303Private Sub Cmd1_Click()Lab1.Visible = TrueLab1.Caption = " 您已下达显示命令 "End SubPrivate Sub Form_Click()Cmd1.Visible = TrueEnd Subex0304Private Sub Form_KeyPress(KeyAscii As Integer)ShowPrint " 输入字符: "; Chr(KeyAscii), "ASCII 码为 ;"; KeyAscii End SubPrivate Sub Form_DblClick()ClsEnd Sub ex0305 Private Sub Form_Load()x = MsgBox(" 在这里显示提示信息 ", 4 + 0, " 请确认 ")x = MsgBox(" 在这里显示 " + Chr(13) + " 提示信息 ", 3 + 0, " x = MsgBox(" 在这里显示 " + Chr(13) + " 提示信息 ", 2 + 16 + 0,End Sub ex0401Private Sub Form_Load()Dim x As Long, s As Stringx = In putBox(" 输入一个整数(1 〜35000)")s = " 奇数"If x Mod 2 = 0 Then s = " 偶数"MsgBox s End Sub ex0402Private Sub Command1_Click()Dim a As Single, b As SingleDim c As Single, d As SingleDim m As Single, n As Single, x As SingleShowa = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)d = Val(Text4.Text)If a > b Then ' 求 a、b 中的较大数m = aElsem = bEnd IfIf c > d Then ' 求 c、d 中的较大数n = cElsen = dEnd IfIf m > n Then ' 求 m、n 中的较大数x = mElsex = nEnd IfText5.Text = x 请确认")请确认")End Subex0403Private Sub Command1_Click()Dim t As String, p As String t = Mid(Text1.Text, 5, 1) Select Case tCase "2"p = " 博士生 "Case "3"p = " 硕士生 "Case "4"p = " 本科生 "Case "5"p = " 专科生 "Case Elsep = " 无效学号 "End SelectText2.Text = Left(Text1.Text, 2) + "Text3.Text = pEnd Subex0404Private Sub Command1_Click()r = 0: g = 0: b = 0If Check1.Value = 1 Thenr = 255End IfIf Check2.Value = 1 Theng = 255End IfIf Check3.Value = 1 Thenb = 255End IfLabel1.BackColor = RGB(r, g, b)End SubPrivate Sub Command2_Click()EndEnd Subex0405Private Sub Form_Load()LabClk.Caption = "0"LabClk.Alignment = 1LabClk.BorderStyle = 1LabClk.FontSize = 22LabClk.FontName = " 黑体 "TimClk.Interval = 1000End SubPrivate Sub TimClk_Timer()LabClk.Caption = Val(LabClk.Caption) + 1End Sub ex0406 Private Sub Form_Load()Command1.Enabled = FalseCommand2.Enabled = FalseEnd SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Text1.SelLength > 0 ThenCommand1.Enabled = TrueEnd IfEnd SubPrivate Sub Command1_Click()Command1.Enabled = TrueCommand2.Enabled = TrueEnd SubPrivate Sub Command2_Click()Text2.Text = Text1.SelTextCommand1.Enabled = FalseCommand2.Enabled = FalseEnd Sub ex0501 Private Sub Form_Load()Dim k As Integer, s As Integer, t As Integers = 0For k = 1 To 100 Step 2s = s + kNext kShowPrint "1 〜100范围内的奇数和:";sEnd Sub ex0502 Private Sub Form_Load()Dim s As SingleShows = 0For k = 1 To 200s = s + k / (1 + k * k)Next kPrint Int(s * 10 + 0.5) / 10End Sub ex0503 Private Sub Form_Load()Showk = 2Do While k < 101s = s + k * (k - 1)k = k + 2LoopPrint sEnd Subex0504Private Sub Form_Load()Dim k As Integer, a As Integer, b As IntegerDim c As Integer, n As IntegerShown = 0Print " 三位数的水仙花数是: "For k = 100 To 999a = Int(k / 100)b = Int((k - 100 * a) / 10)c = k Mod 10If a * a * a + b * b * b + c * c * c = k Then Print kn = n + 1End IfNext kPrint " 一共有 " & n & " 个水仙花数 "End Sub ex0505Private Sub Form_Load()ShowFor k = 1000 To 9999If k Mod 78 = 0 Thena = Int(k / 1000)b = Int(k / 100) - 10 * ac = Int(k / 10) - 100 * a - 10 * bd = k Mod 10If a = b And c = d ThenPrint kEnd IfEnd IfNext kEnd Subex0506Private Sub Command1_Click()Dim s As String, y As StringDim x As String, t As Strings = Text1.Text: y = ""For k = 1 To Len(s)x = Mid(s, k, 1)t = UCase(x)If t >= "A" And t <= "Z" Theny = y + xEnd IfNext kText2.Text = yEnd Subex0507Private Sub Command1_click()FontSize = 12ClsFor i = 0 To List1.ListCount -1If List1.Selected(i) Then 'Print List1.List(i)End IfNext iEnd Subex0508Private Sub Form_Load()ShowFor a = 1 To 9For b = 1 To 9For c = 1 To 9For d = 1 To 9x = a * 1000 + b * 100 + c y = b * 1000 + a * 100 + a z = d * 100 + d * 10 + a If x - y = z ThenPrint "A=" & a & ",B=" & b & ",C=" & c & ",D=" & d End IfNext dNext cNext bNext aEnd Sub ex0601Private Sub Command1_Click()Dim a(10) As Integer, min As Integer, pos As Integer RandomizeFor i = 1 To 10 a(i) = Int(Rnd * 90 + 10) Print a(i);Next iPrintmin = a(1)pos = 1For k = 2 To 10 If a(k) < min Then min = a(k) pos = k 10 + d 10 + c 显示 "按钮单击事件逐项判断 真时为选定Next kPrint " 最小数: "; min, " 位置: "; posEnd Sub ex0602Private Sub Form_Load()Dim a As Variant, b As VariantDim c(8) As Integera = Array(3, 4, 2, 1, 5, 7, 8, 11, 13)b = Array(10, 6, 12, 9, 13, 8, 8, 1, 16)For k = 0 To 8 c(k) = a(k) + b(k)Next kShowFor k = 0 To 8Print c(k)Next kEnd Sub ex0603 Private Sub Form_Load()Dim d() As IntegerDim k As Integer, t As Integer, m As IntegerDim h As Integer, n As Integern = Val(InputBox(" 请输入数组个数 n: "))ReDim d(n)ShowPrint " 处理前数据 :"RandomizeFor k = 1 To nd(k) = Int((101 * Rnd - 50))Print d(k);Next kPrintm = Int(n / 2)For k = 1 To m h = n - k + 1 t = d(h): d(h) = d(k): d(k) = t Next kPrint " 处理的结果 :"For k = 1 To nPrint d(k);Next kEnd Subex0604Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim s As Long, i As Integer, j As IntegerShown = 8For i = 1 To nFor j = 1 To nx = Int(90 * Rnd + 10) ' 产生一个随机数a(i, j) = xNext jNext is = 0For i = 1 To nFor j = 1 To ns = s + a(i, j)Next jNext iPrint " 所有元素之和; "; sPrintFor i = 1 To ns = 0For j = 1 To ns = s + a(i, j)Next jPrint " 第 "; i; " 行元素之和; "; sNext iPrints = 0For i = 1 To ns = s + a(i, i)Next iPrint " 主对角线元素之和; "; sPrints = 0For i = 1 To nFor j = 1 To nIf i = 1 Or i = n Or j = 1 Or j = n Then s = s + a(i, j)End IfNext jNext iPrint " 所有靠边元素之和; "; sEnd Sub ex0605 Option Base 1Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim max As Integer, r As Integer, c As Integer Show Randomizen = 8For i = 1 To nFor j = 1 To nx = Int(900 * Rnd + 100) 'a(i, j) = xPrint x;Next jPrintNext imax = 0: r = 1: c = 1PrintFor i = 1 To nFor j = 1 To nIf a(i, j) > max Then 'max = a(i, j): r = i: c = jEnd IfNext j, iPrint " 最大值为: "; maxPrint " 位于行: "; r, " 列: "; c End Sub ex0606 Dim n As IntegerPrivate Sub Cmd1_Click()n = n + 1If n = 3 Then n = 0Opt1(n).Value = True End SubPrivate Sub Form_Load()n = 1End Sub ex0607Private Sub Form_Load()Dim a(20) As IntegerRandomizea(1) = Int(10 + 90 * Rnd)k = 1Do While k < 20x = Int(10 + 90 * Rnd) 产生一个随机数判断有无更大数For j = 1 To kIf x = a(j) Then f = 1 Exit ForEnd IfNext jIf f = 0 Thenk = k + 1 a(k) = xEnd IfLoopShowFor j = 1 To 20Print a(j)Next jEnd Sub ex0701Private Sub Form_Click() Dim s As Long s = 0For k = 1 To 10 s = s + jc(k)Next kPrint sEnd SubFunction jc(n) As LongDim t As Longt = 1For k = 1 To nt = t * kNext kjc = tEnd Functionex0702Private Sub Form_Load()Dim a As Single, b As Single, c As Single Dim d As Single, m As Single, n As Single Showa = Val(InputBox(" 输入第 1 个数 "))b = Val(InputBox(" 输入第 2 个数 "))c = Val(InputBox(" 输入第 3 个数"))d = Val(InputBox(" 输入第 4 个数 "))m = max(a, b) 'n = max(c, d) 'Print " 最大数为: " & max(m, n) End SubFunction max(x, y) As SingleIf x > y Then max = xElsemax = y 求a、 b 中的较大数求c、 d 中的较大数求m、n 中的较大End Function ex0703Private Sub Command1_Click()Dim d(5) As Single, m As SingleFor k = 0 To 5d(k) = Val(Text1(k).Text) Next kCall Max(d(0), d(1), d(2), m)Call Max(m, d(3), d(4), m)Call Max(m, m, d(5), m) Text2.Text = mEnd Sub ex0704Private Sub Form_Load() Dim x As Long Showx = Val(InputBox(" 输入一个数 "))Print x; " 的位数为: "; fnws(x) End SubFunction fnws(x As Long) As Integer Dim n As Integer n = 1 Do While x \ 10 > 0n = n + 1x = x \ 10 Loop fnws = nEnd Function ex0705Private Sub C1_Click()Form1.HideEnd Sub ex0705APrivate Sub C2_Click()Form1.ShowEnd Sub ex0706 Dim n As IntegerPrivate Sub Command1_Click()usern = Trim(Text1.Text)passw = Trim(Text2.Text)If usern = "username" And passw = "password" Then Form1.HideForm2.ShowElsen = n + 1Text1.SetFocusIf n = 3 ThenForm1.HideForm3.ShowEnd IfEnd IfText1.Text = ""Text2.Text = ""End Subex0706APrivate Sub Command1_Click()Form2.HideForm1.ShowEnd Subex0906BPrivate Sub Command1_Click()Unload Form1Unload Form2Unload Form3EndEnd Sub ex0802 Private Sub Form_Load()Dim i As Integer, j As IntegerShowFor i = 1 To 12Print String(20 - i, 32); ' For j = 1 To 2 * i - 1 'If j <= i Then 'k = j 'Elsek = 2 * i - j 'End IfIf k > 9 Then k = k + 7 ' Print Chr(k + 48); 'Next jPrint ' 输出当前行左边的空格,分号表示下一输出项紧接输出输出2*i-1 个字符按左、右两边指定输出字符左边输出的字符右边输出的字符字母的ASCII 码比数字大7 以字符格式输出换行End SubDim t As Single, f As IntegerPrivate Sub Command1_Click()RandomizeIII! For k = 1 To 30If Mid(Text1.Text, k, 1) = Mid(Text2.Text, k, 1) Then c = c + 1End IfNext k Text2.Locked = True ' 禁止录入Text4.Text = Round(c / 30 * 100, 2) & "%" ' 显示准确率End IfEnd Subex0901Private Sub Command1_Click()Open " 静夜思 .txt" For Input As #1Do While Not EOF(1) '文件未结束时,循环Input #1, xList1.AddItem xLoopClose #1End Sub ex0902 产生原稿文”按钮x = Chr(Int(Rnd * 26) + 97) 's = s + xNext kText1.Text = s 'Text2.Text = ""Text2.Locked = False 'Text2.SetFocus 'Text3.Text = ""Text4.Text = ""f = 0 'End SubPrivate Sub Command2_Click()' EndEnd SubPrivate Sub Text2_KeyUp(KeyCode As Integer,Dim c As Integer, k As IntegerIf f = 0 Then' t = Timer' f = 1'1 End IfIf Len(Text2.Text) < 30 ThenText3.Text = Round(Timer - t, 1) & "Elsec = 0For k = 1 To 30 ' 随机产生小写字母 显示在文本框中 允许录入 设置焦点 第 1 次按键标记, 0 表示未按键 “结束”按钮 As Integer) 第 1 次按键时,开始计时 用t 保存第1次按键的时间 表示已按键和进入录入过程 秒 " ' 显示用户当前所用时间统计录入正确的字母个数Dim d(1 To 20) As IntegerPrivate Sub Command1_Click() '" 产生随机数 "For i = 1 To 20 d(i) = Int(1 + 99 * Rnd) List1.AddItem d(i)Next iEnd SubPrivate Sub Command2_Click() '" 保存 "Open "MyFile4.txt" For Output As #1For i = 1 To 20Write #1, d(i)Next iClose #1End SubPrivate Sub Command3_Click() '" 读出 "Open "MyFile4.txt" For Input As #1Do While Not EOF(1) Input #1, x List2.AddItem xLoopClose #1End SubPrivate Sub Command4_Click() '" 结束 "EndEnd Sub ex0903 Private Sub Form_Load()ShowFor k = 1 To 6第 7 章\ex070" & k & ".vbp"If Dir(fn) = "" ThenPrint Mid(fn, 4) & " 未编写!! " ElsePrint Mid(fn, 4) & " 已编写!! " End IfNext kEnd Subex0904Private Sub Form_Load()chedir = "C:\Documents and Settings\Lin\My Documents\fsodir" If Dir(chedir, 16) = "" ThenMkDir chedirEnd Ifchefile = "C:\Windows\notepad.exe"If Dir(chefile) <> "" ThenFileCopy chefile, chedir & "\mynotepad.exe"End IfMsgBox " 操作完毕! "End Subex1002Private Sub A1_Click()Label1.ForeColor = vbRedEnd SubPrivate Sub A2_Click()Label1.ForeColor = vbBlueEnd SubPrivate Sub A3_Click()Label1.ForeColor = vbGreenEnd SubPrivate Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 ThenPopupMenu mun0End IfEnd Subex1003Private Sub Command1_Click()CommonDialog1.DialogTitle = " 选择文件 " CommonDialog1.Filter = " 文本文件 |*.txt"CommonDialog1.InitDir = "C:\"CommonDialog1.ShowOpenText1.Text = CommonDialog1.FileNameEnd SubPrivate Sub Command2_Click()Unload MeEndEnd Subex1101Private Sub calzc(x As Integer)Text2.Text = Round(2 * 3.14159 * x, 2)End SubPrivate Sub HV_Scroll()Dim r As Integer r = HV.ValueText1.Text = "=" & rCall calzc(r)End SubPrivate Sub Form_Load()HV.Max = 300End Subex1102Private Sub Form_Load()For k = 0 To 3 Image1(k).Stretch = TrueImage1(k).Picture = LoadPicture(" 箭头 " & k + 1 & ".bmp")Next kEnd SubPrivate Sub Image1_Click(Index As Integer) Picture1.ClsSelect Case IndexCase 0Picture1.Print "Case 1箭头向上 "Picture1.Print " Case 2Picture1.Print " Case 3 箭头向左 " 箭头向右 "Picture1.Print "End SelectEnd Sub箭头向下 "。

VB语言程序设计课后编程及上机调试参考答案

VB语言程序设计课后编程及上机调试参考答案

VB语言程序设计课后编程及上机调试参考答案VB语言程序设计课后编程及上机调试参考答案ex0101Private Sub Label1_Click()Caption = "练习"Command1.Caption = "确定"Label1.FontBold = TrueLabel1.AutoSize = TrueLabel1.Caption = "Visual Basic程序设计教程" End Subex0102Private Sub Command1_Click()Txt.Text = "我有电脑"End SubPrivate Sub Command2_Click()Txt.Text = "我没有电脑"End SubPrivate Sub Command3_Click()Txt.Text = "" '一对双撇号,中间不留空End Subex0104Private Sub Command1_Click()Dim x As Singlex = Val(Text1.Text)Text2.Text = 15 * xEnd Subex0202Private Sub Form_Click()Dim r As Single, s As Singler = 4.6s = 3.14159 * r ^ 2Text1.Text = "圆的面积为" & sEnd Subex0204Private Sub Command1_Click() '"最大化"按钮 Form1.WindowState = 2 '最大化End SubPrivate Sub Command2_Click() '"还原"按钮 Form1.WindowState = 0 '还原End SubPrivate Sub Command3_Click() '"最小化"按钮 Form1.WindowState = 1 '最小化End Subex0205Private Sub command1_click()Dim x As SingleDim y As Singlex = Val(Text1.Text)y = Val(Text2.Text)Text3.Text = x * x + y * yEnd Subex0206Private Sub command1_click()Dim x As Stringx = Text1.TextText2.Text = Left(x, 1) + Right(x, 1) End Subex0301Private Sub Form_Load()Dim x As Integer, y As IntegerDim a As Integer, b As Integer, c As Integer x = Val(InputBox("请输入一个三位数"))a = Int(x / 100) '求百位数b = Int(x / 10) - a * 10 '求十位数c = x Mod 10 '求个位数Showy = c * 100 + b * 10 + a '生成倒序数Print x; "倒序数为:"; y '显示倒序数End Subex0302Private Sub Command1_Click()n = Val(Text1.Text)Randomizex = Int(1 + n * Rnd)Label1.Caption = "第一个随机数" + Str(x)x = Int(1 + n * Rnd)Label2.Caption = "第二个随机数" + Str(x)x = Int(1 + n * Rnd)Label3.Caption = "第三个随机数" + Str(x) End Subex0303Private Sub Cmd1_Click()Lab1.Visible = TrueLab1.Caption = "您已下达显示命令"End SubPrivate Sub Form_Click()Cmd1.Visible = TrueEnd Subex0304Private Sub Form_KeyPress(KeyAscii As Integer) ShowPrint "输入字符:"; Chr(KeyAscii), "ASCII码为;"; KeyAsciiEnd SubPrivate Sub Form_DblClick()ClsEnd Subex0305Private Sub Form_Load()x = MsgBox("在这里显示提示信息", 4 + 0, "请确认")x = MsgBox("在这里显示" + Chr(13) + "提示信息", 3 + 0, "请确认")x = MsgBox("在这里显示" + Chr(13) + "提示信息", 2 + 16 + 0, "请确认")End Subex0401Private Sub Form_Load()Dim x As Long, s As Stringx = InputBox("输入一个整数(1~35000)")s = "奇数"If x Mod 2 = 0 Then s = "偶数"MsgBox sEnd Subex0402Private Sub Command1_Click()Dim a As Single, b As SingleDim c As Single, d As SingleDim m As Single, n As Single, x As Single Showa = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)d = Val(Text4.Text)If a > b Then '求a、b中的较大数m = aElsem = bEnd IfIf c > d Then '求c、d中的较大数n = cElsen = dEnd IfIf m > n Then '求m、n中的较大数x = mElsex = nEnd IfText5.Text = xEnd Subex0403Private Sub Command1_Click()Dim t As String, p As String t = Mid(Text1.Text, 5, 1)Select Case tCase "2"p = "博士生"Case "3"p = "硕士生"Case "4"p = "本科生"Case "5"p = "专科生"Case Elsep = "无效学号"End SelectText2.Text = Left(Text1.Text, 2) + "级" Text3.Text = pEnd Subex0404Private Sub Command1_Click()r = 0: g = 0: b = 0If Check1.Value = 1 Thenr = 255End IfIf Check2.Value = 1 Theng = 255End IfIf Check3.Value = 1 Thenb = 255End IfLabel1.BackColor = RGB(r, g, b)End SubPrivate Sub Command2_Click()EndEnd Subex0405Private Sub Form_Load()LabClk.Caption = "0"LabClk.Alignment = 1LabClk.BorderStyle = 1LabClk.FontSize = 22LabClk.FontName = "黑体"TimClk.Interval = 1000End SubPrivate Sub TimClk_Timer()LabClk.Caption = Val(LabClk.Caption) + 1 End Subex0406Private Sub Form_Load()Command1.Enabled = FalseCommand2.Enabled = FalseEnd SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)If Text1.SelLength > 0 ThenCommand1.Enabled = TrueEnd IfEnd SubPrivate Sub Command1_Click()Command1.Enabled = TrueCommand2.Enabled = TrueEnd SubPrivate Sub Command2_Click()Text2.Text = Text1.SelTextCommand1.Enabled = FalseCommand2.Enabled = FalseEnd Subex0501Private Sub Form_Load()Dim k As Integer, s As Integer, t As Integer s = 0For k = 1 To 100 Step 2s = s + kNext kShowPrint "1~100范围内的奇数和:"; sEnd Subex0502Private Sub Form_Load()Dim s As SingleShows = 0For k = 1 To 200s = s + k / (1 + k * k) Next kPrint Int(s * 10 + 0.5) / 10 End Subex0503Private Sub Form_Load()Showk = 2s = 0Do While k < 101s = s + k * (k - 1)k = k + 2LoopPrint sEnd Subex0504Private Sub Form_Load()Dim k As Integer, a As Integer, b As Integer Dim c As Integer, n As IntegerShown = 0Print "三位数的水仙花数是:"For k = 100 To 999a = Int(k / 100)b = Int((k - 100 * a) / 10)c = k Mod 10If a * a * a + b * b * b + c * c * c = k ThenPrint kn = n + 1End IfNext kPrint "一共有" & n & "个水仙花数"End Subex0505Private Sub Form_Load()ShowFor k = 1000 To 9999If k Mod 78 = 0 Thena = Int(k / 1000)b = Int(k / 100) - 10 * ac = Int(k / 10) - 100 * a - 10 * bd = k Mod 10If a = b And c = d ThenPrint kEnd IfEnd IfNext kEnd Subex0506Private Sub Command1_Click()Dim s As String, y As StringDim x As String, t As Strings = Text1.Text: y = ""For k = 1 To Len(s)x = Mid(s, k, 1)t = UCase(x)If t >= "A" And t <= "Z" Theny = y + xEnd IfNext kText2.Text = yEnd Subex0507Private Sub Command1_click() '"显示"按钮单击事件FontSize = 12ClsFor i = 0 To List1.ListCount - 1 '逐项判断 If List1.Selected(i) Then '真时为选定Print List1.List(i)End IfNext iEnd Subex0508Private Sub Form_Load()ShowFor a = 1 To 9For b = 1 To 9For c = 1 To 9For d = 1 To 9x = a * 1000 + b * 100 + c * 10 + d y = b * 1000 + a * 100 + a * 10 + c z = d * 100 + d * 10 + aIf x - y = z ThenPrint "A=" & a & ",B=" & b & ",C=" & c & ",D=" & dEnd IfNext dNext cNext bNext aEnd Subex0601Private Sub Command1_Click()Dim a(10) As Integer, min As Integer, pos As IntegerRandomizeFor i = 1 To 10a(i) = Int(Rnd * 90 + 10)Print a(i);Next iPrintmin = a(1)pos = 1For k = 2 To 10If a(k) < min Thenmin = a(k)pos = kEnd IfNext kPrint "最小数:"; min, "位置:"; posEnd Subex0602Private Sub Form_Load()Dim a As Variant, b As VariantDim c(8) As Integera = Array(3, 4, 2, 1, 5, 7, 8, 11, 13)b = Array(10, 6, 12, 9, 13, 8, 8, 1, 16)For k = 0 To 8c(k) = a(k) + b(k)Next kShowFor k = 0 To 8Print c(k)Next kEnd Subex0603Private Sub Form_Load()Dim d() As IntegerDim k As Integer, t As Integer, m As Integer Dim h As Integer, n As Integern = Val(InputBox("请输入数组个数n:"))ReDim d(n)ShowPrint "处理前数据 :"RandomizeFor k = 1 To nd(k) = Int((101 * Rnd - 50))Print d(k);Next kPrintm = Int(n / 2)For k = 1 To mh = n - k + 1t = d(h): d(h) = d(k): d(k) = tNext kPrint "处理的结果 :"For k = 1 To nPrint d(k);Next kEnd Subex0604Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim s As Long, i As Integer, j As Integer ShowRandomizen = 8For i = 1 To nFor j = 1 To nx = Int(90 * Rnd + 10) '产生一个随机数a(i, j) = xNext jNext is = 0For i = 1 To nFor j = 1 To ns = s + a(i, j)Next jNext iPrint "所有元素之和;"; sPrintFor i = 1 To ns = 0For j = 1 To ns = s + a(i, j)Next jPrint "第"; i; "行元素之和;"; sNext iPrints = 0For i = 1 To ns = s + a(i, i)Next iPrint "主对角线元素之和;"; sPrints = 0For i = 1 To nFor j = 1 To nIf i = 1 Or i = n Or j = 1 Or j = n Then s = s + a(i, j)End IfNext jNext iPrint "所有靠边元素之和;"; sEnd Subex0605Option Base 1Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim max As Integer, r As Integer, c As Integer ShowRandomizen = 8For i = 1 To nFor j = 1 To nx = Int(900 * Rnd + 100) '产生一个随机数a(i, j) = xPrint x;Next jPrintNext imax = 0: r = 1: c = 1PrintFor i = 1 To nFor j = 1 To nIf a(i, j) > max Then '判断有无更大数max = a(i, j): r = i: c = jEnd IfNext j, iPrint "最大值为:"; maxPrint "位于行:"; r, "列:"; cEnd Subex0606Dim n As IntegerPrivate Sub Cmd1_Click()n = n + 1If n = 3 Then n = 0Opt1(n).Value = TrueEnd SubPrivate Sub Form_Load()n = 1End Subex0607Private Sub Form_Load()Dim a(20) As IntegerRandomizea(1) = Int(10 + 90 * Rnd) k = 1Do While k < 20x = Int(10 + 90 * Rnd) f = 0For j = 1 To kIf x = a(j) Then f = 1Exit ForEnd IfNext jIf f = 0 Thenk = k + 1a(k) = xEnd IfLoopShowFor j = 1 To 20Print a(j)Next jEnd Subex0701Private Sub Form_Click() Dim s As Longs = 0For k = 1 To 10s = s + jc(k)Next kPrint sEnd SubFunction jc(n) As Long Dim t As Longt = 1For k = 1 To nt = t * kNext kjc = tEnd Functionex0702Private Sub Form_Load()Dim a As Single, b As Single, c As SingleDim d As Single, m As Single, n As SingleShowa = Val(InputBox("输入第1个数"))b = Val(InputBox("输入第2个数"))c = Val(InputBox("输入第3个数"))d = Val(InputBox("输入第4个数"))m = max(a, b) '求a、b中的较大数n = max(c, d) '求c、d中的较大数Print "最大数为:" & max(m, n) '求m、n中的较大数End SubFunction max(x, y) As SingleIf x > y Thenmax = xElsemax = yEnd IfEnd Functionex0703Private Sub Command1_Click()Dim d(5) As Single, m As Single For k = 0 To 5d(k) = Val(Text1(k).Text)Next kCall Max(d(0), d(1), d(2), m) Call Max(m, d(3), d(4), m)Call Max(m, m, d(5), m)Text2.Text = mEnd Subex0704Private Sub Form_Load()Dim x As LongShowx = Val(InputBox("输入一个数")) Print x; "的位数为:"; fnws(x) End SubFunction fnws(x As Long) As Integer Dim n As Integern = 1Do While x \ 10 > 0n = n + 1x = x \ 10Loopfnws = nEnd Functionex0705Private Sub C1_Click()Form1.HideEnd Subex0705APrivate Sub C2_Click()Form1.ShowEnd Subex0706Dim n As IntegerPrivate Sub Command1_Click() usern = Trim(Text1.Text)passw = Trim(Text2.Text)If usern = "username" And passw = "password" ThenForm1.HideForm2.ShowElsen = n + 1Text1.SetFocusIf n = 3 ThenForm1.HideForm3.ShowEnd IfEnd IfText1.Text = ""Text2.Text = ""End Subex0706APrivate Sub Command1_Click()Form2.HideForm1.ShowEnd Subex0906BPrivate Sub Command1_Click()Unload Form1Unload Form2Unload Form3EndEnd Subex0802Private Sub Form_Load()Dim i As Integer, j As IntegerShowFor i = 1 To 12Print String(20 - i, 32); '输出当前行左边的空格,分号表示下一输出项紧接输出For j = 1 To 2 * i - 1 '输出2*i-1个字符If j <= i Then '按左、右两边指定输出字符k = j '左边输出的字符k = 2 * i - j '右边输出的字符End IfIf k > 9 Then k = k + 7 '字母的ASCII 码比数字大7Print Chr(k + 48); '以字符格式输出Next jPrint '换行Next iEnd Subex0803Dim t As Single, f As IntegerPrivate Sub Command1_Click() '“产生原稿文”按钮Randomizes = ""For k = 1 To 30x = Chr(Int(Rnd * 26) + 97) '随机产生小写字母Next kText1.Text = s '显示在文本框中Text2.Text = ""Text2.Locked = False '允许录入Text2.SetFocus '设置焦点Text3.Text = ""Text4.Text = ""f = 0 '第1次按键标记,0表示未按键End SubPrivate Sub Command2_Click() '“结束”按钮EndEnd SubPrivate Sub Text2_KeyUp(KeyCode As Integer, ShiftAs Integer)Dim c As Integer, k As IntegerIf f = 0 Then'第1次按键时,开始计时t = Timer '用t保存第1次按键的时间f = 1 '1表示已按键和进入录入过程End IfIf Len(Text2.Text) < 30 ThenText3.Text = Round(Timer - t, 1) & "秒" '显示用户当前所用时间Elsec = 0For k = 1 To 30 '统计录入正确的字母个数If Mid(Text1.Text, k, 1) =Mid(Text2.Text, k, 1) Thenc = c + 1End IfNext kText2.Locked = True '禁止录入Text4.Text = Round(c / 30 * 100, 2) & "%" '显示准确率End IfEnd Subex0901Private Sub Command1_Click()Open "静夜思.txt" For Input As #1Do While Not EOF(1) '文件未结束时,循环Input #1, xList1.AddItem xLoopClose #1End Subex0902Dim d(1 To 20) As IntegerPrivate Sub Command1_Click() '"产生随机数" For i = 1 To 20d(i) = Int(1 + 99 * Rnd)List1.AddItem d(i)Next iEnd SubPrivate Sub Command2_Click() '"保存" Open "MyFile4.txt" For Output As #1 For i = 1 To 20Write #1, d(i)Next iClose #1End SubPrivate Sub Command3_Click() '"读出" Open "MyFile4.txt" For Input As #1Do While Not EOF(1)Input #1, xList2.AddItem xLoopClose #1End SubPrivate Sub Command4_Click() '"结束" EndEnd Subex0903Private Sub Form_Load()ShowFor k = 1 To 6fn = "..\第7章\ex070" & k & ".vbp"If Dir(fn) = "" ThenPrint Mid(fn, 4) & "未编写!!"ElsePrint Mid(fn, 4) & "已编写!!"End IfNext kEnd Subex0904Private Sub Form_Load()chedir = "C:\Documents and Settings\Lin\My Documents\fsodir"If Dir(chedir, 16) = "" ThenMkDir chedirEnd Ifchefile = "C:\Windows\notepad.exe"If Dir(chefile) <> "" ThenFileCopy chefile, chedir & "\mynotepad.exe"End IfMsgBox "操作完毕!"End Subex1002Private Sub A1_Click()Label1.ForeColor = vbRedEnd SubPrivate Sub A2_Click()Label1.ForeColor = vbBlueEnd SubPrivate Sub A3_Click()Label1.ForeColor = vbGreenEnd SubPrivate Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button = 2 ThenPopupMenu mun0End IfEnd Subex1003Private Sub Command1_Click()CommonDialog1.DialogTitle = "选择文件"CommonDialog1.Filter = "文本文件|*.txt"CommonDialog1.InitDir = "C:\"CommonDialog1.ShowOpenText1.Text = CommonDialog1.FileName End SubPrivate Sub Command2_Click()Unload MeEndEnd Subex1101Private Sub calzc(x As Integer)Text2.Text = Round(2 * 3.14159 * x, 2) End SubPrivate Sub HV_Scroll()Dim r As Integerr = HV.ValueText1.Text = "=" & rCall calzc(r)End SubPrivate Sub Form_Load()HV.Max = 300End Subex1102Private Sub Form_Load()For k = 0 To 3Image1(k).Stretch = TrueImage1(k).Picture = LoadPicture("箭头" & k + 1 & ".bmp")Next kEnd SubPrivate Sub Image1_Click(Index As Integer)Picture1.Font.Size = 20Picture1.ClsSelect Case IndexCase 0Picture1.Print "箭头向上"Case 1Picture1.Print "箭头向左"Case 2Picture1.Print "箭头向右"Case 3Picture1.Print "箭头向下"End SelectEnd Sub41。

VB程序设计教程实验指导与习题解答上机答案

VB程序设计教程实验指导与习题解答上机答案

自测1程序代码Private Sub Command1_Click()Label1.FontSize = Label1.FontSize + 3 End SubPrivate Sub Command2_Click()Label1.FontBold = TrueEnd SubPrivate Sub Command3_Click()Label1.FontUnderline = TrueEnd SubPrivate Sub Command4_Click()Label1.FontSize = 10Label1.FontBold = FalseLabel1.FontUnderline = FalseEnd Sub初始窗口:单机放大之后窗口:单机下划线之后窗口:单击加粗之后窗口:单击还原之后窗口:自测2程序代码Label1 = "visual basic"Text1 = "程序设计题"End SubPrivate Sub Command2_Click()Text1 = "visual basic"Label1 = "程序设计题"End Sub初始窗口:单击显示之后窗口:单击交换之后的窗口:自测题3Private Sub Command1_Click()Label1.FontSize = Label1.FontSize * (0.5) End SubPrivate Sub Command2_Click()Label1.Top = Label1.Top + 30Label1.Width = Label1.Width + 20Label1.Alignment = 1End Sub初始窗口:单击缩小两倍之后的窗口:单击向右下角移动之后的窗口:自测题4Private Sub Command1_Click() Form1.Caption = "VB学习" Print "简单的VB程序设计" End SubPrivate Sub Command2_Click() ClsEnd SubPrivate Sub Command3_Click() EndEnd SubPrivate Sub Command3_Click() EndEnd Sub初始化窗口:单击显示之后的窗口:单击清除之后的窗口:单击退出之后的窗口:自测题5程序代码Private Sub Command1_Click() Text1.Text = ""Text2.Text = ""End SubText3.Text = Val(Text1.Text) + Val(Text2.Text)End SubPrivate Sub Command3_Click()EndEnd Sub初始化窗口:单击运算之后窗口:单击清除之后的窗口:单击退出之后的窗口:自测练习1Private Sub Command1_Click()Dim a$a = Text1.TextLabel1.Caption = Left(a, 2)End SubPrivate Sub Command2_Click()a = Text1.TextLabel2.Caption = Right(a, 2)End SubPrivate Sub Command3_Click()Text1.Text = Label1.Caption & Label2.CaptionEnd Sub初始窗口界面输入字符串截取前两个字符截取后两个字符字符串连接自测练习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 '千位i = f '交换后的个位f = j '交换后的千位k = hh = g '交换后的十位g = k '交换后的百位l = f * 1000 + g * 100 + h * 10 + iText1.Visible = FalsePrint "加密前的4位整数是7439"; (Chr(10)); "加密后的结果是"; lEnd Sub初始界面单击窗体运行后的界面自测练习1Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox("输入第一个数", "输入一个数", 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, , "输出的结果"自测练习2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox("输入第一个数的值"))b = Val(InputBox("输入第二个数的值"))c = Val(InputBox("输入第三个数的值"))d = Val(InputBox("输入第四个数的值"))e = a + b + c + df = e / 4Print "和="; ePrint "平均值="; fEnd Sub自测练习3Private Sub Form_Click()Dim h%, f%, x%, y%h = Val(InputBox("输入总头数"))f = Val(InputBox("输入总脚数"))x = (4 * h - f) / 2y = (f - 2 * h) / 2Print "笼中鸡的头数为"; x; "只"Print "笼中兔的头数为"; y; "只"End Sub自测练习1:Dim a%, b%, c%a = Val(InputBox("请输入第一条边", "边长"))b = Val(InputBox("请输入第二条边", "边长"))c = Val(InputBox("请输入第三条边", "边长"))If a + b > c And a + c > b And b + c > a ThenIf a * a + b * b = c * c Or a * a + c * c = b * b Or b * b = c * c = a * a ThenPrint "直角"ElseIf a = b And b = c ThenPrint "等边三角形"ElseIf a = b Or a = c Or b = c ThenPrint "等腰三角形"ElsePrint "一般三角形"End IfElsePrint "不是三角形"End IfEnd Sub不是三角形运行结果:初始窗口:输入三条边:运行结果:等边三角形运行结果如下:等腰三角形:一般三角形自测练习2:Private Sub Form_Click()Dim a%, b!a = Val(InputBox("请输入"))If a Mod 2 = 0 And a Mod 3 = 0 And a Mod 5 = 0 Then b = Sqr(a)Print a, bElseEndEnd IfEnd Sub初始化窗口:输入一个数:运行结果:自测练习3Private Sub Command1_Click()Dim a%, b%a = Val(Text1.Text)Select Case a > 0Case a < 20Case a >= 20 And a < 50MsgBox "行李费为0.3元/kg", , "行李费"Case a >= 50 And a < 100MsgBox "行李费为0.4元/kg", , "行李费"Case Elseb = 0.2 * 100 + (a - 100) * 0.5: MsgBox "行李费为" & b & "元", , "行李费" End SelectEnd Sub初始窗口:输入10:输入25:输入55:输入120:自测练习1Option Base 1Private Sub Form_Click()Dim i%, a(1 To 20) As Integera(1) = 1: a(2) = 1Print a(1);Print a(2);For i = 3 To 10a(i) = a(i - 1) + a(i - 2)Print a(i);For i = 11 To 16a(i) = a(i - 1) + a(i - 2)Print a(i);Next iPrintFor i = 17 To 20a(i) = a(i - 1) + a(i - 2)Print a(i);Next i初始界面:运行结果界面:自测练习2Option Base 1Private Sub Form_Load()Form1.Width = 10000Form1.Height = 5000End SubPrivate Sub Command1_Click()Dim i%, j%, t%, a(1 To 4, 1 To 4) As Integer For i = 1 To 4For j = 1 To 4a(i, j) = Int(Rnd * 10) + 1Next iPicture3.Print "对角线的元素如下" For i = 1 To 4Picture3.Print a(i, i);Next iPicture3.PrintFor i = 1 To 4Picture3.Print 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 4For j = 1 To 4Next iEnd Sub运行初始界面:运运行结果界面:自测练习1Sub itostr(a As Integer)Dim b%, c$a = Val(Text1.Text)While a >= 1c = Chr(a Mod 10 + 48) & ca = a \ 10WendText2.Text = c End SubDim a As Integera = Val(Text1.Text)Call itostr(a)End Sub运行初始界面:运行结果界面:验证其他数字:自测练习2:Public Function 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 + (Sin(d) + Sin(e)) * c / 2 I = I + 1Wendarea = sEnd FunctionPrivate Sub Command1_Click()Dim s As DoubleCall area(n)Text1.Text = area(n)运行初始界面:运行结果:自测练习3Private Sub Form_click()n = Val(InputBox("请输入n的值"))x = Val(InputBox("请输入x的值"))Print "e的值="; es(n, x)End SubPrivate Function es(n, x)Dim a As Double, b As Double, c As Double, i As Integer a = 1: b = 1: c = 1For i = 1 To na = x * a:b = b * i:c = c + a / bNext ies = cEnd Function运行初始界面:输入数据:运行结果:自测练习4:For i = 1 To 4For j = i + 1 To 5If a(i) > a(j) ThenEnd IfNext jNext iFor i = 1 To 5Print a(i); " ";Next iFor i = 1 To 5If Y < a(i) Thent = a(i): a(i) = Y: Y = tEnd IfNext iFor i = 1 To 6a(6) = tNext iEnd FunctionPrivate Sub Command1_Click()Dim i#, a%(1 To 6), Y%Y = Val(InputBox("输入y的值", "输入数据")) Insertfun a%(), YPrintFor i = 1 To 6Print a(i); " ";Next i运行初始界面:插入数据:运行结果:自测练习1:Private Sub Command1_Click()If Ch1.Value = 1 ThenText1.Text = "报名参加羽毛球比赛"End IfIf Ch2.Value = 1 ThenText1.Text = "报名参加乒乓球比赛"End IfIf Ch1.Value = 1 And Ch2.Value = 1 Then Text1.Text = "报名参加羽毛球,乒乓球比赛" End IfEnd Sub运行初始界面:运行结果:自测练习4:Private Sub Form_Load()Label1.Alignment = 2Label1.FontSize = 24Label1.FontName = "黑体"Label1.ForeColor = &HFF&Private Sub Option1_Click()Label1.Caption = "我是学生"End SubPrivate Sub Option2_Click()Label1.Caption = "我是教师"End SubPrivate Sub Option3_Click()Label1.Caption = "我是工人"End SubPrivate Sub Option4_Click()Label1.Caption = "我是农民"End Sub运行初始界面:运行结果:自测练习6:Private Sub Command1_Click()For i = 0 To Combo1.ListCount - 1If Combo1.List(i) = Combo1.Text Then Exit ForEnd IfNext iIf i > Combo1.ListCount - 1 Then Combo1.AddItem Combo1.TextEnd SubPrivate Sub Command2_Click()If Combo1.ListIndex <> -1 Then Combo1.RemoveItem Combo1.ListIndex For i = 0 To Combo1.ListCount - 1If Combo1.List(i) = Combo1.Text Then Combo1.RemoveItem iEnd IfExit ForNext iEnd IfEnd SubPrivate Sub Command3_Click()Combo1.ClearEnd Sub运行初始界面:自测练习7:Private Sub Command1_Click()Timer1.Interval = 1Timer1.Enabled = TrueEnd SubPrivate Sub Form_Load()lbltemp1.FontSize = 20Label1.FontSize = 20Label2.FontSize = 20End SubPrivate Sub Timer1_Timer() VSbwd.Value = VSbwd.Value + 10 lbltem = VSbwd.ValueIf VSbwd >= 100 Thenlbltishi = "水开了"Timer1.Enabled = FalseEnd IfEnd Sub运行初始界面:运行结果:自测练习1:Private Sub myhelp_Click() frmAbout.ShowEnd SubPrivate Sub mymenu1_Click() Text1.Text = "百货大楼"End SubPrivate Sub mymenu2_Click() Text1.Text = "利客隆"End SubText1.Text = "稻香村"End Sub运行初始界面:运行结果界面:自测练习2:Private Sub Dis_Click()Text1.Text = "菜单程序设计"Text1.FontSize = 20Text1.FontName = "黑体"End SubPrivate Sub Hid_Click()Text1.Visible = FalseEnd Sub运行初始界面:运行结果界面:自测练习3:Private Sub vbhelp_Click()r = MsgBox("帮助", , "程序设计题") End SubPrivate Sub Vbnew_Click()r = MsgBox("新建", , "程序设计题") End SubPrivate Sub vbopen_Click()r = MsgBox("打开", , "程序设计题")End SubPrivate Sub vbsave_Click()r = MsgBox("存盘", , "程序设计题") End Sub运行初始界面:运行结果:自测练习4:Private Sub Command1_Click() CommonDialog1.Action = 1List1.AddItem CommonDialog1.FileName End Sub运行初始界面:运行结果:自测练习1:Private Sub Command1_Click()Dim a As String, n%, i%, j%Open "E:\Data.txt" For Input As #1 Input #1, an = Len(a)j = 0For i = 1 To nIf Mid(a, i, 1) = "%" Then j = j + 1 Next iClose #1Open "E:\Datares.txt" For Output As #1 Print #1, jClose #1End Sub运行初始界面:运行结果:自测练习3:Private Sub Form_Click()Dim x$Open "e:\txt2.txt" For Input As #1Do While Not EOF(1)Line Input #1, x$LoopClose #1Open "e:\txt1.txt" For Append As #1Print #1, x$Close #1End Sub运行初始界面:自测练习4Private Sub Form_load()Print " 26个英文字母"PrintPrint " a b c d e f g h i j k l m n o p q r s t u v w x y z"Print "字母个数分别为"End SubPrivate Sub Form_Click()Open "E:\Data.txt" For Output As #1文本$ = InputBox("请输入文本")n = UCase(文本$)Print #1, nClose #1Dim a%()Open "E:\Data.txt" For Output As #1For i = 1 To Len(n)ReDim Preserve a(1 To 26)j = Asc(Mid(n, i, 1)) - 64a(j) = a(j) + 1Next iClose #1For j = LBound(a) To UBound(a) Print a(j);Next jEnd Sub。

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 8、 安装 Visual Basic 6.0后,帮助系统是否也已安装? 答:没有。VB6.0的帮助系统在两张光盘上,即 MSDN Library,其中还包含了 VC、VFP 等其他语言的帮 助系统。 9、 如何使用 Visual Basic 6.0的帮助系统? 答:最方便的方法是选定要帮助的内容,然后按 F1功能键,这时系统打开 MSDN Library 查阅器,直接 显示与选定内容有关的帮助信息。 10、 什么是类?什么是对象?什么是事件过程? 答:类是同类对象集合的抽象,它规定了这些对象的公共属性和方法; 对象是类的一个实例,对象包含三个要素:属性、方法和事件。 当在对象上发生了事件后,应用程序就要处理这个事件,而处理的步骤就是事件过程。 11、 属性和方法的区别是什么? 答:属性是对象的特征,方法是对象的行为。前者有值,可以被赋值或引用;后者没有值,表示能够执 行的操作。 12、 当标签边框的大小由 Caption 属性的值进行扩展或缩小时,应对该控件的什么属性进行何种设置? 答:将该控件的 Autosize 属性值设置为 true。 13、 在 VB6.0中,命令按钮的显示形式可以有标准的和图形的两种选择,它们通过什么属性来设置?若选 择图形的,则通过什么属性来装入图形?若已在规定的属性里装入了某个图形文件,但该命令按钮还是 不能显示该图形,而显示的是 Caption 属性设置的文字,应怎样修改? 答: 命令按钮的显示形式通过将 Style 属性值设置为 Graphical 来实现。 通过 Picture 属性来装入图形。 不

VB程序设计教程课后答案

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程序设计教程课后答案与实验题答案-(第三版)剖析

答案习题一答案在教材上找。

习题二1.对象指现实世界中的实体。

每个对象有自己的特征(属性)、行为(方法)和发生在该对象上的活动(事件)。

类是对同一种对象的集合与抽象。

类包含所创建对象的属性数据,以及对这些数据进行操作的方法。

封装和隐藏是类的重要特性,将数据结构和对数据的操作封装在一起,类的内部实现细节对用户来说是透明的。

VB工具箱中的可视图标是VB系统设计好的标准控件类。

通过将控件类实例化,得到真正的控件对象。

在窗体上画一个控件,就将类转换为对象,创建了一个控件对象。

VB中常用的对象是控件。

此外,VB还提供了系统对象。

窗体是个特例,它既是类也是对象。

当向一个工程添加一个新窗体时,实质就由窗体类创建了一个窗体对象。

对象的三要素:属性、事件和方法。

属性:存放对象的数据(决定对象外观及功能)对象属性的设置方法:在设计阶段,利用属性窗口直接设置属性值;程序运行时,通过语句[对象名.]属性名=属性值。

若属性只能在设计阶段设置,在程序运行阶段不可改变,称为只读属性。

事件:发生在对象上的事情。

同一事件,对不同的对象,会引发不同的反应。

事件过程:应用程序处理事件的步骤。

应用程序设计的主要工作就是为对象编写事件过程的代码。

方法:面向对象的程序设计语言,为程序设计人员提供了一种特殊的过程和函数。

方法是面向对象的,调用时一定要指明对象。

2.窗体和控件具有的基本属性“(1) Name属性:名称所创建的对象名称,在程序中引用。

(2) Caption属性:标题该属性决定了对象上显示的内容。

(3) Height、Width、Top和Left属性决定对象的大小和位置。

(4) Enabled 属性:对象是否允许操作(5) Visible 属性:对象是否可见(6) Font 属性组:文本的外观FontName字体、FontSize大小FontBold粗体、FontItalic斜体FontStrikethru 删除线FontUnderline 下划线(7) ForeColor属性:前景颜色(8) BackColor属性:背景颜色(9) MousePointer属性:鼠标指针类型, 设置值范围0~15,由系统指定。

vb程序设计教程课后答案与实验题答案(第三版)

vb程序设计教程课后答案与实验题答案(第三版)

习题一答案在教材上找。

习题二1.对象指现实世界中的实体。

每个对象有自己的特征(属性)、行为(方法)和发生在该对象上的活动(事件)。

类是对同一种对象的集合与抽象。

类包含所创建对象的属性数据,以及对这些数据进行操作的方法。

封装和隐藏是类的重要特性,将数据结构和对数据的操作封装在一起,类的内部实现细节对用户来说是透明的。

VB工具箱中的可视图标是VB系统设计好的标准控件类。

通过将控件类实例化,得到真正的控件对象。

在窗体上画一个控件,就将类转换为对象,创建了一个控件对象。

VB中常用的对象是控件。

此外,VB还提供了系统对象。

窗体是个特例,它既是类也是对象。

当向一个工程添加一个新窗体时,实质就由窗体类创建了一个窗体对象。

对象的三要素:属性、事件和方法。

属性:存放对象的数据(决定对象外观及功能)对象属性的设置方法:在设计阶段,利用属性窗口直接设置属性值;程序运行时,通过语句[对象名.]属性名=属性值。

若属性只能在设计阶段设置,在程序运行阶段不可改变,称为只读属性。

事件:发生在对象上的事情。

同一事件,对不同的对象,会引发不同的反应。

事件过程:应用程序处理事件的步骤。

应用程序设计的主要工作就是为对象编写事件过程的代码。

方法:面向对象的程序设计语言,为程序设计人员提供了一种特殊的过程和函数。

方法是面向对象的,调用时一定要指明对象。

2.窗体和控件具有的基本属性“(1) Name属性:名称所创建的对象名称,在程序中引用。

(2) Caption属性:标题该属性决定了对象上显示的内容。

(3) Height、Width、Top和Left属性决定对象的大小和位置。

(4) Enabled 属性:对象是否允许操作(5) Visible 属性:对象是否可见(6) Font 属性组:文本的外观FontName字体、FontSize大小FontBold粗体、FontItalic斜体FontStrikethru 删除线FontUnderline 下划线(7) ForeColor属性:前景颜色(8) BackColor属性:背景颜色(9) MousePointer属性:鼠标指针类型, 设置值范围0~15,由系统指定。

大学vb上机及课后习题答案实验1-2

大学vb上机及课后习题答案实验1-2

实验1.1.1 标签计算机等级考试True三号1实验1.1.2 200020012等级考试实验1.1.3 “”“”T2=T1实验1.1.4 改变按钮大小C1变宽C1.Width=C1.Width=100实验1.1.5 确认FalseFalseL1请确认C1是300800TrueC2否300800True实验1.1.6 列表框的使用北京山西辽宁浙江广东实验1.1.7 True3True3C1复制Text2=Text1实验1.1.8 计算机等级考试C1移动Text1.Left=0实验1.1.9 程序设计三号2粗体斜体TrueTrue实验1.2.1 计算机等级考试对齐方式字体左对齐居中右对齐宋体黑体Text1.Alignment=2Text1.Alignment=1“宋体”Text1.FontName=”黑体”实验1.2.2 选课CH1数学CH2语文CH3外语CH4计算机1实验1.2.3 20003000FalseCmd1显示图片Cmd2隐藏图片LoadPicture(App.Path&”\图片1.jpg”) LoadPicture(“”)实验1.2.4 FalseC:\VB\Sy02\图片2.jpg设置属性100240020020Picture1.Height=VScroll1.Value实验1.2.5 11001HScroll1.SetFocusText1=HScroll1.Value实验1.2.6 图形控件L11 2 3 4 5Shape1.Shape=L1.Text实验1.2.7 图形控件图形红色边框Shape1.Shape=3&HFF&实验1.2.8True“”三号1000Label1.Caption=Now。

【参考文档】vb实验指导书答案-范文word版 (10页)

【参考文档】vb实验指导书答案-范文word版 (10页)
3
Dim b As Single Dim c As Single Dim y As Single a = 5 b = 2.5 c = 7.8
y = (a * b * 3.14) / (a + b * c) Print y End Sub
2. 参考代码如下:
Private Sub Form_Click() Dim a As Single Dim b As Single Dim c As Single Dim d As Single
本文部分内容来自网络整理,本司不为其真实性负责,如有异议或侵权请及时联系,本司将立即删除!
== 本文为word格式,下载后可方便编辑和修改! ==
vb实验指导书答案
篇一:VB程序设计学习与实验指导书答案(包含实验答案)
VB学习与实验指导测试题
参考答案
第一章
第二章
第三章
第四章
第五章
第六章
第七章
第八章
篇二:VB实验指导书答案
A
14. C 15. C 16. D 17. B 18. A 19. C 20. A 21. A 22. B 23. D 24. C 25. C 26. B 27. D 28. A 29. B 30. A 31. D 32. C
33. D 34. D 35. A 36. A 37. A 38. D 39. B 40. B 41. B 42. B 43. C 44. C 45. C 46. B 47. B 48.
2
4. sq(x As Integer),Function 5. Val(t.Text) 6. 30,70 7. 5
9. 30
10. nAA N, X ,N1,nT1 * X1
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

自测1程序代码Private Sub Command1_Click() Label1.FontSize = Label1.FontSize + 3End SubPrivate Sub Command2_Click() Label1.FontBold = TrueEnd SubPrivate Sub Command3_Click() Label1.FontUnderline = TrueEnd SubPrivate Sub Command4_Click() Label1.FontSize = 10Label1.FontBold = FalseLabel1.FontUnderline = False—End Sub初始窗口:单机放大之后窗口:单机下划线之后窗口:单击加粗之后窗口:单击还原之后窗口:自测2程序代码Private Sub Command1_Click() Label1 = "visual basic"Text1 = "程序设计题"End SubPrivate Sub Command2_Click() Text1 = "visual basic"Label1 = "程序设计题"End Sub初始窗口:单击显示之后窗口:—单击交换之后的窗口:自测题3Private Sub Command1_Click()Label1.FontSize = Label1.FontSize * (0.5)End SubPrivate Sub Command2_Click()Label1.Top = Label1.Top + 30Label1.Width = Label1.Width + 20Label1.Alignment = 1End Sub—初始窗口:单击缩小两倍之后的窗口:单击向右下角移动之后的窗口:—自测题4程序代码Private Sub Command1_Click()Form1.Caption = "VB学习"Print "简单的VB程序设计"End SubPrivate Sub Command2_Click()Cls—End SubPrivate Sub Command3_Click()EndEnd SubPrivate Sub Command3_Click()EndEnd Sub初始化窗口:单击显示之后的窗口:—单击清除之后的窗口:单击退出之后的窗口:—自测题5程序代码Private Sub Command1_Click()Text1.Text = ""Text2.Text = ""End SubPrivate Sub Command2_Click()Text3.Text = Val(Text1.Text) + Val(Text2.Text)End SubPrivate Sub Command3_Click()EndEnd Sub初始化窗口:单击运算之后窗口:单击清除之后的窗口:单击退出之后的窗口:自测练习1Private Sub Command1_Click() Dim a$a = Text1.TextLabel1.Caption = Left(a, 2) End SubPrivate Sub Command2_Click() a = Text1.TextLabel2.Caption = Right(a, 2) End SubPrivate Sub Command3_Click()—Text1.Text = Label1.Caption & Label2.CaptionEnd Sub初始窗口界面输入字符串截取前两个字符截取后两个字符字符串连接自测练习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 + iText1.Visible = FalsePrint "加密前的4位整数是7439"; (Chr(10)); "加密后的结果是"; lEnd Sub初始界面单击窗体运行后的界面自测练习1Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox("输入第一个数", "输入一个数", 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自测练习2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox("输入第一个数的值"))b = Val(InputBox("输入第二个数的值"))c = Val(InputBox("输入第三个数的值"))d = Val(InputBox("输入第四个数的值"))e = a + b + c + df = e / 4—Print "和="; ePrint "平均值="; fEnd Sub自测练习3Private Sub Form_Click()Dim h%, f%, x%, y%h = Val(InputBox("输入总头数")) 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(InputBox("请输入第一条边", "边长"))b = Val(InputBox("请输入第二条边", "边长"))c = Val(InputBox("请输入第三条边", "边长"))If a + b > c And a + c > b And b + c > a ThenIf a * a + b * b = c * c Or a * a + c * c = b * b Or b * b = c * c = a * a ThenPrint "直角"ElseIf a = b And b = c ThenPrint "等边三角形"ElseIf a = b Or a = c Or b = c ThenPrint "等腰三角形"ElsePrint "一般三角形"End IfElsePrint "不是三角形"End IfEnd Sub不是三角形运行结果:初始窗口:输入三条边:运行结果:直角三角形运行结果:—等边三角形运行结果如下:等腰三角形:一般三角形自测练习2:—Private Sub Form_Click()Dim a%, b!a = Val(InputBox("请输入"))If a Mod 2 = 0 And a Mod 3 = 0 And a Mod 5 = 0 Thenb = Sqr(a)Print a, bElseEndEnd IfEnd Sub初始化窗口:输入一个数:—运行结果:自测练习3Private Sub Command1_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 Elseb = 0.2 * 100 + (a - 100) * 0.5: MsgBox "行李费为" & b & "元", , "行李费"—End SelectEnd Sub初始窗口:输入10:输入25:输入55:—输入120:自测练习1Option Base 1Private Sub Form_Click()Dim i%, a(1 To 20) As Integer—a(1) = 1: a(2) = 1Print a(1);Print a(2);For i = 3 To 10a(i) = a(i - 1) + a(i - 2)Print a(i);Next iPrintFor i = 11 To 16a(i) = a(i - 1) + a(i - 2)Print a(i);Next iPrintFor i = 17 To 20a(i) = a(i - 1) + a(i - 2)Print a(i);Next i初始界面:运行结果界面:自测练习2Option Base 1Private Sub Form_Load() Form1.Width = 10000 Form1.Height = 5000 End SubPrivate Sub Command1_Click()Dim i%, j%, t%, a(1 To 4, 1 To 4) As Integer For i = 1 To 4For j = 1 To 4a(i, j) = Int(Rnd * 10) + 1Picture1.Print a(i, j);Next jPicture1.PrintNext iPicture3.Print "对角线的元素如下"For i = 1 To 4Picture3.Print a(i, i);Next iPicture3.PrintFor i = 1 To 4Picture3.Print 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 4For j = 1 To 4Picture2.Print a(i, j);Next jPicture2.PrintNext iEnd Sub运行初始界面:运—运行结果界面:自测练习1Sub itostr(a As Integer)Dim b%, c$—a = Val(Text1.Text)While a >= 1c = Chr(a Mod 10 + 48) & ca = a \ 10WendText2.Text = c End SubPrivate Sub Command1_Click()Dim a As Integera = Val(Text1.Text)Call itostr(a)End Sub运行初始界面:运行结果界面:验证其他数字:自测练习2:Public Function 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 + (Sin(d) + Sin(e)) * c / 2 I = I + 1Wendarea = sEnd Function—Private Sub Command1_Click()Dim s As DoubleCall area(n)Text1.Text = area(n)End Sub运行初始界面:运行结果:自测练习3Private Sub Form_click()—n = Val(InputBox("请输入n的值"))x = Val(InputBox("请输入x的值"))Print "e的值="; es(n, x)End SubPrivate Function es(n, x)Dim a As Double, b As Double, c As Double, i As Integera = 1:b = 1:c = 1For i = 1 To na = x * a:b = b * i:c = c + a / bNext ies = cEnd Function运行初始界面:输入数据:—运行结果:自测练习4:For i = 1 To 4For j = i + 1 To 5If a(i) > a(j) Thent = a(i): a(i) = a(j): a(j) = t— End IfNext jNext iFor i = 1 To 5Print a(i); " ";Next iFor i = 1 To 5If Y < a(i) Thent = a(i): a(i) = Y: Y = tEnd IfNext iFor i = 1 To 6a(6) = tNext iEnd FunctionPrivate Sub Command1_Click()Dim i#, a%(1 To 6), Y%Y = Val(InputBox("输入y的值", "输入数据"))Insertfun a%(), YPrint—For i = 1 To 6Print a(i); " ";Next iEnd Sub运行初始界面:插入数据:运行结果:41011060蓝志鹏资源1102 实验8自测练习1:Private Sub Command1_Click()If Ch1.Value = 1 ThenText1.Text = "报名参加羽毛球比赛"End IfIf Ch2.Value = 1 ThenText1.Text = "报名参加乒乓球比赛"End IfIf Ch1.Value = 1 And Ch2.Value = 1 Then Text1.Text = "报名参加羽毛球,乒乓球比赛" End IfEnd Sub运行初始界面:运行结果:自测练习4:Private Sub Form_Load() Label1.Alignment = 2 Label1.FontSize = 24 Label1.FontName = "黑体" Label1.ForeColor = &HFF&—End SubPrivate Sub Option1_Click()Label1.Caption = "我是学生"End SubPrivate Sub Option2_Click()Label1.Caption = "我是教师"End SubPrivate Sub Option3_Click()Label1.Caption = "我是工人"End SubPrivate Sub Option4_Click()Label1.Caption = "我是农民"End Sub运行初始界面:—运行结果:。

相关文档
最新文档