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实验报告(含答案)
End If
If Check1.Value = 1 Then
Label1.FontBold = True
Else
Label1.FontBold = False
End If
If Check2.Value = 1 Then
Label1.FontItalic = True
Else
Label1.FontItalic = False
图1.1实验1-1运行界面
三.实验结果:对象属性设置
对象
属性
属性值
说明
Form1
caption
我的第一个vb程序
窗体
Label1
caption
请输入姓名
标签
Text1
text
““
文本框
Command1
caption
显示
命令按钮
Command2
caption
清除
命令按钮
四.实验思考:
1.标签label控件设置的属性代码有哪些?
加粗
复选框
Check2
Caption
倾斜
复选框
Check3
Caption
下划线
复选框
Check4
Caption
删除线
复选框
四.实验思考:
1.模拟简易计算器Command1命令的单击事件的程序代码是什么?
Private Sub Command1_Click()
Dim a!, b!
Dim c As String
If Option1.Value = True Then
Label1.FontName = “宋体”
ElseIf Option2.Value = True Then

中职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实验报告(答案)Vb程序设计实验项目试验报告(1)院(系): 课程名称: 日期: 班级学号实验室专业姓名计算机号实验成绩评定名称 VB环境的熟悉与应用所用教师签名软件 Visual Basic 6.0实验目 1(熟悉VB的系统环境,了解VB程序的编写、保存和编译的方法过程。

的 2(初步了解几个常用控件的使用方法。

或要求1、在vb中____C_____被称为对象。

实A.窗体B.控件C.窗体和控件D.窗体、控件和属性验2、设在名称为form1的窗体上只有1个名称为C1的命令按钮,下面叙述中正确的是( B ) 步A.窗体的Click事件过程的过程名是form1_Click 骤B.命令按钮的Click事件过程名是C1_Click、 C.命令按钮的Click事件过程的过程名是Command1_Click 心3、编译执行程序的快捷键是_Ctrl+F5_。

得 4、启动visual basic 后标题栏中显示的信息是(C)。

A.工程-Mmicrosoft Visual Basic[设计] 体B.工程-Mmicrosoft Visual Basic[中断]会C.工程1-Mmicrosoft Visual Basic[设计]第 1 页共 53 页1/53页Vb程序设计实验项目D.工程1-Mmicrosoft Visual Basic[中断]5、Visual Basic集成开发环境主要窗口包括__窗体设计窗口;代码设计窗口;_属性窗口;_工程资源管理器窗口_;_工具箱窗口。

6、属性显示方式分两种,即按__字母顺序和按_分类__顺序,分别通过单击相应的按钮来实现。

7、编一程序,程序运行的初始界面如图1-1所示,当用户在文本框中输入姓名,例如输入“张三”,单击“你输入的姓名是:”按钮(command1),则程序的运行情况如图1-2所示,如果单击“结束”按钮(command2),即结束程序运行。

注意:保存时必须存放在自己创建的文件夹下,窗体文件名为kt1.frm,工程文件名为kt1.vbp。

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程序设计实验指导习题答案

P178 五 1Private Sub Form_DblClick()'双击窗体时,通过InputBox输入n,求1/2+1/2^2....+1/2^nDim n As Integern = InputBox("输入n的值:")For i = 1 To ns = s + 1 / 2 ^ iNextPrint "1/2+1/2^2+...+1/2^" & n & "=" & s End SubP185五Dim a(9) As IntegerPrivate Sub Command1_Click()'在文本框显示10个两位随机整数,逗号分隔Text1.Text = ""For i = 0 To 9a(i) = Int(Rnd * 90 + 10)Text1.Text = Text1.Text & a(i) & "," Next iText1.Text = Left(Text1.Text, Len(Text1.Text) - 1)End SubPrivate Sub Command2_Click()'消息框显示最小值m = a(0)For i = 1 To 9If a(i) < m Then m = a(i)NextMsgBox "10个数的最小值为:" & mEnd SubPrivate Sub Command3_Click()'消息框显示最大值m = a(0)For i = 1 To 9If a(i) > m Then m = a(i)NextMsgBox "10个数的最大值为:" & mEnd Sub Private Sub Command4_Click()'消息框显示平均值For i = 0 To 9m = m + a(i)NextMsgBox "10个数的平均值为:" & m / 10 End SubP169 2P169 3Private Sub Command1_Click()Label1.Top = Label1.Top - Label1.Height / 2 Label1.Height = Label1.Height * 2Label1.Left = Label1.Left - Label1.Width / 2 Label1.Width = Label1.Width * 2Label1.FontSize = Label1.FontSize * 2End SubP169 4Private Sub VS1_Change()Text1.Text = VS1.V alueEnd SubPrivate Sub VS1_Scroll()Text1.Text = VS1.V alueEnd SubP169 5Private Sub Command1_Click()For i = List1.ListCount - 1 To 0 Step -1 List2.AddItem List1.List(i)Next iList1.ClearEnd SubP177 2Private Sub Text1_Change()Label1.Caption = UCase(Text1.Text)End SubP177 3Private Sub Cmd1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Cmd2_Click()EndEnd SubPrivate Sub Timer1_Timer()a = Pic1.PicturePic1.Picture = Pic2.PicturePic2.Picture = aEnd SubP177 4Private Sub Command1_Click()a = Val(Text1.Text)b = Val(Text2.Text)If a < b ThenLabel1.Caption = aElseLabel1.Caption = bEnd IfEnd SubP177 5Private Sub Form_Load()Image1.Picture = LoadPicture(App.Path & "/p1.gif")HS1.Min = 500HS1.Max = 1000End SubPrivate Sub HS1_Change()Image1.Width = HS1.ValueEnd Sub P184 2Private Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Timer1_Timer()a = Label1.BackColorLabel1.BackColor = Label1.ForeColorLabel1.ForeColor = aEnd SubP184 3Private Sub Check1_Click()Text1.FontBold = Check1.ValueEnd SubP184 4Private Sub Command1_Click()Dim n As Integern = InputBox("请输入一个整数:")For i = 1 To ns = s + i ^ 2Next iText1.Text = "从1到" & n & "的平方和为" & sEnd Sub。

(完整版)VB程序设计教程(第3版)课后实验完整答案

(完整版)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程序设计教程实验指导与习题解答上机答案()

自测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程序代码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.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)); "加密后的结果是"; l End 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 "和="; 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 Then Print "等腰三角形"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 = 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) + 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) & c a = 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 DoubleDim 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 / 2I = 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) = 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%(), YPrintFor i = 1 To 6Print a(i); " ";Next iEnd Sub运行初始界面:插入数据:运行结果:自测练习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 ThenText1.Text = "报名参加羽毛球,乒乓球比赛" End IfEnd Sub运行初始界面:运行结果:自测练习4:Private Sub Form_Load()Label1.Alignment = 2Label1.FontSize = 24Label1.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运行初始界面:运行结果:自测练习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 IfEnd 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 = 20 lbltishi.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 SubPrivate Sub mymenu3_Click() Text1.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.FileNameEnd 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 #1 For 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实验报告答案全(2)(1)

