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

程序代码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实验答案

计算机VB实验内容实验二1. 《实践指导》P10,实验1,设计一个加法器程序(请参考本次实验中实例2)。

(程序实际运行效果可参考程序“Prg3.exe” )保存要求:(1)在lab02文件夹中新建子文件夹“prg3”,用于保存本题的程序;(2)将本题的工程文件命名为“project3.vbp”,窗体文件命名为“form3.frm”。

注:该题的第5项要求中关于“同时第一个文本框获得焦点”部分不要求实现过程Private Sub Command1_Click()Dim a As Single, b As Single, c As Singlea = Val(Text1.Text)b = Val(Text2.Text)c = a + bLabel2 = cEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Label2 = ""End Sub2. 编写一个标签变化程序(请参考本次实验中实例题1来完成,如下图1所示)(程序实际运行效果可参考程序“Prg4.exe” )保存要求:(1)在lab02文件夹中新建子文件夹“prg4”,用于保存本题的程序;(2)将本题的工程文件命名为“project4.vbp”,窗体文件命名为“form4.frm”。

设计要求:(1)单击窗体(Form1),则窗体打印输出文字“你点击了窗体”(如下图2所示)(2)单击按钮Command1,则在Label1中显示“你点击了按钮Command1,请进入”,字体大小15磅,字体为宋体(如下图3所示)(3)单击按钮Command2,Label1显示“你点击了按钮Command2,请离开”,字体大小25磅,字体为黑体(如下图4所示)(图1)(图2)(图3)(图4)过程Private Sub Command1_Click()Label1.FontSize = 15Label1.FontName = "宋体"Label1 = "你点击了按钮Command1,请进入"End SubPrivate Sub Command2_Click()Label1.FontSize = 25Label1.FontName = "黑体"Label1 = "你点击了按钮Command2,请离开"End SubPrivate Sub Form_Click()Form1.Print "你点击了窗体"End Sub实验三二、设计题1.《实践指导》P20,实验3。

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实验指导书_理论综合练习题_答案(完结版)

VB实验指导书_理论综合练习题_答案(完结版)

第二部分综合练习理论练习一一单选1-5 CDCCB 6-10 ABDCD 11-15 CCBBD 16-20 DBCBA 二多选1 ABCE2 CE3 BCE4 ADE5 ABCD6 ABCDE7 ACD8 ABCDE9 ABC 10 ABCDE三判断1-5×√×√√6-10 √×√√√四填空、1 x=int(Rnd*101) End If avg=s/82 i=1 to 10 Right(str(i),1) 或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)Clscreatedata a()sort a()For i = 1 To 10Print a(i);Next iEnd SubSub createdata(a())For i = 1 To 10a(i) = Int(Rnd * 101)Next iEnd SubSub sort(a())For i = 1 To 9For j = 1 To 10 - iIf a(j) > a(j + 1) 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 #1 Len = Len(student) End SubPrivate Sub cmdadd_Click()student.no = Text1.Textstudent.Bscj = V al(Text2.Text)student.Sjcj = V al(Text3.Text)lastrecord = LOF(1) / Len(student) + 1Put #1, lastrecord, studentText1.Text = ""Text2.Text = ""Text3.Text = ""End SubPrivate Sub cmdquit_Click()Close #1EndEnd Sub理论练习二一单选1-5 CABCD 6-10 ABCCD 11-15 BBBAB 16-20 DBAAC 二多选1 CD2 AD3 CE4 BC5 AD6 BCDE7 CDE8 ABCDE9 ABD 10 ACDE三判断1-5××××√6-10 √√√××四填空1 n-1 或者Sqr(n) 0 True2 x y3 1 to 10 2*i-14 Button=2 start=True -(x,y)五阅读程序1-5 DBDAB六程序设计1Private Sub Form_click()japan = 47528china = 22257n = 0Do While china <= japanchina = china * 1.098japan = japan * 1.028n = n + 1LoopPrint n & "年之后,中国GDP将超过日本"End Sub2' VB6中的Split函数,其功能是将一字符串用分界符分割为一字符串数组。

VB实验报告答案 txt

VB实验报告答案 txt
Label2 = "弧度" & Text1 & "转换为" & aa & "度" & bb & "分" & cc & "秒"
End Sub
方法二
Private Sub Command1_Click()
x = InputBox("请输入弧度数值", "弧度转换", 0)
xx = Val(x)
Dim x!, a!, aa%, b!, bb%, c!, cc$
x = Val(Text1)
a = x * 180 / 3.14
aa = Int(a)
b = (a - aa) * 60
bb = Int(b)
c = (b - bb) * 60
cc = Format(c, "#.000")
If x > y Then
t = x: x = y: y = t
End If
End If
Label1 = x & Space(5) & y & Space(5) & z
End Sub
2-4
方法一
Private Sub Command1_Click()
x = Val(InputBox("请输入上网时间:"))
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()

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

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

