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-5 CDCCB 640ABDCD 11-15 CCBBD 16-20 DBCBA二多选1 ABCE 2CE 3 BCE 4 ADE 5 ABCD6ABCDE 7ACD8ABCDE 9 ABC 10ABCDE三判断1-5 X V X V V6-10 V X V V V四填空1 x=int(Rnd*101)End If avg=s/82 i=l to 10Right(str(i),l)或Right(str(i mod 10))3 m*n/GCD(m,n)GCD(b, a mod b)4 Exit For i & “是素数”Next i五阅读程序1-4 DDCB六程序设计1Option Base 1Private Sub Form_click()Dim a( 10)Ciscreatedata a()sort a()Fori= ITo 10Print a(i);Next iEnd SubSub createdata(a())Fori = ITo 10a(i) = Int(Rnd * 101)Next iEnd SubSub sort(a())For i = 1 To 9Forj = 1 To 10-iIf a(j) > a(j + l)Thent = a(j): a(j) = a(j + 1): a(j + 1) = tEnd IfNext jNext iEnd Sub2Private Type ksno As String * 8Bscj As IntegerSjcj As IntegerEnd TypeDim student As ksPrivate Sub Form_Load()Open "c:\ksxx.dat" For Random As#l Len = Len(student)End SubPrivate Sub cmdadd_Click()student.no = Text 1.Textstudent.Bscj = Val(Text2.Text)student.Sjcj = Vai (Tex t3.Text)lastrecord = LOF( 1) / Len(student) + 1Put # 1, lastrecord, studentTextl.Text =Text2.Text = ””Text3.Text ="End SubPrivate Sub cmdquit_Click()Close #1EndEnd Sub1-5 CABCD理论练习二6-10 ABCCD 11-15 BBBAB1 CD2 AD3CE4BC6BCDE7CDE8ABCDE9 ABD三判断二多选1-5 X X X X V 6-10 V V V X X 16-20 DBAAC5 AD10ACDE1n-l 或者Sqr (n)02X y3 1 to 102*i-14Button=2start=True 五阅读程序1-5DBDAB六程序设计1Private Sub Form_click()四填空japan = 47528china = 22257n = 0 True — (x, y)Do While china <= japanchina = china * 1.098japan = japan * 1.028 n= n + 1LoopPrint n & ”年之后,中国GDP将超过日本”End Sub•VB6中的Split函数,其功能足将一字符巾用分界符分割为一字符串数组。

青岛科技大学VB上机实验答案

青岛科技大学VB上机实验答案

实验一 VB环境和简单应用程序设计(4个学时)一、实验目的1.熟悉Visual Basic集成开发环境的使用。

2.掌握建立、编辑和运行简单的Visual Basic应用程序的全过程。

3.掌握窗体对象的属性、事件和方法。

二、实验内容1. 在VB的集成开发环境中实现如下的操作:1)、将“标准”工具栏去掉后再添加上,将“编辑”工具栏添上再去掉。

2)、分别利用“菜单”和“工具栏”中的命令打开“属性窗口”、“工程资源管理器窗口”3)、将“窗体布局窗口“的”启动位置“设置成“手工”。

4)、在工具箱中任意添加一个Active X 控件。

5)、在工程1中增加两个窗体:Form1、Form26)、在工程1中增加两个标准模块:Module1 、Module27)、在工程1中增加一个类模块:Class18)、在工程资源管理器中将Form2、Module2 删除。

9)、在在工程资源管理器中利用“切换文件夹”按钮隐藏或显示对象的文件夹10)、将代码窗口中的字体大小改为18号字。

2.设计一个窗体,窗体内有1个文本框和3个命令按钮控件。

要求:当按“显示”按扭时,在文本框内显示“欢迎来到青岛科技大学!”一串红色、四号、隶书字符串。

当按“清除”按钮时,清除文本框内全部信息;当按“退出”按钮时,结束程序运行。

1) 创建界面(将设计好的界面截下来粘贴在下面)3)代码设计Private Sub Command1_Click()T ext1.T ext = "欢迎来到青岛科技大学!"End SubPrivate Sub Command2_Click()T ext1.T ext = ""End SubPrivate Sub Command3_Click()EndEnd Sub4)调试过程记录(错误情况及改正方法,不得少于三条)1、text1与text颠倒了位置通过查课本改正3. 设计一个窗体,在窗体上添加一个文本框和三个命令按钮。

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%()。

visual basic 程序设计课后习题参考答案