vb实验报告答案全(2)(1)

实验一问答题:1、答:常见的有visual Basic、C++、Java、SQL。

用途特点:(参考课本4-5页)2、答:代码是一行或几行命令。

程序是针对某个任务编写的有序代码的集合。

软件是程序和文档的集合。

它们的关系是:代码 < 程序 < 软件3、答:面向对象程序设计中的每一个对象都应该能够接受数据、处理数据并将数据传达给其它对象,因此它们都可以被看作一个小型的“机器”,即对象。

它能够让人们更简单地设计并维护程序,使得程序更加便于分析、设计、理解。

4、答:参考课本第9页5、答:类——是创建对象实例的模板, 包含了创建对象的属性描述和行为特征的定义。

对象——是类的一个实例,继承了类的属性、方法。

控件——是具有图形界面的对象,它同样具有属性、方法、事件,是用来设计用户界面的重要元素。

属性——是对象的性质,用来描述和反应对象特征的参数。

事件——响应对象的动作,它发生在用户与程序交互时。

如单击控件、鼠标移动、键盘按下。

过程——指附在该对象上的程序代码,是事件的处理程序。

6、答:参考课本12页到17页。

实验二问答题:1、答通用属性有:Caption标题、Enabled可用性、Visible可见性、ForeColor前景颜色、BackColor背景颜色等。

2、答标签label是用来显示信息的,不具有输入功能。

属性有Caption、BackStyle、Alignment、BorderStyle、AutoSize。

文本框用来输入、输出数据,编辑文本。

属性有Text、 Maxlength、MultiLine、 ScrollBars、 Locked 、 PassWord 。

3、答结果为:标签里显示一个“abc”,图片框里显示3行“欢迎您”。

4、答要保存2次,分别是工程文件.vbp和窗体文件.frm。