自测1程序代码Private Sub Command1_Click() Labell .FontSize = Labell .FontSize + 3End SubPrivate Sub Command2_Click() Label1 .FontBold = TrueEnd SubPrivate Sub Command3_Click() Label1 .FontUnderline = TrueEnd SubPrivate Sub Command4_Click() Label1 .FontSize = 10Label1 .FontBold = False Label1 .FontUnderline = FalseEnd Sub初始窗口:单机放大之后窗口: 单机下划线之后窗口:单击加粗之后窗口: 单击还原之后窗口:自测2程序代码Private Sub Command1_Click() Labell = "visual basic"Textl ="程序设计题"End SubPrivate Sub Command2_Click() Text1 = "visual basic"Label1 ="程序设计题"End Sub初始窗口:交换显示 单击显示之后窗口:FormlFormlTestivi SU ^L L basic 程序设计题 显示单击交换之后的窗口:自测题3Private Sub Comma nd1_Click()Labell.Fo ntSize = Labell.Fo ntSize * (0.5)End SubPrivate Sub Comma nd2_Click() Label1.Top = Label1.Top + 30 Label1.Width = Label1.Width + 20Label1.Alig nment = 1 End Sub初始窗口:单击缩小两倍之后的窗口:单击向右下角移动之后的窗口:缩小两倍标签的属性设畳向右下角移动自测题4程序代码Private Sub Command1_Click() Forml.Caption = "VB 学习"Print "简单的VB程序设计"End SubPrivate Sub Command2_Click()乌FormlClsEnd SubPrivate Sub Command3_Click() EndEnd SubPrivate Sub Command3_Click() EndEnd Sub初始化窗口:单击显示之后的窗口:单击清除之后的窗口:单击退出之后的窗口:ih 191 - vHuiJ tMH :Hi*E! M1£| *凹 T»c.i ffisa:1 «2'耳11也 n^Li ftft? Ulil> 井回 ■一阖 耳储凹 £J - U- ' # ■ X ■甩腐 I G c I 卜 II ・对 EF 曲曽 41M41 0 Ifl] - Fermi (fern^ n 2 口Q -0Cl Pciml CI IS :-陶E 4 gdH撑 4 JT.KjS .兰I□ 30 B^1«L QftLj0 F GE L £T H II■It • Form 】«婀田判踽砸1>:■»?:>i*fF^iruch I - ]| 花Unftabav F faSiU F K K-L-T□ 卿值疏瞬 fc<r-Ur3«.ylB t - S LCI I I L H r-H h- pi^Capi.Tii-iTrwC-E^riLIra Ev«4.J. R •皿[T-U1IJI.I EulL.J FilK-L-r 皿口讣“ F L U• ■■FAfruBTr-irvCiLo- Trw 13 -亡■卄 Jui tf -矗Li 4T IM w'-mlrw自测题5 程序代码Private Sub Command1_Click()Textl .Text =""Text2 .Text =""End SubPrivate Sub Command2_Click()Text3 .Text = Val(Text1 .Text) + Val(Text2 .Text) End SubPrivate Sub Command3_Click()EndEnd Sub初始化窗口:单击运算之后窗口:单击清除之后的窗口:单击退出之后的窗口ItfHal -魯工cgn冋咅13MIE-當eH._*w 酉軽-A E Jlq -卑巨m ^BAD区,F «E -iK y >3L ■•■二・®C F 爭味*6£3|1ss-privaCDSubcommancHIC-ick()DimaSa HTexf ︱k.TexfLabe-︱k.capfion HLeft?2)EndSubprivaCDSubCommand2lc-ick()a HTexf ︱k.TexfLabe-2.capfion HRighf?2)EndSubprivaCDSub Command3lc-ick()H a- H a --F s IX-Textl.Text = Labell.Caption & Label2.Caption End Sub初始窗口界面输入字符串截取前两个字符Forml I =回]M7Kr wciainiwo漓鯉两平斗截哑診个付字符串连接截取后两个字符字符串连接Forml I = | 回]WT wornniwo截勢载疇个ps;自测练习2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f%, g%, h%, i%, j%, k%, l% a = 7349e = a Mod 10 '个位d = (a \ 10) Mod 10 ' 十位c = (a \ 100) Mod 10 ' 百位b = a \ 1000 ' 千位i = (e + 7) Mod 10 ' 个位h = (d + 7) Mod 10 ' 十位g = (c + 7) Mod 10 ' 百位f = (b + 7) Mod 10 ' 千位j = ii = f ' 交换后的个位f = j ' 交换后的千位k = hh = g '交换后的十位g = k '交换后的百位l = f * 1000 + g * 100 + h * 10 + i Text1.Visible = False加密后的结果是Print" 加密前的4位整数是7439"; (Chr(10));" ";lEnd Sub初始界面单击窗体运行后的界面自测练习1Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(lnputBox(" 输入第一个数","输入一个数",8))b = Val(InputBox(" 输入第一个数","输入一个数",7))c = a + bd = a - be = a * bf = a / bf = Fix(f * 100 + 0.5) / 100MsgBox "x+y=" & c & Chr(10) & "x-y=" & d & Chr(10) & "x*y=" & e & Chr(10) & "x/y=" & f,," 输出的结果"End Sub瑾出的结果塔x+y=15x-y=l x*y=56 如"4自测练习2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(lnputBox(" 输入第一个数的值"))b = Val(InputBox(" 输入第二个数的值"))c = Val(InputBox(" 输入第三个数的值"))d =Val(InputBox(" 输入第四个数的值")) e = a + b + c + dPrin t "和=";e Print" 平均值=";f End Sub0 Forml 口回I—SWT 和二10 平均值二2 5自测练习3Private Sub Form_Click()Dim h%, f%, x%, y%h = Val(lnputBox(" 输入总头数")) f = Val(InputBox(" 输入总脚数")) x = (4 * h - f) / 2y = (f - 2 * h) / 2Print "笼中鸡的头数为";x;" 只" Print"笼中兔的头数为";y;" 只"End Sub自测练习1:Private Sub Form_Click() Dim a%, b%, c%a = Val(lnputBox(" 请输入第一条边","边长"))b = Val(lnputBox(" 请输入第二条边","边长"))c = Val(lnputBox(" 请输入第三条边","边长")) If a + b > c And a + c > b And b + c > a The nIf a * a + b * b = c * c Or a * a + c * c = b * b Or b * b c * c = a * a The n Pri nt " 直角"ElseIf a =b And b = c The nPri nt " 等边三角形"ElseIf a =b Or a = c Or b = c The nPri nt " 等腰三角形"ElsePri nt " 般三角形"End IfElsePri nt " 不是三角形"End IfEnd Sub不是三角形运行结果: 初始窗口:输入三条边:运行结果:直角三角形运行结果:等边三角形运行结果如下: 等腰三角形:般三角形自测练习2:Private Sub Form_Click()Dim a%, b!a = Val(l nputBox(" 请输入"))If a Mod 2 = 0 And a Mod 3 = 0 And a Mod 5 = 0 Then b = Sqr(a) Pri nt a, bElseEndEnd IfEnd Sub初始化窗口:输入一个数:运行结果:自测练习3Private Sub Comma nd1_Click()Dim a%, b%a = Val(Text1.Text)Select Case a > 0Case a < 20MsgBox "行李费为0.2元/kg",," 行李费" Case a >= 20 And a < 50MsgBox "行李费为0.3元/kg",," 行李费" Case a >= 50 And a < 100MsgBox "行李费为0.4元/kg",," 行李费”Case Else元",,"行李费"End SelectEnd Sub 初始窗口:输入10: 输入25: 输入55:输入120:自测练习1Option Base 1Private Sub Form_Click() Dim i%, a(1 To 20) As In tegera(1) = 1: a(2) = 1Pri nt a(1);Pri nt a(2);Fori = 3 To 10a(i) = a(i - 1) + a(i - 2) Pri nt a(i);Next iPri ntFori = 11 To 16a(i) = a(i - 1) + a(i - 2) Pri nt a(i);Next iPri ntFor i = 17 To 20a(i) = a(i - 1) + a(i - 2) Pri nt a(i);Next i初始界面:运行结果界面:上Forml I = | 回IWT1 123 5 8 13 21 34 5539 144 233 377 610 9E7159TT 2504 4101 6765自测练习2Option Base 1Private Sub Form_Load()Forml.Width = 10000Form1.Height = 5000End SubPrivate Sub Comma nd1_Click()Dim i%, j%, t%, a(1 To 4, 1 To 4) As In teger For i = 1 To 4 Forj = 1 To 4a(i, j) = In t(R nd * 10) + 1Picturel.Pri nt a(i, j);Next jPicture1.Pri ntNext iPicture3.Print" 对角线的元素如下”For i = 1 To 4Picture3.Pri nt a(i, i);Next iPicture3.Pri ntFor i = 1 To 4Picture3.Pri nt a(i, 5 - i);Next iFor i = 1 To 4t = a(1, i) a(1, i) = a(4, i)a(4, i) = tNext iFor i = 1 To 4t = a(i, 2)a(i, 2) = a(i, 3)a(i, 3) = tNext iFor i = 1 To 4Forj = 1 To 4 Picture2.Pri nt a(i, j); Next jPicture2.Pri nt Next iEnd Sub运行初始界面:运行结果界面:自测练习1Sub itostr(a As In teger) Dim b%, c$a = Val(Textl.Text)While a >= 1c = Chr(a Mod 10 + 48) & ca = a \ 10WendText2.Text = cEnd SubPrivate Sub Comma nd1_Click() Dim a As In tegera = Val(Text1.Text)Call itostr(a)End Sub运行初始界面:运行结果界面:0 Forml 口虽验证其他数字:自测练习2:Public Fun cti on area( n) As Double Dim c#, d#, e#, s#n 二Val(Text2.Text)c = (1 - 0) / nWhile e <= 1d = I * c:e = (I + 1) * cs = s + (Si n(d) + Si n(e)) * c / 2I = I + 1Wendarea = sEnd Fun cti onPrivate Sub Comma nd1_Click() Dim s As DoubleCall area( n)Text1.Text = area (n)End Sub运行初始界面:运行结果:自测练习3Private Sub Form_click()n 二Val(lnputBox(" 请输入n 的值"))x = Val(lnputBox(" 请输入x 的值"))Pri nt "e 的值二";es( n, x)End SubPrivate Fun cti on es(n, x)Dim a As Double, b As Double, c As Double, i As In teger a = 1: b = 1: c = 1For i = 1 To na = x * a:b = b * i:c = c + a / bNext ies = cEnd Fun cti on运行初始界面:输入数据:。