visual basic 程序设计课后习题参考答案
6
[Exit Function] End Function
(4). Function 过程的调用方法: ①直接调用 像使用 VB 内部函数一样,只需写出函数名
和相应的参数即可 ②用 Call 语句调用 与调用 Sub 过程一样来调用 Function
过程,当用这种方法调用 Function 过程时,将会放弃返回值 3、简述 VB 过程中参数传递的两种方式。
第五章 数 组
4
一、选择题
1 2 3 4 5 6 7 8 9 10 DADEBBCCC A
二、填空题
1 2、12、1、3、-1、2 0123 2222
2 2101 4444
3 name、index 4 preserve、erase 5 ubound、lbound
第六章 过 程
一、选择题
1 2 3 4 5 6 7 8 9 10 DCDCBABAB D 11 12 13 14 15 16 17 18 19 20 ACCDABCDB C
二、填空题
1 bas 2 形式、实际 3 a()、Ubound(b)、n=n-1 4 30、70 5 fedcba、static
三、简答题
6 static 7 static 8 12、7 9 visual basic 程序设计 10 -100
1、简述事件过程和通用过程的含义和联系。
5
VB 应用程序是由过程组成的,过程是完成某种特殊功能的一 组独立的程序代码。VB 中的过程有两大类:事件过程和通用过程
Visual basic 程序设计习题参考答案
第一章 Visual basic 程序设计
一、选择题
1 2 3 4 5 6 7 8 9 10
DC
CDCBAC B

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

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

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

中职VB程序设计(第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程序设计学习与实验指导答案-推荐下载

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

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语言程序设计课后编程及上机调试参考答案

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程序设计教程(第3版)课后实验答案

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

习题二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语言程序设计课后编程及上机调试参考答案

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练习题(上机)含答案

VB练习题(上机)含答案VB练习题(上机)含答案第一部分1 在窗体上添加一个命令按钮(名称为Cmd1,标题为"输出平均值")。

程序运行后,单击命令按钮完成以下工作:①随机产生20个0到1000的整数,将其放入一个一维数组中②求出所有元素的平均值,并显示在窗体上(如下图所示)Private Sub Cmd1_Click()Dim a%(19), i%, sum!, aver!RandomizeFor i = 0 To 19a(i) = Int(Rnd * 1001)sum = sum + a(i)Next iaver = sum / 20Print averEnd Sub2 请在名称为Form1的窗体上添加一个名称为Text1的文本框和一个名称为C1、标题为"转换"的命令按钮,如下图所示。

在程序运行时,单击"转换"按钮,可以把Text1中的小写字母转换为大写,把大写字母转换为小写,其他字符不变。

Private Sub C1_Click()Dim ch As String, ch1 As String, i%ch = Text1For i = 1 To Len(ch)If Asc(Mid(ch, i, 1)) >= 65 And Asc(Mid(ch, i, 1)) <= 90 Thench1 = ch1 + LCase(Mid(ch, i, 1)) Elsech1 = ch1 + UCase(Mid(ch, i, 1)) End IfNext iText1 = Text1 + vbCrLfText1 = Text1 + ch1End Sub3 在窗体上添加一个命令按钮(名称为MyCmd1,标题为"输出最大值")。

程序运行后,单击命令按钮完成以下工作:①随机产生30个0~1000的整数,将其放入一个一维数组中②求出其中的最大值,并显示在窗体上。

VB程序设计学习与实验指导书答案(包含实验答案)

VB程序设计学习与实验指导书答案(包含实验答案)

VB学习与实验指导测试题参考答案第一章第二章第三章第四章第五章第六章第七章第八章第九章综合测试题一综合测试题二下篇实验教程实验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程序设计课后习题答案在学习VB程序设计过程中,课后习题是巩固知识、提高编程能力的重要环节。

本文将为大家提供一些VB程序设计课后习题的答案,希望能够帮助大家更好地理解和掌握相关知识。

1. 编写一个VB程序,实现计算两个数的和、差、积、商的功能。

答案:```vbPrivate Sub btnCalculate_Click()Dim num1 As DoubleDim num2 As Doublenum1 = CDbl(txtNum1.Text)num2 = CDbl(txtNum2.Text)lblSum.Caption = "和:" & num1 + num2lblDifference.Caption = "差:" & num1 - num2lblProduct.Caption = "积:" & num1 * num2If num2 <> 0 ThenlblQuotient.Caption = "商:" & num1 / num2ElselblQuotient.Caption = "除数不能为0"End IfEnd Sub```2. 编写一个VB程序,实现判断一个数是否为素数的功能。

答案:```vbPrivate Sub btnCheckPrime_Click()Dim num As IntegerDim i As IntegerDim isPrime As Booleannum = CInt(txtNum.Text)isPrime = TrueIf num < 2 ThenlblResult.Caption = "不是素数"Exit SubEnd IfFor i = 2 To Int(Sqr(num))If num Mod i = 0 ThenisPrime = FalseExit ForEnd IfNext iIf isPrime ThenlblResult.Caption = "是素数"ElselblResult.Caption = "不是素数"End IfEnd Sub```3. 编写一个VB程序,实现将一个字符串中的大写字母转换为小写字母,小写字母转换为大写字母的功能。

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。

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.工程文件的拓展名叫。

【参考文档】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 = 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运行初始界面:运行结果:。

相关文档
最新文档