实验一:一、选择1.D2.D3.B4.A5.B6.C7.CD8.D9.D10.编程机制是C、设计方式是B11.A12.D13.D14.C15.A二、填空1.windows2. 中断3.工具箱4.代码5.分类6.form2.show7. 出现语法错误8. 错9. 事件10. 面向对象11. 工程文件结构及各文件名12. 工程13. 设计程序代码14.双击窗体15.vb的安装文件夹16.属性17.方法18.font 19. form_load() 20.对象1.Private Sub Command1_Click()Print Sqr(8), 8 ^ (1 / 3)End Sub2.Private Sub Command1_Click()For i = 100 To 110Print Sqr(i)Next iEnd Sub3.Private Sub Form_Load()Print " 郑州大学在前进!"End Sub4. Private Sub label_click()PrintLabel.caption=”蓝天白云绿水青山”End sub实验二:一、选择1.B2.C3.B4.C5.C6.C7.B8.B9.D10.A11.C12.C13.C14.B15.A16.C17.B18.D19.C20.C二、填空1. Form_Click()2. Interval、5003..vbp .frm4.left top Height、Width twip5.picture6.load7. locked8. font Alignment9. GotFocus() LostFocus() 10. 属性窗口程序代码1.Private Sub Command1_Click()Label3 = Val(Text1) * Val(Text2)Private Sub Command2_Click()Label3 = Val(Text1) / Val(Text2)End Sub2.Private Sub Command1_Click()Picture1.Visible = TruePicture1.Picture = LoadPicture("d:\tu1.jpg") End SubPrivate Sub Command2_Click()Picture1.Visible = TruePicture1.Picture = LoadPicture("d:\tu2.jpg") End SubPrivate Sub Command3_Click()Picture1.Visible = False'也可以改为:Picture1.Picture = LoadPicture("") End Sub3.Private Sub Command1_Click()Label3 = Val(Text1) * Val(Text2) End Sub4.Private Sub Command1_Click() Text2 = Text1End SubPrivate Sub Command2_Click() Text1 = ""Text2 = ""End SubPrivate Sub Form_Load() Command1.Visible = False Command2.Visible = FalseEnd SubPrivate Sub Text1_Change() Command1.Visible = True Command2.Visible = TrueEnd Sub5.Private Sub Form_Load()Image1.Picture = LoadPicture("d:\tu3.jpg")End SubPrivate Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()Image1.Left = Int(Rnd * (Form1.ScaleWidth - Image1.Width)) Image1.Top = Int(Rnd * (Form1.ScaleHeight - Image1.Height)) End实验三:一、选择1.A2.BC3.BC4.A5.A6.A7.BCD8.D9.B10.B 11.B二、判断题不合法的变量:3. 4. 5. 6. 8. 10. 11. 14.15. 16.三、1、abs(x+y)2. (3+x*y)^23. (-b+sqr(b^2-4*a*c))/(2*a)4.sin(30*3.14/180)+exp(2)四、1. int(rnd* 71+20) 或int(rnd* 71)+202. x<0 and y>0 or x>0 and y<0 或者x*y<03. x mod 3=0 or x mod 7=0或x/3=x\3 or x/7=x\74. x>=10 and x<205. x>="A" and x<="Z"6. left(s,3) 或mid(s,1,3)操作题:2.Private Sub Command1_Click()Dim n%n = Abs(Val(Text1))Label2 = Format(n ^ 2, "#.000") & Space(2) & Format(Sqr(n), "#.000") & Space(2) & Format(n ^ 3, "#.000") & Space(2) & Format(n ^ (1 / 3), "#.000")'上句的输出也可以用下面的print方式:' Print Format(n ^ 2, "#.000"); Spc(2); Format(Sqr(n), "#.000"); Spc(2); Format(n ^ 3, "#.000"); Spc(2); Format(n ^ (1 / 3), "#.000")End Sub3.Private Sub Command1_Click()Dim x%, y%x = Int(Rnd * 900 + 100)Print "产生的随机数:"; xy = (x Mod 10) * 100 + (x \ 10 Mod 10) * 10 + x \ 100Print "反序数:"; Format(y, "000")End SubPrivate Sub Command2_Click()Dim x%, y As Stringx = Int(Rnd * 900 + 100)Print "产生的随机数:"; xy = Trim(Str(x))Print "反序数:" & Right(y, 1) & Mid(y, 2, 1) & Left(y, 1)End Sub4.Private Sub Command1_Click()Dim m%, n%Randomizem = Val(Text1): n = Val(Text2)x = Int(Rnd * (n - m) + m)y = Int(Rnd * (n - m) + m)z = Int(Rnd * (n - m) + m)Label3 = m & "到" & n & "之间的3个随机数为: " & x & Space(3) & y & Space(3) & zEnd Sub5.Private Sub Command1_Click()Label1.Caption = DateEnd SubPrivate Sub Command2_Click()Label2.Caption = TimeEnd SubPrivate Sub Command3_Click()Label3.Caption = WeekdayName(Weekday(Date))End Sub实验四:一、选择1.C2.D3. C4.D5.A6.D7.B8.B9.A10.C二、填空1. 48.71E-01, -4.87122. 关系、逻辑、算术3. 900,100,mid(s,2,1)4.m、1,2,3 、print m & "月是第二季度"、end select三、程序结果1. X=4 y=132. 10操作题:1.方法一:Private Sub Command1_Click()x = InputBox("请输入弧度数值", "弧度转换", 0)xx = Val(x)a = x * 180 / 3.14aa = Int(a)b = (a - aa) * 60bb = Int(b)c = (b - bb) * 60cc = Format(c, "#.000")MsgBox "弧度" & x & "转换为" & aa & "度" & bb & "分" & cc & "秒" End Sub方法二:Option ExplicitPrivate Sub Command1_Click()Dim x!, a!, aa%, b!, bb%, c!, cc$x = Val(Text1)a = x * 180 / 3.14aa = Int(a)b = (a - aa) * 60bb = Int(b)c = (b - bb) * 60cc = Format(c, "#.000")Label2 = "弧度" & Text1 & "转换为" & aa & "度" & bb & "分" & cc & "秒"End Sub2.Private Sub Command1_Click()Dim x%x = Val(Text1)If x / 400 = x \ 400 Or x Mod 4 = 0 And x Mod 100 <> 0 ThenLabel2 = Text1 & "年是闰年"ElseLabel2 = Text1 & "年不是闰年"End IfEnd Sub3.Private Sub Command1_Click()Dim x%, y%, z%x = InputBox("输入第一个数")y = InputBox("输入第二个数")z = InputBox("输入第三个数")Print "输入的数是:"; x; y; zIf x > y Then t = x: x = y: y = tIf y > z Then t = y: y = z: z = tIf x > y Then t = x: x = y: y = tPrint "排序结果是:"; x; y; zEnd Sub4.方法一:Private Sub Command1_Click() x = Val(InputBox("请输入上网时间:")) If x <> -1 ThenSelect Case xCase Is < 10fei = 25Case 10 To 50fei = x * 2Case 50 To 100fei = x * 1.5fei = x * 1End SelectMsgBox "上网费用为:" & fei & "元" End IfEnd SubPrivate Sub Command2_Click()EndEnd Sub方法二:Private Sub Command1_Click() Dox = Val(InputBox("请输入上网时间:", , -1)) If x <> -1 ThenSelect Case xCase Is < 10fei = 25Case 10 To 50fei = x * 2Case 50 To 100fei = x * 1.5Case Is >= 100End Selectzongfei = zongfei & Space(3) & fei MsgBox zongfei, , "上网费用为"ElseExit DoEnd IfLoopEnd SubPrivate Sub Command2_Click()EndEnd Sub实验五一、选择B C B A C二、填空(1)for x=2 to 10s*(1-1/x)(2) 1 t>1E-6(3) j t(4) 5 11 51.Private Sub Command1_Click()For n = 1 To 100s = s + nNext nPrint sEnd SubPrivate Sub Command2_Click()n = 1Do While n <= 100s = s + nn = n + 1LoopPrint sEnd Sub2.Private Sub Command1_Click()For i = 0 To 20For j = 0 To 33If i * 5 + j * 3 + 1 / 3 * (100 - i - j) = 100 Then Print i, j, 100 - i - j Next jNext iEnd Sub3.Private Sub Command1_Click()n = 0DoIf n Mod 2 = 1 And n Mod 3 = 2 And n Mod 5 = 4 And n Mod 6 = 5 And n Mod 7 = 0 Then Exit Don = n + 1LoopPrint nEnd Sub4.'已知x,y,z分别是0~9中的一个数,求x,y,z的值,使得xxz+yzz=532. Private Sub Command1_Click()Dim x%, y%, z%, i%, j%For x = 0 To 9For y = 0 To 9For z = 0 To 9If (x * 100 + x * 10 + z) + (y * 100 + z * 10 + z) = 532 Then Print x, y, z NextNextNextEnd SubPrivate Sub Command2_Click()For x = 0 To 9For y = 0 To 9For z = 0 To 9If Val(x & x & z) + Val(y & z & z) = 532 Then Print x; y; z NextNextNextEnd Sub5.Private Sub Command1_Click()x = Val(Text1)y = x * 4n = 0Do While x <= yx = x * (1 + 0.1)n = n + 1LoopPrint x, nEnd Sub6.Private Sub Command1_Click()n = Val(InputBox("输入计算到第几项:", , 0))For i = 1 To ns = s + (-1) ^ (i + 1) * iNextPrint n, sEnd SubPrivate Sub Command2_Click()n = Val(InputBox("输入计算到第几项:", , 0))p = 1For i = 1 To ns = s + p * ip = -pNextPrint n, sEnd Sub7.'s=(0+1)+(0+1+2)+(0+1+2+3)+(0+1+2+3+4)+……(0+1+2+3+4+……n) Private Sub Command1_Click()Dim n%, s%n = Val(InputBox("输入计算到第几项:", , 0))s = 0: t = 0For i = 1 To nt = t + is = s + tNext iPrint sEnd SubPrivate Sub Command2_Click()Dim n%, s%n = Val(InputBox("输入计算到第几项:", , 0)) s = 0: t = 0For i = 1 To nt = 0For j = 1 To it = t + jNexts = s + tNextPrint sEnd Sub8.Private Sub Command1_Click()Dim s As Double, pi As Doublen = 1: s = 0Do While 1 / (2 * n - 1) >= 0.0001 '也可以是Do Until 1 / (2 * n - 1)< 0.0001s = s + (-1) ^ (n + 1) * 1 / (2 * n - 1)n = n + 1Looppi = 4 * sPrint piEnd Sub9.'5-9:输出所有的“水仙花数”.'所谓的“水仙花数”是指一个3位数,其各位数字的立方和等于该数本身。

VB实验参考答案

VB实验参考答案

VB实验参考答案VB实验参考答案VB(Visual Basic)是一种常用的编程语言,广泛应用于软件开发领域。