VB实验教材的实验、习题答案

VB实验教材的实验、习题答案

第一章VB开发环境与VB概述习题答案习题一、选择题第二章常用控件与界面设计习题答案习题一、选择题第三章实验与习题实验实验3_1…算术运算Private Sub Command1_Click()Const a As Single = 3, b As Single = 2, c As Single = -1, d As Single = 6Dim x As Single, y As Single, z As Single, m As Singlex = 2: y = 1: z = 1: m = 1List1.ClearList1.AddItem a / (b + c / b)List1.AddItem (x + Sqr(x ^ 2 + 1)) ^ (1 / 3)List1.AddItem ((2 * y) / (a * x + b * y) * (a * x - b * y))List1.AddItem 1 + 1 / (1 + 1 / m)List1.AddItem 1 / 2 * (d / 3) ^ (2 * x)List1.AddItem Log(y + Cos(x) ^ 2)List1.AddItem Abs((Exp(x) + Sin(x) ^ 3) / (x + y))List1.AddItem Log((Exp(x * y) + Abs(1 / Tan(z) + Cos(x) ^ 3)) / (x + y - z))List1.AddItem Sin(45 * 3.1415 / 180) + (Exp(10) + Log(10)) / Sqr(x + y + 1) List1.AddItem Log(a) / Log(b)End Sub…关系运算Private Sub Command2_Click()List1.ClearList1.AddItem Mid("Visual Basic", 1, 12) = Right("Language Visual Basic", 12) List1.AddItem "ABCRG" >= "abcde"List1.AddItem Int(134.69) >= CInt(134.9)List1.AddItem 78.9 / 32.77 <= 97.5 / 43.87 And -45.4 > -4.98List1.AddItem Str(32.345) = CStr(32.345)End Sub…逻辑运算Private Sub Command3_Click()Dim x As Integer, y As IntegerDim C1 As Integer, C2 As Integer, C3 As IntegerC1 = 70: C2 = 80: C3 = 90x = 9: y = -2List1.ClearList1.AddItem x + y < 10 And x - y > 0List1.AddItem (x% >= 0 And y% >= 0) Or (x% < 0 And y% < 0)List1.AddItem x = 0 Xor y = 0List1.AddItem C1 + C2 + C3 >= 255 Or C1 > 90 And C2 > 90 And C3 > 80End Sub实验3_2略实验3_3略实验3_4…零售结算Private Sub Command1_Click()Dim dj As Single, sl As Single, je As Single, n As IntegerLabel1.Caption = "金额:"dj = InputBox("请输入商品的单价:", "单价框")sl = InputBox("请输入商品的数量:", "数量框", 1)je = dj * sln = MsgBox("共计金额=" & je, vbOKCancel + vbInformation, "结果") If n = vbOK Then Label1.Caption = "金额:" & Str(je) & "元"End Sub…产生随机数Private Sub Command2_Click()Dim m As Integer, n As IntegerDim x1 As Integer, x2 As Integer, x3 As Integerm = V al(Text1.Text): n = Text2.TextRandomizex1 = Int(Rnd * (n - m + 1) + m)x2 = Int(Rnd * (n - m + 1) + m)x3 = Int(Rnd * (n - m + 1) + m)Label4.Caption = "结果为:" & Str(x1) & Str(x2) & Str(x3)End Sub…求逆序数Private Sub Command3_Click()Dim a As Integer, h As Integer, t As Integer, n As IntegerRandomizea = Int(Rnd * (999 - 100 + 1) + 100)h = Mid(CStr(a), 1, 1)t = Mid(CStr(a), 2, 1)n = Right(CStr(a), 1)Label5.Caption = a & "-->" & Format(n * 100 + t * 10 + h, "000")End Sub实验3_5略习题选择题填空题1、2 -32768~327672、整型长整型单精度双精度3、0 False “”4、Chr(Int(Rnd*(Asc(“L”)-Asc(“C”))+Asc(“C”)))x>0 And y>0 Or x<0 And y<0c>=”a” And c<=”z” Or c>=”A” And c<=”Z”x>=10 And x<20x<z Xor y<z5、False2TrueFalseTrueTrueTrueTrue6、18820010068.568765547、a=1 b=1a=2 b=1a=3 b=1a=4 b=18、Y Mod 4=0 And Y Mod 100<>0 Or Y Mod 400 =09、He Said, “Good morning”.10、EDEF11、(A>0 And A<>Int(A)) And (B<0 And B<>Int(B))12、a+b+c+d(a+b+c+d)/4sumaver13、(f-2*h)/2(4*h-f)/2简答题1、略2、Private Sub Form_Click()Const g = 9.8Dim V0 As Single, t As SingleDim S As SingleV0 = InputBox("请输入V0的值:")t = InputBox("请输入时间t的值:")S = (1 / 2) * g * t ^ 2 + V0 * tMsgBox ("位移量为:" & S)End Sub3、Private Sub Command1_Click()Dim l As Single, w As Single, h As SingleDim s As Singlel = Text1.Textw = Text2.Texth = Text3.Texts = (l * w + l * h + w * h) * 2Label1.Caption = sEnd Sub第四章选择分支与循环实验答案实验4-1方法一:x<=5 ; y方法二:Is<=2 ;Case Else实验4-2Shape1.BackColor=vbRed;Inter=15;Inter=Inter-1;Inter;实验4-3b<cb=aa=k实验4-4方法二:s*n ; t/s<10^-5实验4-5方法一:m>=10^-4 ; (-1)^(n+1)*m实验4-6x2=x3 ; <10^-6实验4-7实验4-8i+2*j+5*k=10 ; n实验4-9题目一:a) 5b)i=16 p=12 n=5c)i=9 p=8 n=1题目二:120 10实验4-10N=1 ;S=N& "*3 " & "+1 "实验4-11Len(st); Ch=Lcase(ch) ; Case Else ; Mid(Char,I,1)&St实验4-12i\100 ; (i Mod 100)\10习题一、选择题二、填空题1.Is=0 ; 1 To 10 ; Is >102. 93. 3 ; 4 154. this is a book ;This Is A Book5. 3 ; 3 ; 3 56. 32 07. 48. 15 19. 1 ; 401 ;10410. 1 2 3 ;1 3; 111. (3)12. 2 0 2413. 10 1414. BAABC CBAABC15. X Mod P=0 ; X=X+1 ;Find=False16. abs(t)<10^(-7) ; s+t17. Mid(n,1,1)=Mid(n,2,1) And Mid(n,3,1)=Mid(n,4,1)S=S+118. Mid(n,i,1)>Mid(n,i+1,1)19. "输入n";N/I=0 ;Print I第五章数组实验5_1Int(90 * Rnd) + 10a(i) = a(21 - i)a(21 - i) = t5_2k = x Mod 10i = i + 15_3s5_4max < a(i, j)row = Icol = j5_51ReDim Preserve prime(m)prime(j)5_6d Mod 25_7Exit Fora(j + 1) = a(j)5_8N – IA(j) = A(j + 1)5_9A(i, 1)JMin = MaxNot Flag5_10ch >= "0" And ch <= "9"P = P & chReDim Preserve C(k)5_11Private Sub Form_Click()Dim x As Integer, i As Integer, k As Integer, j As Integer Dim a() As Integerx = InputBox("输入正整数x=")i = 2Print x; "的质因子为:";Do While x >= iIf x Mod i = 0 Thenk = k + 1ReDim Preserve a(k)a(k) = ix = x \ iElsei = i + 1End IfLoopFor j = 1 To UBound(a)Print a(j);Next jEnd Sub习题一选择题二填空题1.V ariant2.ReDim A(N)A(1)If M < A(I) Then M = A(I)3.Int(26 * Rnd) + 65Chr(t)i + 1 To 10A(i) > A(j)4.InStr(s, ",")Right(s, Len(s) - n)s5. 4 5 66 5 43 2 16.T – 1I + 17.k = 6 - i – jmax = m8.j = aj = j - 39.i + 1i = i + 110. 237三编程题1.Option ExplicitOption Base 1Private Sub Command1_Click()Dim a(10) As IntegerDim i As Integer, max As IntegerFor i = 1 To 10a(i) = Int(90 * Rnd) + 10Print a(i);Next iPrinti = 1max = 0Do While i <= 10If a(i) Mod 3 = 0 ThenIf a(i) > max Thenmax = a(i)End IfEnd Ifi = i + 1LoopIf max = 0 ThenPrint "无要找的数"ElsePrint max & "是最大的能被3整除的数"End IfEnd Sub2.Option ExplicitOption Base 1Private Sub Command1_Click()Dim A() As IntegerDim I As Integer, m As IntegerDim K As IntegerReDim A(10)For I = 1 To 10A(I) = IPrint A(I);Next IPrintm = InputBox("ÊäÈëm")K = 9 + mReDim Preserve A(K)For I = 11 To KA(I) = A(I - 10)Next IFor I = 1 To 10A(I) = A(I + m - 1)Next IFor I = 1 To 10Print A(I);Next IPrintEnd Sub3.Option ExplicitPrivate Sub Command1_Click()Dim I As Integer, J As Integer, K As IntegerDim a() As Integer, n As Integer, p As IntegerDim s As String, Flag As Booleanp = 1For K = 10 To 100I = 1Do While I <= 10 And Not FlagJ = 1Do While J <= 10 And Not Flagn = I ^ 2 + J ^ 2If n = K ThenFlag = TrueReDim Preserve a(p)a(p) = Kp = p + 1s = I & Str(J) & Str(K)List1.AddItem sEnd IfJ = J + 1LoopI = I + 1LoopFlag = FalseNext KEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim A(10) As IntegerDim B(10) As Integer, S As StringDim I As Integer, J As Integer, X As IntegerA(1) = Int(90 * Rnd) + 10S = A(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = A(J) Then Exit ForNext JIf J = I ThenA(I) = XS = S & " " & A(I)Exit DoEnd IfLoopNext IText1.Text = SB(1) = Int(90 * Rnd) + 10S = B(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = B(J) Then Exit ForNext JIf J = I ThenB(I) = XS = S & " " & B(I)Exit DoEnd IfLoopNext IText2.Text = SS = ""For I = 1 To 10For J = 1 To 10If A(I) = B(J) ThenS = S & " " & A(I)End IfNext JNext IText3.Text = SEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim I As Integer, J As IntegerDim a() As Integer, K As Integer, Sum As Integer K = V al(Text1.Text)I = 1DoJ = K Mod 10ReDim Preserve a(I)a(I) = JSum = Sum + JK = K \ 10I = I + 1Loop Until K = 0Text2.Text = SumEnd Sub6.Option ExplicitPrivate Sub Command1_Click()Dim a(100, 2) As Integer, K As IntegerDim I As Integer, J As IntegerDim M As Integer, N As IntegerK = 1For I = 1 To 99For J = 1 To 99If I > J ThenM = I - JN = I + JIf Sqr(M) = Int(Sqr(M)) And Sqr(N) = Int(Sqr(N)) ThenList1.AddItem I & " " & Ja(K, 1) = Ia(K, 2) = JK = K + 1End IfEnd IfNext JNext IEnd Sub第六章参考答案实验实验6-11、Exit Do2、Y(X)3、X >= -1实验6-2【题目二】42 、26、8实验6-31、s1, key2、s As String3、ch >= "a" And ch <= "z"4、Mid(s, i, 1) = Chr(Asc(ch) + k - 26)思考:解密函数Private Sub dec(s As String, k As Integer) '解密过程Dim i As Integer, ch As String * 1For i = 1 To Len(s)ch = Mid(s, i, 1)If "A" <= ch And ch <= "Z" ThenIf Asc(ch) - k < Asc("A") ThenMid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于A的ASCII值则加上26 ElseMid(s, i, 1) = Chr(Asc(ch) - k)End IfElseIf ch >= "a" And ch <= "z" Then '多分支格式,ch介于小写a与z之间If Asc(ch) - k < Asc("a") ThenMid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于a的ASCII值则加上26ElseMid(s, i, 1) = Chr(Asc(ch) - k)End IfEnd IfNext iEnd Sub实验6-41、b() As Integer, st As String2、L <= R3、ReDim Preserve b(R)4、L = L + 1辗转相除法求最大公约数函数Private Function Gcd(ByV al p As Integer, ByV al q As Integer) As IntegerDim r As Integerr = p Mod qDo While r <> 0p = qq = rr = p Mod qLoopGcd = qEnd Function实验6-5【题目一】age = age(n - 1) - 3【题目二】1、(Left + Right) / 22、Left = Mid + 1实验6-61、3 -12、7 43、3 -14、7 0实验6-7【题目一】1、Sqr(2 + t)2、Abs(a - 1) < eps【题目二】1、Dim X As Integer2、"S(" & I & ")=" & S(I)3、(j * i + 1)习题参考答案一选择题二、填空1(1)形式、(2)实在2(1)按地址传递、(2)ByV al3(1)窗体模块、(2)标准模块、(3)类模块4(1) 65(1)4 20 1016(1) 6 26 、(2)-2 987(1)10 6 、(2) 5 -58(1) 6 5 、(2)8 79(1)11 、(2)710(1)Fun(i) 、(2)Fun=p11(1) 4 、(2)20.712(1)29 、(2)28.713(1)k = j 、(2)b() As Integer14(1)gec 、(2)ge 、(3) 315(1)p1 = True And p2 = True 或p1 And p2 、(2)p1 = p2 – 2 、(3)Isp = True 、(4)m Mod i = 016(1)Convert(st) 、(2)Len(s) 、(3)"A" To "F" 、(4)k = k + p * h17(1)isualVi 、(2)sualV isu18(1)s + a 、(2)n + 1 、(3)x As Single, n As Integer 、(4)p * (x + i) / ((2 * i - 1) * i * x) 三、改错题1、Option Base 1Private Sub Command1_Click()Dim A() As Integer, I As Integer, J As Integer, Logic As BooleanDim K As IntegerReDim A(1)A(1) = 50————————'K=1For I = 51 To 149K = 1 '位置错Logic = FalseCall Sub1(A, I, Logic)If Logic ThenK = K + 1ReDim A(K) 'ReDim Preserve A(K)A(K) = IEnd IfNext IFor I = 1 To UBound(A)Text1 = Text1 & Str$(A(I))If I Mod 5 = 0 Then Text1 = Text1 & vbCrLfNext IEnd SubPrivate Sub Sub1(A() As Integer, N As Integer, F As Boolean)Dim I As Integer, J As Integer, Ub As IntegerUb = UBound(A)For I = 1 To UbFor J = 2 To A(I)If A(I) Mod J = 0 And N Mod J = 0 ThenExit For 'Exit SubEnd IfNext JF = TrueNext IEnd Sub2、Option ExplicitOption Base 1Private Sub Command1_Click()Dim I As Integer, Flg As Boolean, S1 As Integer, S2 As IntegerDim J As Integer, K As Integer, P() As IntegerReDim P(1)P(1) = 2For I = 3 To 150 Step 2For J = 2 To Sqr(I)If I Mod J = 0 Then Exit ForNext JIf J > Sqr(I) ThenReDim Preserve P(UBound(P) + 1)P(UBound(P) + 1) = I 'P(UBound(P)) = IEnd IfNext IFor I = 80 To 125If fun(I, P, S1, S2) Then 'If fun(I, P, S1, S2)Text1 = Text1 & Str$(I) & "=" & Str(S1) & "*" & Str$(S2) & vbCrLf End IfNext IEnd SubPrivate Function fun(N As Integer, P() As Integer, S1 As Integer, S2 As Integer) As Boolean Dim I As Integer, J As IntegerFor I = 1 To UBound(P)For J = 1 To UBound(P) - 1If N = P(I) * P(J) ThenS1 = P(I)S2 = P(J)'fun = TrueExit Functionfun = True '位置错End IfNext JNext IEnd Function3、Option ExplicitPrivate Sub Get_Chess(Chess() As Integer, idx As Integer, Over As Integer) 'ByV al idx As IntegerDim Ub As Integer, Counter As Integer, K As IntegerUb = UBound(Chess)Chess(idx) = 0Counter = 1K = 0 '位置错Do Until Counter = Ub - 1Do Until K = 2idx = idx + 1If idx > Ub Then idx = 1K = K + Chess(idx)LoopChess(idx) = 0Counter = Counter + 1LoopFor Over = 1 To UbIf Chess(Over) <> 0 Then Exit ForNext OverEnd SubPrivate Sub Command1_Click()Dim Chess(32) As Integer, I As Integer, J As IntegerDim K As Integer, idx As IntegerFor I = 1 To 32For J = 1 To 32Chess(J) = 1Next JCall Get_Chess(Chess, I, K)If K = 23 ThenText1 = "从第" & Str$(I) & "号棋子开始取"Exit ForEnd IfNext IEnd Sub5、Option ExplicitPrivate Sub Form_Click()Dim S As String, Flg As BooleanDoS = InputBox("输入一个自然数")If S = "" Or Not IsNumeric(S) ThenMsgBox "请重新输入", 48 + vbOKOnlyElseExit DoEnd IfLoopjudge(S, Flg) ' Call judge(S, Flg) 或judge S, Flg If Flg ThenPrint S; "是回文数"ElsePrint S; "不是回文数"End IfEnd SubPrivate Sub judge(Ch As String, F As Boolean)Dim L As Integer, I As IntegerL = Len(Ch)F = True ' F = FalseFor I = 1 To LIf Mid$(Ch, I, 1) <> Mid$(Ch, L + 1 - I, 1) Then Exit Sub Next IF = False ' F = TrueEnd Sub四、编程题1、编程验证任一大于2的偶数可以表示成两个素数之和。

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

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实验指导后题目-参考答案

vb实验指导后题目-参考答案

期末自测题(A卷)文件部分的选择题要做,其它类型的题目不用做,不作考察选择题其它部分还没有时间做一、单选题(每题1分,共25分)1、211.66.160.1 是Internet上的( )。

(A) IP地址 (B)域名 (C)密码 (D)软件编号2、在以下四个www网址中,()网址不符合www网址书写规则。

(A) (B) (C) (D) 3、下列字符中,其ASCII码值最小的一个是()。

(A) A (B) a (C) Z (D) X4、下列软件中属于浏览器的是()。

(A) Excel (B) Internet Explorer (C) QQ (D) Visual Basic5、电子邮件(E-mail)地址的正确形式是()。

(A)用户名@域名 (B)用户名#域名 (C)用户名/域名 (D)用户名.域名6、下面变量名不合法的是()。

(A) a2 (B) abcd (C) a$x (D) Cd_E7、下列表达式中,正确的Visual Basic表达式是()。

(A) 2sin45° (B) ∏*R2 (C) x÷y×5 (D) (x+1)/(x^2+1)/28、下面逻辑表达式的值为真的是()。

(A) "A"> "a" (B) "abc"> "bc"(C) "That"> "Thank" (D) 12> 12.19、下列过程定义语句说明不合法的是()。

(A) Sub f1(ByRef n() As Integer) (B) Sub f1(ByRef n As Integer)(C) Sub f1(ByVal n() As Integer) (D) Sub f1(ByVal n As Integer)10、执行下面的4个打印语句,将出错的是()。

VB实验及答案

VB实验及答案

对象名称
属性名称
Form1
Caption
Command1 Caption
Label1
Caption
Label2
Caption
Label3
Caption
Text1、Text2 Text
属性值 象限判断 判断 X= Y=
(3)编写事件代码: Private Sub Command1_Click() Dim x!, y!
Private Sub Command2_Click() Dim f!, c! c = Val(Text2.Text) f = 9 / 5 * c + 32 Text1 = Str(f)
End Sub
(4)程序的运行及保存。 4 求圆的面积及圆柱体的体积,界面如图 2-3 所示。
【步骤】 (1)设计应用程序的界面:在窗体上创建两个命令按钮 Command1 和 Command2,四个标签 Label1、Label2、Label3 和 Label4,四个文本框 Text1、Text2、Text3 和 Text4。 (2)设置对象的属性
【步骤】
( 1 ) 在 窗 体 中 创 建 一 个 标 签 Label1 、 一 个 命 令 按 钮 Command1。
(2)在属性窗口中设置对象的属性:
对象名称
属性名称
属性值
Form1
Caption
设计界面
Label1
Caption
请留意此处
Command1
Caption
单击此处
(3)在 Command1 的 Click 事件中编写程序代码:
x = Val(Text1) y = Val(Text2) If x > 0 Then

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

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实验指导书-测试题答案

营销1042第1章测试题答案一、AABD第2章测试题答案一、BCDACACC二、1.Gotfocus2.Lostfocus3.Setfocus4.Style,15.S(165)6.Vbp7. 18. ScrollBars三、1.答:Private Sub Form_Click()Form1.BackColor = vbBlue End SubPrivate Sub Form_DblClick() Form1.BackColor = vbRed End Sub2.答:(1)若在设计状态完成:(2)若在运行状态完成:编写窗体的Load事件过程如下:Private Sub Form_Load()Form1.BackColor = vbWhiteLabel1.Caption = "欢迎使用VB6.0!"Label1.ForeColor = vbYellowLabel1.BackColor = vbBlueLabel1.FontName = "黑体"Label1.FontItalic = TrueLabel1.FontSize = 20End Sub第3章测试题答案一、BBDBCADA二、1.True ”cde”2.”bcd”-123.True ”abc123xy”4.A*exp(-2*t)*sin(50*t+ 3) 5.4/3*3.1416*r^3 6.Long & 7.Double # 8.关系逻辑第4章测试题答案一、BBBAB ADBDA ADBAC二、1.判断奇偶数InputBox("输入一个整数")If a Mod 2 = 1 ThenElseMsgBox a & "是偶数"2.计算Y值Val(Text1.Text)x > 100 Thenx > 0 ThenElse3.购物优惠xVB实验指导书测试题答案Is > 5000 Is > 3000 Is > 2000 Is > 1000 Case Else 4.1+2+。

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实验任务5答案

VB实验任务5答案

实验任务5课程名称:程序设计基础VB实验名称——实验五Visual Basic程序设计基础(1)一、实验目的:1.掌握变量的定义和赋值2.掌握各种类型的数据的使用3.掌握各种运算表达式的值和使用二、实验内容(包括实验要求(题目)、实验步骤、程序清单、运行情况):实验1(1) 请分别在窗体的单击事件过程中声明定义如下变量,记录错误类型,并分析出错原因,将出错的变量名进行修改, 使其不再出错。

P59Visual Basic代码中要声明和命名一些元素(变量、常量、数据类型、过程等),命名时必须遵循以下规则:●必须以字母或汉字开头,由字母、汉字、数字或下划线组成。

●字符必须并排书写,不能出现上下标形式。

●长度小于等于255个字符。

●不可以是系统关键字。

●不可以包含空格、西文标点符号和类型说明符%、&、!、#、@、$。

●在作用域范围内必须唯一。

Private Sub Form_Click()Dim 5Fg As Integer’错在数字开头,修正为FgDim L*og As Long’错在内部包含*,修正为LogDim s-ig As Single’错在内部包含-,修正为sigDim dob_ As Double‘正确Dim _Name As string ’错在_开头,修正为Name_Dim bln@Frag As Boolean’错在内部包含@,修正为blnFragDim do As Date ’错在是系统关键字,修正为dEnd Sub,并分析出错原因)运行时,单击窗体会出现“溢出错误”的提示;分析出错原因:32768超出了Integer变量Fg的表示范围①32768(或-32768、-32769)——对Fg整型变量赋值32768或-32769,运行时,单击窗体会出现“溢出错误”的提示;分析出错原因:32768和-32769超出了Integer变量Fg的表示范围②32768(或-32768、-32769) ——对Log长整型变量赋值,运行时,单击窗体会正常显示接收的值;分析原因:32768(或-32768、-32769)都没有超出Long长整型变量Log的表示范围③1234567.12345678(或123456789.123、1.2345678)——对sig单精度变量赋值1234567.12345678,运行时,单击窗体会显示1234567;分析原因:在Visual Basic中规定单精度浮点数精度即有效位数为7位,单精度型和双精度型常量的小数形式若超出有效位数,进行小数部分的截取;对sig单精度变量赋值123456789.123,运行时,单击窗体会显示1.234568E+08;分析原因:在Visual Basic中规定单精度浮点数精度即有效位数为7位,若整数部分超出有效位数,自动转为指数形式表示;对sig单精度变量赋值1.2345678,运行时,单击窗体会显示1.234568;分析原因:在Visual Basic中规定单精度浮点数精度即有效位数为7位,单精度型和双精度型常量的小数形式若超出有效位数,进行小数部分的截取④1234567.12345678(或123456789.123、1.2345678)——对dob_双精度变量赋值,运行时,单击窗体会正常显示接收的值;分析原因:在Visual Basic中规定双精度浮点数精度为15~16位。

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

实验一2.Private Sub Command1_Click() Label1.ForeColor = vbRedEnd SubPrivate Sub Command2_Click() Label1.BackColor = vbBlueEnd SubPrivate Sub Command3_Click() Label1.ForeColor = Form1.ForeColor Label1.BackColor = Form1.BackColor End SubPrivate Sub Command4_Click()EndEnd Sub3.Private Sub Command1_Click()Text1.FontSize = 30Command1.Enabled = False Command2.Enabled = True Command3.Enabled = TrueEnd SubPrivate Sub Command2_Click()Text1.FontSize = 6Command2.Enabled = False Command1.Enabled = True Command3.Enabled = TrueEnd SubPrivate Sub Command3_Click()Text1.FontSize = 9Command3.Enabled = False Command1.Enabled = True Command2.Enabled = TrueEnd Sub4.Private Sub Command1_Click()a = 3.14r = Val(Text1.Text)Text2.Text = 2 * a * rText3.Text = a * r * rEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text3.Text = ""End SubPrivate Sub Command3_Click()EndEnd Sub5.Private Sub Command1_Click()Label1.BorderStyle = 1End SubPrivate Sub Command2_Click()Label1.Left = Label1.Left + 200Label1.Top = Label1.Top - 150End SubPrivate Sub Command3_Click()Label1.Visible = FalseEnd SubPrivate Sub Command4_Click()Label1.Visible = TrueEnd Sub6.Private Sub Command1_Click()Text2.Text = Text1.SelTextText3.Text = Text1.SelLengthText1.Locked = TrueEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd Sub7.Private Sub Command1_Click()Dim r, q, vq = Val(Text2.Text)r = Val(Text1.Text)v = Val(Text3.Text)Label5.Caption = r * 60 * 60 + q * 60 + v End SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text2.SetFocusText3.SetFocusEnd SubPrivate Sub Command3_Click()EndEnd SubPrivate Sub Text1_keypress(keyascii As Integer) If keyascii = 13 Then Text2.SetFocusEnd SubPrivate Sub Text2_keypress(keyascii As Integer) If keyascii = 13 Then Text3.SetFocusEnd Sub8.(1)Dim a, v, s, cPrivate Sub Text1_KeyPress(KeyAscii As Integer) a = Val(Text1.Text)If KeyAscii = 13 Thenv = a * a * as = 6 * a * ac = 4 * aLabel5.Caption = vLabel6.Caption = sText2.Text = cEnd IfEnd Sub(2)Dim a, s, v, cPrivate Sub Text1_LostFocus()a = Val(Text1.Text)c = 12 * av = a * a * as = 6 * a * ac = Val(Text2.Text)Label5.Caption = vLabel6.Caption = sEnd Sub(3)Dim a, v, s, cPrivate Sub Text1_Change()a = Val(Text1.Text)v = a * a * as = 6 * a * ac = 12 * aLabel5.Caption = vLabel6.Caption = sText2.Text = cEnd Sub实验二2.Private Sub Picture1_Click()a = Int(Val(Text1.Text) / 100)b = Int((Val(Text1.Text) Mod 100) / 10)c = Int((Val(Text1.Text) Mod 100) Mod 10)d = a * a + b * b + c * cPicture1.Print a; b; c; dEnd Sub3.Private Sub Command1_Click()a = Val(Text1.Text)b = Val(Text2.Text)s = a / bText3.Text = Format(s, "###.##")Text4.Text = a \ bText5.Text = a Mod bEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""Text5.Text = ""Text1.SetFocusEnd SubPrivate Sub Command3_Click()EndEnd Sub4.Private Sub Command1_Click()a = Val(Text1.Text)b = Val(Text2.Text)Picture1.Print Int(Rnd * (b - a + 1) + a); Picture1.Print Int(Rnd * (b - a + 1) + a); Picture1.Print Int(Rnd * (b - a + 1) + a)t1 = Int(Rnd * (b - a + 1) + a)t2 = Int(Rnd * (b - a + 1) + a)t3 = Int(Rnd * (b - a + 1) + a)s = Sqr(t1 + t2 + t3)f = Format(s, "##.####")Picture1.Print "三个数和的平方根" & "=" & f End SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text1.SetFocusEnd SubPrivate Sub Command3_Click()EndEnd Sub5.Private Sub Form_Load()Text1.Text = ""Text2.Text = ""End SubPrivate Sub Text2_KeyPress(KeyAscii As Integer) Dim i, xIf KeyAscii = 13 ThenIf Len(Text1) > 25 Theni = InStr(Text1, Text2)x = Left(Text1, i - 1) + Mid(Text1, i + Len(Text2)) End IfEnd IfPicture1.Print xEnd Sub6.Private Sub Command1_Click()RandomizeText1.FontSize = Text1.FontSize * Int(Rnd * 3 + 2) Command1.Enabled = FalseCommand2.Enabled = TrueCommand3.Enabled = TrueEnd SubPrivate Sub Command2_Click()RandomizeText1.FontSize = Text1.FontSize / Int(Rnd * 3 + 2) Command1.Enabled = TrueCommand2.Enabled = FalseCommand3.Enabled = TrueEnd SubPrivate Sub Command3_Click()Text1.FontSize = 9Command1.Enabled = TrueCommand2.Enabled = TrueCommand3.Enabled = FalseEnd Sub实验三2.Private Sub Form_Click()FontItalic = TruePrint "斜体→程序设计语言"FontName = "黑体"Print "黑体→程序设计语言"FontName = "幼圆"Print "幼圆→程序设计语言"FontName = "楷体_gb2312"Print "楷体→程序设计语言"FontName = "隶书"Print "隶书→程序设计语言"FontName = "@宋体"Print "设置宋体字体旋转"End Sub3.Private Sub Command1_Click()Dim a&, day&, hour&, minute&, second&a = Val(Text1.Text)day = Int(a \ 86400)hour = Int((a Mod 86400) \ 3600)minute = Int((a Mod 3600) \ 60)second = Int(a Mod 60)Picture1.Print a&; "秒" & "=" & day&; "天" & hour&; "小时" & minute&; "分" & second; "秒" End Sub4.Private Sub Command1_Click()r = InputBox("输入圆半径")Text1.Text = rLabel5.Caption = 3.14 * r * rLabel6.Caption = 4 * 3.14 * r * rLabel7.Caption = 4 / 3 * 3.14 * r * r * rEnd SubPrivate Sub Command2_Click()Label5.Caption = ""Label6.Caption = ""Label7.Caption = ""Text1.SetFocusText1.Text = ""End Sub6.Private Sub Command1_Click()Dim H%, F%, X%, Y%H = Val(Text1.Text)F = Val(Text2.Text)X = (4 * H - F) / 2Y = (F - 2 * H) / 2Picture1.Print "鸡的数量"; XPicture1.Print "兔子的数量"; YEnd SubPrivate Sub Command2_Click()Label3.Caption = ""Text1.Text = ""Text2.Text = ""Text1.SetFocusEnd Sub7.Private Sub Form_Load()Text1.Text = ""Text2.Text = ""Label4.Caption = ""End SubPrivate Sub Text2_KeyPress(KeyAscii As Integer) Dim p, dIf KeyAscii = 13 Thenp = Val(Text1.Text)d = Val(Text2.Text)s = p * dc = s - (s * 0.005 + s * 0.015 + s * 0.035 + 27.83) Label4.Caption = Format(c, "####.##")End IfEnd Sub实验四2.Private Sub Command1_Click()a = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)If a + b > c Or a + c > b Or b + c > a Thenp = (a + b + c) / 2s = Sqr(p * (p - a) * (p - b) * (p - c))Label5.Caption = Format(s, "#00.000")ElseMsgBox "不能构成三角形"End IfEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Label5.Caption = ""Text1.SetFocusEnd SubPrivate Sub Command3_Click()EndEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text2.SetFocusEnd SubPrivate Sub Text1_LostFocus()If Not IsNumeric(Text1.Text) ThenMsgBox "输入错误!重新输入"Text1.Text = ""Text1.SetFocusEnd IfEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text3.SetFocusEnd SubPrivate Sub Text2_LostFocus()If Not IsNumeric(Text2.Text) ThenMsgBox "输入错误!重新输入"Text2.Text = ""Text2.SetFocusEnd IfEnd SubPrivate Sub Text3_LostFocus()If Not IsNumeric(Text1.Text) ThenMsgBox "输入错误!重新输入"Text3.Text = ""Text3.SetFocusEnd IfEnd Sub3.Private Sub Command1_Click()a = Val(Text1.Text)b = Val(Text2.Text)Select Case Text3.TextCase "+"Text4.Text = a + bCase "-"Text4.Text = a - bCase "*"Text4.Text = a * bCase "/"If b = 0 ThenMsgBox "除数为零"Text2.Text = ""ElseText4.Text = a / bEnd IfCase "\"If b = 0 ThenMsgBox "除数为零"Text2.Text = ""ElseText4.Text = a \ bEnd IfCase "mod"Text4.Text = a Mod bCase "^"Text4.Text = a ^ bEnd SelectEnd SubPrivate Sub Command2_Click() Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""Text1.SetFocusEnd SubPrivate Sub Command3_Click() EndEnd SubPrivate Sub Form_Load()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""End SubPrivate Sub Text1_LostFocus()If Not IsNumeric(Text1.Text) ThenMsgBox "输入出错!重新输入"Text1.Text = ""Text1.SetFocusEnd IfEnd SubPrivate Sub Text2_LostFocus()If Not IsNumeric(Text2.Text) ThenMsgBox "输入错误!重新输入"Text2.Text = ""Text2.SetFocusEnd IfEnd Sub6.Private Sub Text1_LostFocus()If Not IsNumeric(Text1.Text) ThenMsgBox "不是数字,重新输入!"Text1.Text = ""Text1.SetFocusEnd IfEnd SubPrivate Sub Text2_LostFocus()If Not IsNumeric(Text2.Text) ThenMsgBox "不是数字,重新输入!"Text2.Text = ""Text2.SetFocusEnd IfEnd SubPrivate Sub Text3_LostFocus()If Not IsNumeric(Text3.Text) ThenMsgBox "不是数字,重新输入!"Text3.Text = ""Text3.SetFocusEnd IfEnd SubPrivate Sub Form_Load()Text1.Text = ""Text2.Text = ""Text3.Text = ""End SubPrivate Sub Text3_KeyPress(KeyAscii As Integer) If KeyAscii = 13 ThenDim a(0 To 2) As Integera(0) = InputBox("输入第一个数字", 输入, 0)a(1) = InputBox("输入第二个数字", 输入, 0)a(2) = InputBox("输入第三个数字", 输入, 0)For j = 1 To 2For i = 0 To 2 - jIf a(i) < a(i + 1) Then t = a(i): a(i) = a(i + 1): a(i + 1) = t Next iNext jPicture1.Print a(0); ">"; a(1); ">"; a(2)End IfEnd Sub7.Private Sub Command1_Click()Dim a As Integera = Val(Text1.Text)If (a Mod 400) = 0 ThenLabel3.Caption = "是闰年"ElseLabel3.Caption = "不是闰年"End IfSelect Case Text2.TextCase 1, 3, 5, 7, 8, 10, 12Label5.Caption = 31Case 2If (a Mod 400) = 0 ThenLabel5.Caption = 28ElseLabel5.Caption = 29End IfCase 4, 6, 9, 11Label5.Caption = 30End SelectSelect Case Text2.TextCase 12, 1, 2Label4.Caption = "冬季"Case 3, 4, 5Label4.Caption = "春季"Case 6, 7, 8Label4.Caption = "夏季"Case 9, 10, 11Label4.Caption = "秋季"End SelectEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Picture1.ClsPicture2.ClsPicture3.ClsText1.SetFocusEnd Sub8.Private Sub Form_Click()a = Val(InputBox("M1"))b = Val(InputBox("M2"))c = Val(InputBox("M3"))d = (a + b + c) / 3If d > 95 ThenPrint "一等奖"End IfIf a = 100 And b = 100 And c >= 80 Or a = 100 And c = 100 And b >= 80 Or c = 100 And b = 100 And a >= 80 ThenPrint "一等奖"End IfIf d > 90 ThenPrint "二等奖"End IfIf a = 100 And b >= 75 And c >= 75 Or b = 100 And c >= 75 And b >= 75 Or c = 100 And b >= 75 And a >= 75 ThenPrint "二等奖"End IfIf a >= 70 And b >= 70 And c >= 70 ThenPrint "三等奖"End IfEnd Sub实验五2.Private Sub Picture1_Click()For n = 2 To 1000If n = n ^ 2 Mod 10 Then Picture1.Print nIf n = n ^ 2 Mod 100 Then Picture1.Print nIf n = n ^ 2 Mod 1000 Then Picture1.Print nNext nEnd Sub3.Private Sub Command1_Click()Dim n%, s$, t As Strings = 0n = 0For x = 10 To 10000If x Mod 3 = 2 Or x Mod 5 = 3 Or x Mod 7 = 2 Then t = t & x & vbCrLfn = n + 1s = s + xEnd IfNext xText1.Text = tPicture1.Print "数的和" & sPicture1.Print "数的个数" & nEnd SubPrivate Sub Command2_Click()Dim n%, s$, t As Strings = 0n = 0x = 10Do While x < 10000If x Mod 3 = 2 Or x Mod 5 = 3 Or x Mod 7 = 2 Then t = t & x & vbCrLfn = n + 1s = s + xEnd Ifx = x + 1LoopText1.Text = tPicture1.Print "数的和" & sPicture1.Print "数的个数" & nEnd Sub5.Private Sub Picture1_Click()Dim n%, s%n = Val(InputBox("n值"))s = 0For i = 1 To ns = s + i ^ 2NextPicture1.Print sEnd SubPrivate Sub Picture2_Click()Dim n As Integern = V al(InputBox("输入n值"))sum = 0Dim a1 As DoubleDim a2 As DoubleDim a As DoubleDim sum As Doublea1 = 1a2 = 1For i = 1 To nt = a1 + a2a1 = a2a2 = ta = a2 / a1sum = sum + aNext iPicture2.Print sumEnd SubPrivate Sub Picture3_Click() Dim n%, s%n = Val(InputBox("n值"))s = 0a1 = 1a2 = 1For i = 1 To nt = a1 * a2Next iPicture3.Print sEnd SubPrivate Sub Picture4_Click() Dim i, n As Integer, s As Double n = Val(InputBox("n值"))If n >= 1 ThenFor i = 1 To nt = 5 * 10 ^ na = t + 5 * 10 ^ ns = s + tNext iPicture4.Print sEnd IfEnd SubPrivate Sub Picture5_Click() Dim i, n As IntegerDim s As Singlen = Val(InputBox("n值"))For i = 1 To ns = s + (-1) ^ (i + 1) * (1 / i) Next it = Format(s, "##0.#######") Picture5.Print tEnd Sub8.Private Sub Command2_Click() Picture1.ClsEnd SubPrivate Sub Command1_Click() For n = 6 To 1000k = 0For x = 1 To n / 2If n Mod x = 0 Thenk = k + xEnd IfNext xIf k = n ThenPicture1.Print kEnd IfNext nEnd Sub10.Private Sub Form_Click()For i = 1 To 9For a = 1 To iPrint Tab(20 - i);NextFor n = 1 To iPrint Trim(n);NextFor s = n - 2 To 1 Step -1Print Trim(s);NextPrintNextEnd Sub实验六2.Private Sub Form_Click()Dim a(100)RandomizeMax = 20Min = 100s = 0n = 0For i = 1 To 100a(i) = Int(Rnd * 81 + 20)Picture1.Print a(i);If i / 10 = i \ 10 Then Picture1.PrintIf a(i) > Max Then Max = a(i)If a(i) < Min Then Min = a(i)s = s + a(i)Next iv = Format(s / 100, "##0.###")For i = 1 To 100If a(i) > (s / 100) Then n = n + 1NextLabel1.Caption = "max=" & Max & vbCrLf & "min=" & Min & vbCrLf & "平均值为" & v & vbCrLf & "大于平均值的元素个数为" & nEnd Sub3.Private Sub Command1_Click()Dim a(), b() As Variant, c() As Singlea = Array(2, 8, 7, 6, 4, 28, 70, 25)b = Array(79, 27, 32, 41, 57, 66, 78, 80)Print "第一个数组为:" & vbCrLfFor i = LBound(a) To UBound(a)Print a(i);Next iPrintPrint "第二个数组为:" & vbCrLfFor i = LBound(a) To UBound(a)Print b(i);Next iReDim c(UBound(a))PrintPrint "两个数组相对元素相加的结果为:" & vbCrLfFor i = LBound(a) To UBound(a)c(i) = a(i) + b(i)Print c(i);Next iPrintFor i = LBound(a) To UBound(a) - 1For j = LBound(a) To UBound(a) - 1 - iIf c(j) < c(j + 1) Thent = c(j)c(j) = c(j + 1)c(j + 1) = tEnd IfNextNextPrintPrint "相加的结果的降序为:" & vbCrLfFor i = LBound(a) To UBound(a)Print c(i);NextEnd Sub4.Private Sub Form_Click()Dim a(20)RandomizePrint " 对换前" & crlfFor i = 1 To 20a(i) = Int(Rnd * 89 + 11)Print a(i);If i / 10 = i \ 10 Then PrintNext iPrintPrint " 对换后" & crlfFor i = 1 To 10t = a(i): a(i) = a(i + 10): a(i + 10) = tNext iFor i = 1 To 20Print a(i);If i / 10 = i \ 10 Then PrintNext iEnd Sub6.Private Sub Picture1_Click()n = V al(Text1.Text)ReDim a(n + 1, n + 1), b(n + 1, n + 1)Clsk = 8For i = 1 To nPicture1.Print String((n - i) * k / 2 + 1, " ");For j = 1 To ia(i, 1) = 1a(i, i) = 1a(i + 1, j + 1) = a(i, j) + a(i, j + 1)b(i, j) = Trim(Str(a(i, j)))Picture1.Print b(i, j); String(k - Len(b(i, j)), " ");Next jPicture1.PrintNext iEnd Sub9.'Option Base 1Dim s() As String, n%Private Sub Command1_Click()For i = 1 To UBound(s) - iFor j = 1 To UBound(s) - iIf s(j) < s(j + 1) Then t = s(j): s(j) = s(j + 1): s(j + 1) = t Next jNext iFor i = LBound(s) To UBound(s)Picture2.Print s(i)Next iEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii = 13 Thenn = n + 1ReDim Preserve s(1 To n)s(n) = Text1.TextPicture1.Print s(n)Text1.Text = ""Text1.SetFocusEnd IfEnd Sub实验七5.Private Sub tt(x, r)Dim s As StringDom = x Mod rx = x \ rIf m = 10 Then m = "A"If m = 11 Then m = "B"If m = 12 Then m = "C"If m = 13 Then m = "D"If m = 14 Then m = "E"If m = 15 Then m = "F"s = m & sLoop Until x = 0tt(x, r) = sEnd SubPrivate Sub Command1_Click() x = Val(Text1.Text)r = Val(Text2.Text)Call tt(x, r)End SubPrivate Sub Command2_Click() x = Val(Text1.Text)r = Val(Text2.Text)Text3.Text = zh(x, r)End SubPrivate Sub Command3_Click() Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd SubFunction zh(x, r)Dim s As StringDom = x Mod rx = x \ rIf m = 10 Then m = "A"If m = 11 Then m = "B"If m = 12 Then m = "C"If m = 13 Then m = "D"If m = 14 Then m = "E"If m = 15 Then m = "F"s = m & sLoop Until x = 0zh = sEnd Function。

相关文档
最新文档