在学习VB的过程中,进行实验是非常重要的一部分。

本文将为大家提供一些VB实验的参考答案,帮助大家更好地理解和掌握VB编程。

实验一:简单的计算器程序要求:编写一个简单的计算器程序,能够实现基本的加减乘除运算。

参考答案:```vbPrivate Sub btnCalculate_Click()Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text)num2 = CDbl(txtNum2.Text)If rbAdd.Checked Thenresult = num1 + num2ElseIf rbSubtract.Checked Thenresult = num1 - num2ElseIf rbMultiply.Checked Thenresult = num1 * num2ElseIf rbDivide.Checked ThenIf num2 <> 0 Thenresult = num1 / num2ElseMsgBox("Error: Division by zero!")End IfEnd IftxtResult.Text = resultEnd Sub```实验二:学生成绩管理系统要求:编写一个学生成绩管理系统,能够实现学生信息的录入、查询和统计功能。

参考答案:```vbPrivate Sub btnAdd_Click()Dim name As StringDim score As Integername = txtName.Textscore = CInt(txtScore.Text)lstStudents.Items.Add(name & " - " & score)End SubPrivate Sub btnSearch_Click()Dim searchName As StringDim index As IntegersearchName = txtSearch.Textindex = lstStudents.FindString(searchName)If index <> -1 ThenlstStudents.SelectedIndex = indexElseMsgBox("Student not found!")End IfEnd SubPrivate Sub btnStatistics_Click()Dim totalScore As IntegerDim averageScore As DoubleDim count As IntegerFor Each item As String In lstStudents.ItemsDim score As Integer = CInt(item.Split("-")(1).Trim()) totalScore += scorecount += 1NextaverageScore = totalScore / counttxtTotalScore.Text = totalScoretxtAverageScore.Text = averageScore```实验三:简单的图书管理系统要求:编写一个简单的图书管理系统,能够实现图书信息的录入、查询和删除功能。

vb实验作业参考答案

vb实验作业参考答案

vb实验作业参考答案VB实验作业参考答案引言:Visual Basic(VB)是一种基于事件驱动的编程语言,广泛应用于Windows操作系统的软件开发。

在学习VB编程过程中,实验作业是非常重要的一部分,通过实践来巩固所学知识。

本文将提供一些VB实验作业的参考答案,帮助读者更好地理解和掌握VB编程。

一、VB基础知识实验作业参考答案1. 实验题目:编写一个VB程序,实现两个整数的加法运算,并将结果显示在文本框中。

参考答案:```Private Sub btnAdd_Click()Dim num1 As IntegerDim num2 As IntegerDim result As Integernum1 = CInt(txtNum1.Text)num2 = CInt(txtNum2.Text)result = num1 + num2txtResult.Text = CStr(result)End Sub```2. 实验题目:编写一个VB程序,实现输入一个数字,判断该数字是奇数还是偶数,并在消息框中显示结果。

参考答案:```Private Sub btnCheck_Click()Dim num As Integernum = CInt(txtNum.Text)If num Mod 2 = 0 ThenMsgBox "该数字是偶数"ElseMsgBox "该数字是奇数"End IfEnd Sub```二、VB控件应用实验作业参考答案1. 实验题目:编写一个VB程序,实现一个简单的计算器功能,包括加法、减法、乘法和除法操作。

参考答案:```Private Sub btnAdd_Click()Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text) num2 = CDbl(txtNum2.Text)result = num1 + num2txtResult.Text = CStr(result) End SubPrivate Sub btnSubtract_Click() Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text) num2 = CDbl(txtNum2.Text)result = num1 - num2txtResult.Text = CStr(result) End SubPrivate Sub btnMultiply_Click() Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text) num2 = CDbl(txtNum2.Text)result = num1 * num2txtResult.Text = CStr(result) End SubPrivate Sub btnDivide_Click() Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text)num2 = CDbl(txtNum2.Text)If num2 = 0 ThenMsgBox "除数不能为0"Elseresult = num1 / num2txtResult.Text = CStr(result)End IfEnd Sub```2. 实验题目:编写一个VB程序,实现一个简单的登录界面,包括用户名和密码输入框以及登录按钮。

VB程序设计学习与实验指导答案

VB程序设计学习与实验指导答案

Visual Basic 程序设计学习与实验指导答案上篇学习指导第1章Visual Basic 概述1.事件2.查看对象3.工程4.视图属性窗口5.窗体编辑器第2章面向对象程序设计初步1.控件2.事件3.类属性4.属性5.略第3章Visual Basic 语言基础1.(a*sin(30/180*3.14)+c*(log(b)/log(10)))/((Abs(d)+1)*(e+f))+12.mod3.X=Int(X) And Y=Int(Y) And X*Y>04. 4.Y Mod 4=0 And Y Mod 100<>0 Or Y Mod 400=05.x=Int((99-10+1)*Rnd+10)6.0 “”7.空格8.6,845.309.(1)8(2)1(3)abcd(4)出错,类型不匹配(5)False(6)2008-6-29(7)I likeVB(8)4(9)4 4(10)3 4(11)10 -10(12)-1(13)aa(14)3(15)0(16)1(17)C(18)5(19)8(20)34.54(21)中国(22)上海(23)VISUAL BASIC(24)visual basic10.(1)x<-100 or x>100(2)a=Int(a) And b =Int(b) Or a<0 And b<0(3)x<=y or x>=z(4)a>0 And a<>Int(a)(5)a=0 xor b=0(6)Len(S)<10(7)UCase(S)=S(8)Left(S,1)=”a” And Right(S,1)=”a”(9)Instr(S,”@”)<>0(10)Trim(S)=S(11)Date=#8/8/2008#(12)Weekday(Date)=2第4章程序控制结构与算法基础一.简单填空1.Randomize2.N=Int((99-10+1)*Rnd+10)3.M=(Int((100-10+1)*Rnd+10))/104.Exit For5.Exit Do二.读程序写结果1.150 122.22 23 -13. 5 3 04.20 40 60三.程序填空1.Len(s)Mid(s,i,1)c>=”A” And c<=”Z”c>=”a” And c<=”z”c>=”0” And c<=”9”n3=n3+12.01 n-1n Mod i=0sum+isum=n3.1000CStr(n)CStr(n*n)Right(s2,Len(s1))=s14.100 2002 N-1Exit Forcount+1count Mod 5=0 Print5.sum=1a*x^2/((2*n-1)*(2*n))sum+aAbs(a)<=0.0000001第5章数组的应用1.120 362.10 31 73.26 14 26三.程序填空1.A(i,j);Picture1.PrintA(i.1)1A(i,j)j“第” & i & “行最大数是” & Max Data & “,第” & Maxj & “列”2.Text1.Text & A(i);kpreserve B(k)B(k)=A(i)3.Sqr(n - m) = Int(Sqr(n - m))ReDim Preserve B(k)nA(m) & "和" & B(m)4.Int((100-50+1)*Rnd+50)1B(i)+1第6章过程四.读程序写结果1.x=2,y=2 m=22.9 4,5,9 273.50 264. 5 64,55.7,14 11,22 15,306.29 29 37.12 25下篇实验教程实验2 Visual Basic 变量、函数与表达式的使用实验2-1 算术运算符的使用13178332262-2-22007-10-153 2.857143 2.85714285714286实验2-2 字符运算符的使用20071020071020172007-10-10102007-10-20出错,类型不匹配实验2-3 关系运算符的使用FalseFalseFalseFalseFalseFalseFalseTrueFalseTrue实验2-4 逻辑运算符的使用TrueTrueFalseTrueFalseFalseTrueTrueFalse5-59实验2-5 常用函数的使用3.14 3.147.389056098930651 -1 .999999998205103 4-1 1 0.70554755825 251250 0A a65 9748 688 -98 -89 -9aaa 4.5 aaa4.516 5Visua 6.0sua Basic Basic 6.0abcde EFGBasic Basic BasicVisual Basic 6.0 Basic8 8aaa dd2011-3-152011-3-15 14:35:5215320113001.731.731.7317.32E-010173%实验3 算法基础及程序控制结构实验3-1 三个数的交换A=CC=BB=TBC实验3-2 求周长和面积Const PI=3.14159262*PI*RPI*R*RPicture1.ClsFormat(L, ".00")Format(M, ".00")实验3-3 求分段函数的值x=Val(Text1.Text)y=1+Sin(x)y=Log(x)Text1.Text = ""Text2.Text = ""实验3-4 求一元二次方程的根Val(Text2.Text)Val(Text3.Text)b ^ 2 - 4 * a * c"x1=" & (-b + Sqr(delt)) / (2 * a)"x2=" & (-b - Sqr(delt)) / (2 * a)Text2.Text = ""Text3.Text = ""End实验3-5 判断素数N Mod k = 0k=NN Mod i=0k=2实验3-6 求最大公约数和最小公倍数M<NL=ML=NM Mod k = 0 And N Mod k = 0Text3.Text = kExit ForM>NL=ML=Nk Mod M = 0 And k Mod N = 0Text4.Text = kExit For实验3-7 判断升序数、降序数CStr(N)Len(S) – 1Mid(S, k, 1) >= Mid(S, k + 1, 1)k = Len(S)N = Val(Text1.Text)S = CStr(N)For k = 1 To Len(S) - 1If Mid(S, k, 1) <= Mid(S, k + 1, 1) Then Exit For Next kk = Len(S)实验3-8 判断回文数1Len(s)\2-1Mid(S, k, 1) <> Mid(S, Len(S) - k + 1, 1)k = Len(S) \ 2Mid(S, k, 1) + S1S = S1实验3-9 求级数的值Val(Text1.Text)1x ^ ns * nt / s <= 10 ^ -6Text2.Text = y实验3-10 查找数字串并求和Text1.Text = ""Text2.Text = ""List1.ClearText1.TextFalseWhile Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" Flag = Truek = k * 10 + Mid(s, i, 1)i = i + 1Flag = Truesum + kText2.Text = sum实验3-11 随机产生20个奇数Int((99 - 10 + 1) * Rnd) + 10a Mod 2 = 1n Mod 5 = 0Picture1.Cls实验3-12 加密解密Chr(Asc("a") + (Asc(c) - Asc("a") + 3) Mod 26)c = Chr(Asc("A") + (Asc(c) - Asc("A") + 3) Mod 26) c & s2Text2.TextLen(s2)Mid(s2, i, 1)c = Chr(Asc("a") + (Asc(c) - Asc("a") + 23) Mod 26) c = Chr(Asc("A") + (Asc(c) - Asc("A") + 23) Mod 26) c & s1s1Text1.Text = ""Text2.Text = ""实验3-13 统计单词个数Text1.TextMid(s, i, 1) <> " " And i <= Len(s)i = i + 1Mid(s, start, i - start)nText1.Text = ""List1.Clear实验4 数组的使用实验4-1 一维数组的产生及输出i = 1 To 20Int((9 - 0 + 1) * Rnd + 0)i = 1 To 20Print a(i);Printi = 1 To 20Picture1.Print a(i);If i Mod 5 = 0 Then Picture1.Printi = 1 To 20Text1.Text & Space(2) & a(i)If i Mod 5 = 0 Then Text1.Text = Text1.Text & vbCrLf v In aIf i Mod 5 = 0 Then Picture2.Print实验4-2 选手得分Int((50 - 10 + 1) * Rnd + 10) / 10i = 1 To 6sum = sum + score(i)max = score(1)min = score(1)score(i) > max Then max = score(i)score(i) < min Then min = score(i)(sum - max - min) / 4实验4-3 产生10个互不相同的整数Int((999 - 10 + 1) * Rnd + 10)t Mod 10 = 5Then Exit Forn= n + 1a(i) = tFor i = 1 To 10Print a(i);If i Mod 5 = 0 Then PrintNext i实验4-4 统计数字出现的次数IsNumeric(S) = FalseExit SubLen(S)c >= "0" And c <= "9"A(c) = A(c) + 1A(k) <> 0m = m + 1实验4-5 排序1 To 10Int((99 - 10 + 1) * Rnd + 10)Text1.Text & A(n) & " "1 To 9i + 1 To 10A(i) > A(j)T = A(j)A(j) = A(i)A(i) = T1 To 910 - iA(j) > A(j + 1)T = A(j + 1)A(j + 1) = A(j)A(j) = T1 To 10Text3.Text = Text3.Text & A(i) & " "10T = A(i)ji - 1k + 11 To 10Text4.Text = Text4.Text & A(i) & " "实验4-6 二维数组的产生及输出1 To 41 To 5Int((9 - 0 + 1) * Rnd + 0)1 To 41 To 5Print A(i, j);Print1 To 41 To 5Picture1.Print A(i, j);Picture1.Print1 To 41 To 5Text1.Text = Text1.Text & A(i, j) & " "Text1.Text = Text1.Text & vbCrLf实验4-6 查找最大和最小元素及其位置1 To 31 To 4A(i, j) = Int((99 - 10 + 1) * Rnd + 10)Picture1.Print A(i, j);Picture1.PrintA(1, 1), 1, 1A(1, 1), 1, 1A(i, j)ijA(i, j) < minA(i, j)ij"最大元素" & "A(" & maxi & "," & maxj & ")=" & max "最小元素" & "A(" & mini & "," & minj & ")=" & min实验4-7 矩阵转置Dim A() As Integer"请输入N的值"ReDim A(N, N) As IntegerFor i = 1 To NFor j = 1 To NA(i, j) = Int((99 - 10 + 1) * Rnd + 10)Text1.Text = Text1.Text & A(i, j) & " "Next jText1.Text = Text1.Text & vbCrLfNext it = A(i, j)A(i, j) = A(j, i)A(j, i) = tFor i = 1 To NFor j = 1 To NText2.Text = Text2.Text & A(i, j) & " "Next jText2.Text = Text2.Text & vbCrLfNext i实验5 过程实验5-1 孪生素数和降序素数Dim i As IntegerFor i = 2 To N - 1If N Mod i = 0 Then Exit FunctionNext iPrime = TrueDim a As IntegerDim b As Integera = N \ 10b = N Mod 10If a > b ThenDecNumber = TrueElseDecNumber = FalseEnd If10 To 100Prime(i) = True And Prime(i + 2) = TrueList2.AddItem i & "和" & i + 2DecNumber(i) = True And Prime(i) = TrueList3.AddItem i实验5-2 求多项式和k = 1a = f(x, k)S + ak = k + 1Single As SingleDim i As Integer, a As Singlea = (x + 1) / xFor i = 2 To ka = a * (x + i) / ((2 * i - 1) * x)Next ia实验5-3 进制转换Asc(C) - Asc("A") + 10Left(S, k - 1)Mid(S, k + 1)Change(Mid(S2, i, 1)) * N ^ (0 - i)T1 + T2Tran(8, S)Tran(16, S)Not (C >= "0" And C <= "7" Or C >= "A" And C <= "F" Or C = ".")实验5-4 Armstrong数i As Long, a As Long, b As LongCombo1.Text实验5-5Option Base 1Dim a(5) As IntegerDim b(5) As Integerb(i) = i * i + 1Text2.Text = Text2.Text & b(i) & " "1 To 51 To 5Gcd(a(i), b(j)) = 1Gcd = KExit For实验5-6Create(a)Output(a)Sort(a)Output(a)GetMaxMin(a, MaxData, MinData)MaxDataMinDataAverage(a)Int((99 - 10 + 1) * Rnd + 10)1 To UBound(a)a(i);a(i) > a(j)t = a(j)a(j) = a(i)a(i) = t2 To UBound(a)a(i) > MM = a(i)a(i) < NN = a(i)s = s + a(i)Average = s / UBound(a)实验6 界面设计实验6-1 用户登陆MsgBox "请登录!"PassWordInput=TxtPassW.TextUserIdInput=UserId And PassWordInput=PassWordCmdReset_Click实验6-2 学籍登记OptXb(0).Value = TrueList1.AddItem Space(4) & xh & Space(6) & xm & Space(6) & xb & Space(12) & xy & Space(16) & zy & Space(4)List1.RemoveItem List1.ListIndex实验6-3 字体格式设置Select Case OpFontCheck2.Value = 1OpColor = IndexOpFont = Index实验6-4 兴趣调查List1.AddItem ItemEndSelect Case IndexItem = Text1.Text实验6-5 调色板。

vb实验报告标准答案

vb实验报告标准答案

竭诚为您提供优质文档/双击可除vb实验报告标准答案篇一:Vb郭贤海实验报告及答案实验1.1设计一个程序,程序运行的初始界面如图1-1所示。

当单击“显示”按钮时,在文本框中显示“欢迎使用Vb!”(图1-1);当单击“清除”按钮时,清除文本框内的文本;当单击“退出”按钮时,结束程序运行。

图1-1程序运行初始界面图1-2单击“显示”按钮后的程序界面实验1.2设计一个程序,程序运行的初始界面如图1-3所示,其中“显示”按钮为不可用。

同时要求:(1)当单击“改变文字”按钮时,在左边标签文字内容改为“你好,张三!”,同时“改变文字”按钮变为不可用(图1-4);(2)当单击“隐藏”按钮时,将左边标签设为不可见,同时“隐藏”按钮变为不可用,“显示”按钮变为可用(图1-5);(3)当单击“显示”按钮时,重新显示左边标签,同时“隐藏”按钮变为可用,“显示”按钮变为不可用(图1-4)。

图1-3第1题的程序运行初始界面图1-4单击“改变文字”按钮后的程序界面图1-5单击“隐藏”按钮后的程序界面四、实验原始记录实验1.1程序的界面设计。

(可以是多张主要的图。

下面的图要替换成你们自己设计的图。

如何取图?设计好界面,按“printscreensysRq”键,打开画图软件,单击“编辑|粘贴”命令,利用菜单栏下方的“选定”功能,选中窗体,按“ctrl+c”键,然后选中下面的实验样例图,按“ctrl+V”键,替换掉)程序代码。

privatesubcommand1_click()Text1.Text="欢迎使用Vb!"endsubprivatesubcommand2_click()Text1.Text=""endsubprivatesubcommand3_click()endendsub实验1.2程序的界面设计。

(可以是多张主要的图。

下面的图要替换成你们自己设计的图)程序代码。

privatesubcommand1_click()Label1.Visible=Truecommand2.enabled=Truecommand1.enabled=Falseendsubprivatesubcommand2_click()Label1.Visible=Falsecomma nd2.enabled=Falsecommand1.enabled=Trueendsub privatesubcommand3_click()Label1.caption="你好,张三!"command3.enabled=Falseendsub五、实验结果及分析实验1.1运行结果。

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,由系统指定。

VB6.0程序设计实践教程 习题及答案

VB6.0程序设计实践教程 习题及答案

VB6.0程序设计实践教程习题及答案vb6.0程序设计实践教程习题及答案vb6.0第一章一、判断题1.属性是visualbasic对象性质的描述,对象的数据就保存在属性中。

2.控件的属性值不可以在程序运行时动态地修改。

3.许多属性可以轻易在属性单上设置、修正,并立即在屏幕上看见效果。

4.所谓留存工程,就是指留存正在编辑的工程的窗体。

5.面向对象的程序设计是一种以对象为基础,由事件驱动对象执行的设计方法。

6.为了使一个控件在运行时不可见,应该将该控件的enabled属性设置为false。

7.保存visualbasic文件时,若一个工程包含多个窗体或模块,则系统先保存工程文件,再分别保存各窗体或模块文件。

8.事件就是由visualbasic预先定义的对象能辨识的动作。

9.方法就是visualbasic对象可以适当的用户操作方式。

10.窗体中的控件,是使用工具箱中的工具在窗体上画出的各图形对象。

11.由visualbasic语言编写的应用程序有解释和编译两种执行方式。

12.在关上一个visualbasic工程展开修正后,必须另存为一个版本,只需单击“工程另存为…”就行及,因为系统将同时留存其他文件。

13.当用load命令将窗体装入内存时,一定触发窗体的load事件和activate事件.二、选择题1.要使某个控件不可操作,要对属性进行设置。

a、enabledb、visibalec、captiond、name2.以下不属于对象的基本特征的就是。

a、属性b、方法c、事件d、函数3.当运转程序时,系统自动继续执行启动窗体的事件过程。

a、clickb、loadc、dblclickd、unload4.visualbasic中“程序运行”容许采用的快捷键就是。

a、f2b、f5c、alt+f3d、f85.发生改变控件在窗体中的左右边线应当修正该控件的属性。

a、topb、leftc、widthd、right6.工程文件的拓展名叫。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Visual Basic 程序设计学习与实验指导答案上篇学习指导第1章Visual Basic 概述1.事件2.查看对象3.工程4.视图属性窗口5.窗体编辑器第2章面向对象程序设计初步1.控件2.事件3.类属性4.属性5.略第3章Visual Basic 语言基础1.(a*sin(30/180*3.14)+c*(log(b)/log(10)))/((Abs(d)+1)*(e+f))+12.mod3.X=Int(X) And Y=Int(Y) And X*Y>04. 4.Y Mod 4=0 And Y Mod 100<>0 Or Y Mod 400=05.x=Int((99-10+1)*Rnd+10)6.0 “”7.空格8.6,845.309.(1)8(2)1(3)abcd(4)出错,类型不匹配(5)False(6)2008-6-29(7)I likeVB(8)4(9)4 4(10)3 4(11)10 -10(12)-1(13)aa(14)3(15)0(16)1(17)C(18)5(19)8(20)34.54(21)中国(22)上海(23)VISUAL BASIC(24)visual basic10.(1)x<-100 or x>100(2)a=Int(a) And b =Int(b) Or a<0 And b<0(3)x<=y or x>=z(4)a>0 And a<>Int(a)(5)a=0 xor b=0(6)Len(S)<10(7)UCase(S)=S(8)Left(S,1)=”a” And Right(S,1)=”a”(9)Instr(S,”@”)<>0(10)Trim(S)=S(11)Date=#8/8/2008#(12)Weekday(Date)=2第4章程序控制结构与算法基础一.简单填空1.Randomize2.N=Int((99-10+1)*Rnd+10)3.M=(Int((100-10+1)*Rnd+10))/104.Exit For5.Exit Do二.读程序写结果1.150 122.22 23 -13. 5 3 04.20 40 60三.程序填空1.Len(s)Mid(s,i,1)c>=”A” And c<=”Z”c>=”a” And c<=”z”c>=”0” And c<=”9”n3=n3+12.01 n-1n Mod i=0sum+isum=n3.1000CStr(n)CStr(n*n)Right(s2,Len(s1))=s14.100 2002 N-1Exit Forcount+1count Mod 5=0 Print5.sum=1a*x^2/((2*n-1)*(2*n))sum+aAbs(a)<=0.0000001第5章数组的应用1.120 362.10 31 73.26 14 26三.程序填空1.A(i,j);Picture1.PrintA(i.1)1A(i,j)j“第” & i & “行最大数是” & Max Data & “,第” & Maxj & “列”2.Text1.Text & A(i);kpreserve B(k)B(k)=A(i)3.Sqr(n - m) = Int(Sqr(n - m))ReDim Preserve B(k)nA(m) & "和" & B(m)4.Int((100-50+1)*Rnd+50)1B(i)+1第6章过程四.读程序写结果1.x=2,y=2 m=22.9 4,5,9 273.50 264. 5 64,55.7,14 11,22 15,306.29 29 37.12 25下篇实验教程实验2 Visual Basic 变量、函数与表达式的使用实验2-1 算术运算符的使用13178332262-2-22007-10-153 2.857143 2.85714285714286实验2-2 字符运算符的使用20071020071020172007-10-10102007-10-20出错,类型不匹配实验2-3 关系运算符的使用FalseFalseFalseFalseFalseFalseFalseTrueFalseTrue实验2-4 逻辑运算符的使用TrueTrueFalseTrueFalseFalseTrueTrueFalse5-59实验2-5 常用函数的使用3.14 3.147.389056098930651 -1 .999999998205103 4-1 1 0.70554755825 251250 0A a65 9748 688 -98 -89 -9aaa 4.5 aaa4.516 5Visua 6.0sua Basic Basic 6.0abcde EFGBasic Basic BasicVisual Basic 6.0 Basic8 8aaa dd2011-3-152011-3-15 14:35:5215320113001.731.731.7317.32E-010173%实验3 算法基础及程序控制结构实验3-1 三个数的交换A=CC=BB=TBC实验3-2 求周长和面积Const PI=3.14159262*PI*RPI*R*RPicture1.ClsFormat(L, ".00")Format(M, ".00")实验3-3 求分段函数的值x=Val(Text1.Text)y=1+Sin(x)y=Log(x)Text1.Text = ""Text2.Text = ""实验3-4 求一元二次方程的根Val(Text2.Text)Val(Text3.Text)b ^ 2 - 4 * a * c"x1=" & (-b + Sqr(delt)) / (2 * a)"x2=" & (-b - Sqr(delt)) / (2 * a)Text2.Text = ""Text3.Text = ""End实验3-5 判断素数N Mod k = 0k=NN Mod i=0k=2实验3-6 求最大公约数和最小公倍数M<NL=ML=NM Mod k = 0 And N Mod k = 0Text3.Text = kExit ForM>NL=ML=Nk Mod M = 0 And k Mod N = 0Text4.Text = kExit For实验3-7 判断升序数、降序数CStr(N)Len(S) – 1Mid(S, k, 1) >= Mid(S, k + 1, 1)k = Len(S)N = Val(Text1.Text)S = CStr(N)For k = 1 To Len(S) - 1If Mid(S, k, 1) <= Mid(S, k + 1, 1) Then Exit For Next kk = Len(S)实验3-8 判断回文数1Len(s)\2-1Mid(S, k, 1) <> Mid(S, Len(S) - k + 1, 1)k = Len(S) \ 2Mid(S, k, 1) + S1S = S1实验3-9 求级数的值Val(Text1.Text)1x ^ ns * nt / s <= 10 ^ -6Text2.Text = y实验3-10 查找数字串并求和Text1.Text = ""Text2.Text = ""List1.ClearText1.TextFalseWhile Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" Flag = Truek = k * 10 + Mid(s, i, 1)i = i + 1Flag = Truesum + kText2.Text = sum实验3-11 随机产生20个奇数Int((99 - 10 + 1) * Rnd) + 10a Mod 2 = 1n Mod 5 = 0Picture1.Cls实验3-12 加密解密Chr(Asc("a") + (Asc(c) - Asc("a") + 3) Mod 26)c = Chr(Asc("A") + (Asc(c) - Asc("A") + 3) Mod 26) c & s2Text2.TextLen(s2)Mid(s2, i, 1)c = Chr(Asc("a") + (Asc(c) - Asc("a") + 23) Mod 26) c = Chr(Asc("A") + (Asc(c) - Asc("A") + 23) Mod 26) c & s1s1Text1.Text = ""Text2.Text = ""实验3-13 统计单词个数Text1.TextMid(s, i, 1) <> " " And i <= Len(s)i = i + 1Mid(s, start, i - start)nText1.Text = ""List1.Clear实验4 数组的使用实验4-1 一维数组的产生及输出i = 1 To 20Int((9 - 0 + 1) * Rnd + 0)i = 1 To 20Print a(i);Printi = 1 To 20Picture1.Print a(i);If i Mod 5 = 0 Then Picture1.Printi = 1 To 20Text1.Text & Space(2) & a(i)If i Mod 5 = 0 Then Text1.Text = Text1.Text & vbCrLf v In aIf i Mod 5 = 0 Then Picture2.Print实验4-2 选手得分Int((50 - 10 + 1) * Rnd + 10) / 10i = 1 To 6sum = sum + score(i)max = score(1)min = score(1)score(i) > max Then max = score(i)score(i) < min Then min = score(i)(sum - max - min) / 4实验4-3 产生10个互不相同的整数Int((999 - 10 + 1) * Rnd + 10)t Mod 10 = 5Then Exit Forn= n + 1a(i) = tFor i = 1 To 10Print a(i);If i Mod 5 = 0 Then PrintNext i实验4-4 统计数字出现的次数IsNumeric(S) = FalseExit SubLen(S)c >= "0" And c <= "9"A(c) = A(c) + 1A(k) <> 0m = m + 1实验4-5 排序1 To 10Int((99 - 10 + 1) * Rnd + 10)Text1.Text & A(n) & " "1 To 9i + 1 To 10A(i) > A(j)T = A(j)A(j) = A(i)A(i) = T1 To 910 - iA(j) > A(j + 1)T = A(j + 1)A(j + 1) = A(j)A(j) = T1 To 10Text3.Text = Text3.Text & A(i) & " "10T = A(i)ji - 1k + 11 To 10Text4.Text = Text4.Text & A(i) & " "实验4-6 二维数组的产生及输出1 To 41 To 5Int((9 - 0 + 1) * Rnd + 0)1 To 41 To 5Print A(i, j);Print1 To 41 To 5Picture1.Print A(i, j);Picture1.Print1 To 41 To 5Text1.Text = Text1.Text & A(i, j) & " "Text1.Text = Text1.Text & vbCrLf实验4-6 查找最大和最小元素及其位置1 To 31 To 4A(i, j) = Int((99 - 10 + 1) * Rnd + 10)Picture1.Print A(i, j);Picture1.PrintA(1, 1), 1, 1A(1, 1), 1, 1A(i, j)ijA(i, j) < minA(i, j)ij"最大元素" & "A(" & maxi & "," & maxj & ")=" & max "最小元素" & "A(" & mini & "," & minj & ")=" & min实验4-7 矩阵转置Dim A() As Integer"请输入N的值"ReDim A(N, N) As IntegerFor i = 1 To NFor j = 1 To NA(i, j) = Int((99 - 10 + 1) * Rnd + 10)Text1.Text = Text1.Text & A(i, j) & " "Next jText1.Text = Text1.Text & vbCrLfNext it = A(i, j)A(i, j) = A(j, i)A(j, i) = tFor i = 1 To NFor j = 1 To NText2.Text = Text2.Text & A(i, j) & " "Next jText2.Text = Text2.Text & vbCrLfNext i实验5 过程实验5-1 孪生素数和降序素数Dim i As IntegerFor i = 2 To N - 1If N Mod i = 0 Then Exit FunctionNext iPrime = TrueDim a As IntegerDim b As Integera = N \ 10b = N Mod 10If a > b ThenDecNumber = TrueElseDecNumber = FalseEnd If10 To 100Prime(i) = True And Prime(i + 2) = TrueList2.AddItem i & "和" & i + 2DecNumber(i) = True And Prime(i) = TrueList3.AddItem i实验5-2 求多项式和k = 1a = f(x, k)S + ak = k + 1Single As SingleDim i As Integer, a As Singlea = (x + 1) / xFor i = 2 To ka = a * (x + i) / ((2 * i - 1) * x)Next ia实验5-3 进制转换Asc(C) - Asc("A") + 10Left(S, k - 1)Mid(S, k + 1)Change(Mid(S2, i, 1)) * N ^ (0 - i)T1 + T2Tran(8, S)Tran(16, S)Not (C >= "0" And C <= "7" Or C >= "A" And C <= "F" Or C = ".")实验5-4 Armstrong数i As Long, a As Long, b As LongCombo1.Text实验5-5Option Base 1Dim a(5) As IntegerDim b(5) As Integerb(i) = i * i + 1Text2.Text = Text2.Text & b(i) & " "1 To 51 To 5Gcd(a(i), b(j)) = 1Gcd = KExit For实验5-6Create(a)Output(a)Sort(a)Output(a)GetMaxMin(a, MaxData, MinData)MaxDataMinDataAverage(a)Int((99 - 10 + 1) * Rnd + 10)1 To UBound(a)a(i);a(i) > a(j)t = a(j)a(j) = a(i)a(i) = t2 To UBound(a)a(i) > MM = a(i)a(i) < NN = a(i)s = s + a(i)Average = s / UBound(a)实验6 界面设计实验6-1 用户登陆MsgBox "请登录!"PassWordInput=TxtPassW.TextUserIdInput=UserId And PassWordInput=PassWordCmdReset_Click实验6-2 学籍登记OptXb(0).Value = TrueList1.AddItem Space(4) & xh & Space(6) & xm & Space(6) & xb & Space(12) & xy & Space(16) & zy & Space(4)List1.RemoveItem List1.ListIndex实验6-3 字体格式设置Select Case OpFontCheck2.Value = 1OpColor = IndexOpFont = Index实验6-4 兴趣调查List1.AddItem ItemEndSelect Case IndexItem = Text1.Text实验6-5 调色板。

相关文档
最新文档