郑州大学VB实验报告书 参考 答案
【参考文档】vb实验指导书答案-范文word版 (10页)
第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实验报告(答案)
Print "数理化"
End Sub
Private Sub Cmd2_Click()
Print "政史地"
End Sub
心得体会:(可以从以下几个方面来总结:你在上机过程中遇到了哪些难题?你是怎么克服的?你对你的程序的评价?你的收获有哪些?你有什么没有解决的问题?等)
A. Text1.MaxLength = 0 B. Text1.Enabled = False
C. Text1.Visible = FalseD. Text1.Width = 0
5、设置命令按钮的属性时,只有将(A)属性设置为1,Picture属性才有效,否则无效。
A、StyleB、CaptionC、EnabledD、Default
试验报告(1)
院(系):课程名称:日期:
班级
学号
实验室
专业
姓名
计算机号
实验
名称
VB环境的熟悉与应用
成绩评定
所用
软件
Visual Basic 6.0
教师签名
实
验
目
的
或
要
求
1.熟悉VB的系统环境,了解VB程序的编写、保存和编译的方法过程。
2.初步了解几个常用控件的使用方法。
实
验
步
骤
、
心
得
体
会
1、在vb中____C_____被称为对象。
10、确定一个控件在窗体上位置的属性是__Left_______和___Top______。
11、窗体边框类型的默认值是___2___。
9、Visual Basic集成开发环境主要窗口包括__窗体设计窗口;代码设计窗口;_属性窗口;_工程资源管理器窗口_;_工具箱窗口。
VisualBasic程序设计—试验报告册-参考答案
实验一VERSION 5.00Begin VB.Form Form1Caption = "Form1" ClientHeight = 3195ClientLeft = 60ClientTop = 345ClientWidth = 4680LinkTopic = "Form1"ScaleHeight = 3195ScaleWidth = 4680 StartUpPosition = 3 ' 窗口缺省Begin mandButton Command1Caption = "Command1"Height = 375Left = 2640TabIndex = 0Top = 2400Width = 1575EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = FalseAttribute VB_PredeclaredId = True Attribute VB_Exposed = FalsePrivate Sub Command1_Click()Print Sqr(8), 8 A (1 / 3)End SubVERSION 5.00Begin VB.Form Form1Caption = "Form1" ClientHeight = 3195ClientLeft = 60ClientTop = 345ClientWidth = 4680LinkTopic = "Form1"ScaleHeight = 3195ScaleWidth = 4680 StartUpPosition = 3 ' 窗口缺省Begin mandButton Command1Caption = "Command1"Height = 495Left = 3720TabIndex = 0Top = 2640Width = 855EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Command1_Click()Dim i%For i = 100 To 110Print i, i A (1 / 2)NextEnd SubVERSION 5.00Begin VB.Form Form1AutoRedraw = -1 'TrueCaption = "Form1"ClientHeight = 3195ClientLeft = 60ClientTop = 345ClientWidth = 4680BeginProperty FontName =" 楷体_GB2312"Size = 21.75Charset = 134Weight = 400Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'FalseEndPropertyForeColor = &H000000FF&LinkTopic = "Form1"ScaleHeight = 3195ScaleWidth = 4680 StartUpPosition = 3 ' 窗口缺省EndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = FalseAttribute VB_PredeclaredId = True Attribute VB_Exposed = False窗口缺省蓝天、白云、绿水、青山宋体"Private Sub Form_Load()Print: PrintPrint " 郑州大学在前进! "End SubVERSION 5.00Begin VB.Form Form1Caption = "Form1" ClientHeight = 3780ClientLeft = 60ClientTop = 345 ClientWidth = 6285LinkTopic = "Form1"ScaleHeight = 3780ScaleWidth = 6285 StartUpPosition = 3 ' Beginbel Label1Caption = " BeginProperty FontName = " Size = 21.75 Charset = 134Weight = 400Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'False EndPropertyForeColor = &H00FF0000&TabIndex = 0 Top = 1080Width = 4935EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = False 实验 2VERSION 5.00Begin VB.Form Form1Caption = "Form1"ClientHeight = 3090 Height Left = 975= 600ClientLeft = ClientTop ClientWidth60 = 450 = 3615BeginProperty FontName Size Charset Weight Underline Italic = = " 宋体"12= 134= 700= 0 'FalseStrikethrough = 0 'FalseEndProperty LinkTopic ScaleHeight ScaleWidth = "Form1" = 3090= 3615StartUpPosition = 3 ' 窗口缺省Begin mandButton Command2Caption Height Left = TabIndex Top Width End = " 商" = 3751920= 4= 1680= 975Begin mandButton Command1Caption Height Left = TabIndex Top Width End = " 乘积" = 375 600= 3= 1680 = 975Begin VB.TextBox Text2Height Left = TabIndex Top Width End = 375 1920 = 2 = 840= 1095Begin VB.TextBox Text1Height Left = TabIndex Top = 375480= 1 = 840Width = 1095EndBegin bel Label3BorderStyle = 1 'Fixed SingleCaption = "Label3"Height = 375Left = 2040TabIndex = 6Top = 2400Width = 975EndBegin bel Label2Caption = " 计算结果为:Height = 375Left = 480TabIndex = 5Top = 2400Width = 1575EndBegin bel Label1AutoSize = -1 'TrueCaption = " 请输入两个数:Height = 240Left = 960TabIndex = 0Top = 360Width = 1785EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Command1_Click()Label3 = Val(Text1) * Val(Text2)End SubPrivate Sub Command2_Click()Label3 = Val(Text1) / Val(Text2)End SubVERSION 5.00Begin VB.Form Form1Caption = "Form1"ClientHeight = 3090ClientLeft = 60ClientTop = 450ClientWidth = 5490BeginProperty FontName = " 宋体"Size = 12Charset = 134Weight = 700Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'False EndPropertyLinkTopic = "Form1"ScaleHeight = 3090ScaleWidth = 5490 StartUpPosition = 3 ' 窗口缺省Begin mandButton Command3Caption = " 隐藏"Height = 375Left = 4080TabIndex = 3Top = 2040Width = 975EndBegin mandButton Command2Caption = " 图片2"Height = 375Left = 4080TabIndex = 2Top = 1320Width = 975EndBegin mandButton Command1Caption = " 图片1"Height = 375宋体" Left = 4080TabIndex = 1Top= 600 Width= 975 EndBegin VB.PictureBox Picture1AutoSize = -1 'TrueBeginProperty FontName= " Size = 9Charset= 134 Weight= 400 Underline =0 'False Italic = 0'False Strikethrough = 0 'FalseEndPropertyHeight = 1935Left = 600ScaleHeight = 1875ScaleWidth = 2715TabIndex = 0Top= 480 Width= 2775 EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = True Attribute VB_Exposed = FalsePrivate Sub Command1_Click() Picture1.Picture = LoadPicture("d:\tu1.jpg") End SubPrivate Sub Command2_Click() Picture1.Picture = LoadPicture("d:\tu2.jpg") End SubPrivate Sub Command3_Click() Picture1.Visible = False End SubVERSION 5.00Begin VB.Form Form1Caption = " 收款机 " ClientHeight = 2730ClientLeft = 60ClientTop = 450ClientWidth = 4680BeginProperty FontName = " 宋体"Size = 12Charset = 134Weight = 700Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'FalseEndPropertyLinkTopic = "Form1" ScaleHeight = 2730 ScaleWidth = 4680StartUpPosition = 3 ' 窗口缺省Begin mandButton Command1Caption = " 总价为"Height = 375Left = 600TabIndex = 4Top = 1920Width = 1695EndBegin VB.TextBox Text2Height = 495Left = 3000TabIndex = 3Top = 960Width = 1335EndBegin VB.TextBox Text1Height = 495Left = 3000TabIndex = 2Top = 240Width = 1335EndBegin bel Label3Alignment = 2 'CenterBorderStyle = 1 'Fixed Single Height = 495Left = 2760TabIndex = 5Top = 1920Width = 1455EndBegin bel Label2Alignment = 2 'CenterCaption = " 货物的单价(元):Height = 375Left = 360TabIndex = 1Top = 1080Width = 2295EndBegin bel Label1Alignment = 2 'CenterCaption = " 货物的数量(个):Height = 375Left = 360TabIndex = 0Top = 360Width = 2295EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Command1_Click()Label3 = Text1 * Text2 End SubBegin VB.Form Form1Caption = "Form1"ClientHeight = 1890ClientLeft = 60ClientTop = 450 ClientWidth = 4365LinkTopic = "Form1" ScaleHeight = 1890 ScaleWidth = 4365StartUpPosition = 3 ' 窗口缺省Begin mandButton Command2 Caption = "清除"BeginProperty FontName = " 宋体"Size = 12 Charset =134Weight = 700Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'FalseEndPropertyHeight = 375Left = 2400TabIndex = 3Top = 1200Width = 975EndBegin mandButton Command1 Caption = "复制"BeginProperty FontName = " 宋体"Size = 12Charset = 134Weight = 700Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'FalseEndPropertyHeight = 375Left = 720TabIndex = 2Top = 1200Width = 975EndBegin VB.TextBox Text2Height = 495Left = 2160TabIndex = 1Top = 360Width = 1695EndBegin VB.TextBox Text1Height = 495Left = 480TabIndex = 0Top = 360Width = 1455EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Command1_Click()Text2 = Text1End SubPrivate Sub Command2_Click()Text1 = ""Text2 = ""End SubPrivate Sub Form_Load()Command1.Visible = FalseCommand2.Visible = False End SubPrivate Sub Text1_Change()Command1.Visible = TrueCommand2.Visible = True End SubVERSION 5.00Begin VB.Form Form1Begin mandButton Command2 Caption = " 停止"Height = 495Caption = "Form1"ClientHeight = 3300ClientLeft =60 ClientTop = 450ClientWidth = 4695BeginProperty FontName= " Size =12 Charset= 134 Weight =700 Underline= 0 'False Italic =0 'False Strikethrough = 0 'False EndPropertyLinkTopic ="Form1" ScaleHeight3300 ScaleWidth = 4695StartUpPosition = 3 'Begin VB.Timer Timer1Enabled= 0 'False Interval =500 Left =3120 Top = 1320End 宋体" 窗口缺省Left = 2640TabIndex = 1Top = 2400Width = 975EndBegin mandButton Command1 Caption = " 移动"Height = 495Left = 840TabIndex = 0Top = 2400Width = 1095EndBegin VB.Image Image1Height = 1800Left = 840Top = 360Width = 1500EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Form_Load()Image1.Picture = LoadPicture("d:\tu3.jpg")End SubPrivate Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()Image1.Left = Int(Rnd * (Form1.ScaleWidth -Image1.Width))Image1.Top = Int(Rnd * (Form1.ScaleHeight - Image1.Height))End Sub实验3VERSION 5.00Begin VB.Form Form1Caption = "Form1"ClientHeight = 3195ClientLeft = 60ClientTop = 345ClientWidth = 4680LinkTopic = "Form1"ScaleHeight = 3195ScaleWidth = 4680StartUpPosition = 3 ' 窗口缺省Begin mandButton Command1Caption = "Command1"Height = 495Left = 3720TabIndex = 0Top = 2640Width = 855EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = FalseAttribute VB_PredeclaredId = True Attribute VB_Exposed = FalsePrivate Sub Command1_Click()Print 2 * 3 A 2 * 8 / 4 + 3 A 2Print Sqr(Sqr(64))Print #2/27/2004# - 10Print Int(-3.1415926)Print Int(Abs(99 - 100) / 2)Print Fix(-3.1415926)Print Int(-3.5), Int(3.5)Print Fix(3.5), Fix(3.5)Print Sgn(7 * 3 + 2)Print LCase("Hello")Print Val("16Year")Print Str(-459.65)Print Len("Hello 程序设计ok") Print "MNT" & 123 & "ABC" Print 123 + Mid("123456", 3, 2)Print 123 & Mid("123456", 3, 2)Print DateAdd("m", 1, #2/27/2004#)End SubCaption = "Form1" ClientHeight = 3195 ClientLeft = 60 ClientTop = 345 ClientWidth = 6825 BeginProperty FontName = " 宋体"Size = 15Charset = 134Weight = 700Underline = 0 'False Italic = 0 'FalseStrikethrough = 0 'False EndProperty LinkTopic = "Form1" ScaleHeight = 3195 ScaleWidth = 6825StartUpPosition = 3 ' 窗口缺省Begin VB.TextBox Text1Height = 495Left = 3120 TabIndex = 2Text = "Text1"Top = 240Width = 1695EndBegin mandButton Command1Caption = " 计算平方立方(根) " BeginProperty FontName = " 宋体" Size = 14.25 Charset = 134Weight = 700Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'False EndProperty Height = 495Left = 1680TabIndex = 0 Top= 960Width = 3015EndBegin bel Label2Caption = "Label2"Height = 735Left = 480TabIndex = 3Top = 1920Width = 5895EndBegin bel Label1Caption = " 输入一个数"Height = 495Left = 1320TabIndex = 1Top = 240Width = 1935EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Command1_Click()Dim n%n = Abs(Val(Text1))Label2 = Format(n A 2, "#.000") & Space(2) & Format(Sqr( n), "#.000") & Space(2) & Format(n A 3, "#.000") & Space(2) & Format(n A (1 / 3), "#.000") End SubBegin VB.Form Form1Caption = "Form1"ClientHeight = 3330ClientLeft = 60ClientTop = 345ClientWidth = 5985LinkTopic = "Form1"ScaleHeight = 3330ScaleWidth = 5985StartUpPosition = 3 ' 窗口缺省Begin mandButton Command2Caption = " 方法二"Height = 495Left = 3840 TabIndex = 1Top = 1800Width = 1215EndBegin mandButton Command1Caption = " 方法一"Height = 495Left = 3840TabIndex = 0Top = 600Width = 1215EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Command1_Click()Dim x%, y%x = Int(Rnd * 900 + 100)Print " 产生的随机数:"; xy = (x Mod 10) * 100 + (x \ 10 Mod 10) * 10 + x \ 100Print " 反序数:"; Format(y, "000")End SubPrivate Sub Command2_Click()Dim x%, y As String x = Int(Rnd * 900 + 100)Print " 产生的随机数:"; xy = Trim(Str(x))Print " 反序数:" & Right(y, 1) & Mid(y, 2, 1) & Left(y, 1) End Sub Begin VB.Form Form1 Caption = "Form1" ClientHeight = 4275 ClientLeft = 60 ClientTop = 345 ClientWidth = 6975 LinkTopic = "Form1" ScaleHeight = 4275ScaleWidth = 6975 StartUpPosition = 3 ' 窗口缺省Begin VB.TextBox Text2Height = 615Left = 4080TabIndex = 5Top = 960Width = 1215EndBegin mandButton Command1 Caption = " 开始产生" Height = 495Left = 2640TabIndex = 3Top = 1920Width = 1215EndBegin VB.TextBox Text1Height = 615Left = 1200TabIndex = 0Top = 960Width = 1215EndBegin bel Label3Caption = "Label3"Height = 375Left = 840TabIndex = 4Top = 2880Width = 4695EndBegin bel Label2Alignment = 2 'CenterCaption = " 到" BeginProperty FontName = " 隶书"Size = 15Charset = 134Weight = 700Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'FalseEndPropertyHeight = 375Left = 2760 TabIndex = 2Top = 1080Width = 975EndBegin bel Label1Caption = " 输入随机数范围:" BeginProperty FontName = " 隶书" Size = 14.25Charset = 134Weight = 700Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'FalseEndPropertyHeight = 495Left = 480 TabIndex = 1Top = 360Width = 2655EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = False Attribute VB_PredeclaredId = TrueAttribute VB_Exposed = False Private Sub Command1_Click()Dim m%, n%Randomize m = Val(Text1): n = Val(Text2) x = Int(Rnd * (n - m) + m) y = Int(Rnd * (n - m) + m) z = Int(Rnd * (n - m) + m)Label3 = m& "到" & n & "之间的3个随机数为: " & x & Space(3) & y & Space(3) & z End SubVERSION 5.00Begin VB.Form Form1 Caption = "Form1"ClientHeight = 3270ClientLeft = 60ClientTop = 450ClientWidth = 6000LinkTopic = "Form1"ScaleHeight = 3270ScaleWidth = 6000StartUpPosition = 3 ' 窗口缺省Begin mandButton Command3 Caption = " 星期几" Height = 495Left = 360TabIndex = 2Top = 2280Width = 1455EndBegin mandButton Command2 Caption = " 时间" Height = 495Left = 360TabIndex = 1Top = 1440Width = 1455EndBegin mandButton Command1 Caption = " 日期" Height = 495Left = 360TabIndex = 0Top = 600Width = 1455EndBegin bel Label3BorderStyle = 1 'Fixed SingleCaption = "Label3"Height = 495Left = 2520TabIndex = 5Top = 2280Width = 2535EndBegin bel Label2BorderStyle = 1 'Fixed SingleCaption = "Label2"Height = 495Left = 2520TabIndex = 4Top = 1440Width = 2535EndBegin bel Label1BorderStyle = 1 'Fixed SingleCaption = "Label1"Left = 2520TabIndex = 3Top = 600Width = 2535EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = False Private Sub Command1_Click() Label1.Caption = Date End SubPrivate Sub Command2_Click()Label2.Caption = TimeEnd SubPrivate Sub Command3_Click()Label3.Caption = WeekdayName(Weekday(Date))End Sub实验4VERSION 5.00Begin VB.Form Form1Caption = "Form1"ClientHeight = 4305ClientLeft = 60ClientTop = 450ClientWidth = 6345BeginProperty FontName = " 宋体"Size = 14.25Charset = 134Weight = 700Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'FalseEndPropertyLinkTopic = "Form1"ScaleWidth = 6345StartUpPosition = 3 ' 窗口缺省Begin mandButton Command1Caption = " 转换"Height = 495Left = 2160TabIndex = 2Top = 1800Width = 1455EndBegin VB.TextBox Text1Height = 495Left = 3480TabIndex = 1Top = 720Width = 1455EndBegin bel Label2Height = 975Left = 360TabIndex = 3Top = 2760Width = 5775EndBegin bel Label1Caption = " 请输入弧度数值:Height = 495Left = 600TabIndex = 0Top = 720Width = 2415EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption Explicit分" & cc & " Private Sub Command1_Click()Dim x!, a!, aa%, b!, bb%, c!, cc$x = Val(Text1)a = x * 180 / 3.14 aa = Int(a)b = (a - aa) * 60bb = Int(b)c = (b - bb) * 60cc = Format(c, "#.000")Label2 = " 弧度 " & Text1 & " 转换为 " & aa & " 度 " & bb & " 秒" End SubVERSION 5.00Begin VB.Form Form1Caption = "Form1"ClientHeight = 3255ClientLeft = 60ClientTop = 450ClientWidth = 4980LinkTopic = "Form1"ScaleHeight = 3255ScaleWidth = 4980StartUpPosition = 3 ' 窗口缺省Begin mandButton Command1Caption = " 判断 "Height = 495Left = 1560 TabIndex = 2Top = 1440Width = 1335EndBegin VB.TextBox Text1Height = 615Left = 960TabIndex = 0Top = 600Width = 2655EndBegin bel Label2Height = 735Left = 960 TabIndex = 3Top = 2160Width = 2775EndBegin bel Label1Caption = " 输入一个年份:" Height = 375Left = 1320TabIndex = 1Top = 240Width = 1935EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Command1_Click()Dim x%x = Val(Text1)If x / 400 = x \ 400 Or x Mod 4 = 0 And x Mod 100 <> 0 Then Label2 = Text1 & " 年是闰年"ElseLabel2 = Text1 & " 年不是闰年"End IfEnd Sub VERSION 5.00Begin VB.Form Form1 Caption = "Form1"ClientHeight = 3090ClientLeft = 60ClientTop = 450ClientWidth = 4680LinkTopic = "Form1"ScaleHeight = 3090ScaleWidth = 4680StartUpPosition = 3 ' 窗口缺省Begin mandButton Command1Caption = "3 个数排序"Height = 495Left = 1800 TabIndex = 0Top = 1320Width = 1215EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False AttributeVB_PredeclaredId = True Attribute VB_Exposed = FalsePrivate Sub Command1_Click()Dim x%, y%, z%x = InputBox(" 输入第一个数") y = InputBox(" 输入第二个数") z = InputBox(" 输入第三个数") If x > y Then t = x: x = y: y = t If y > z Then t = y: y = z: z = t If x > y Then t = x: x = y: y = t Print x, y, z End Sub VERSION 5.00 Begin VB.Form Form1Caption = "Form1" ClientHeight = 5430 ClientLeft = 60 ClientTop = 450 ClientWidth = 6975 LinkTopic = "Form1" ScaleHeight = 5430 ScaleWidth = 6975 StartUpPosition = 3 '窗口缺省Begin mandButton Command2Caption = " 结束"Height = 495 Left = 3840 TabIndex = 1 Top = 2040Width = 1215EndBegin mandButton Command1 Caption = " 计费"Height = 495Left = 1080 TabIndex = 0 Top = 2040Width = 1215EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Command1_Click()x = Val(InputBox(" 请输入上网时间:")) If x <> -1 ThenSelect Case xCase Is < 10fei = 25Case 10 To 50fei = x * 2Case 50 To 100fei = x * 1.5Case Is >= 100fei = x * 1End SelectMsgBox " 上网费用为:" & fei & " 元"End IfEnd SubPrivate Sub Command2_Click()EndEnd Sub VERSION 5.00Begin VB.Form Form1 Caption = "Form1" ClientHeight = 4050 ClientLeft = 60 ClientTop = 450 ClientWidth = 6285 LinkTopic = "Form1" ScaleHeight = 4050 ScaleWidth = 6285 StartUpPosition = 3 ' 窗口缺省Begin mandButton Command1Caption = " 弧度转换为度分秒Height = 615秒"Left = 2160TabIndex = 0Top = 1560Width = 2415EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Command1_Click()x = InputBox(" 请输入弧度数值 ", " 弧度转换 ", 0)xx = Val(x)a = x * 180 / 3.14aa = Int(a)b = (a - aa) * 60bb = Int(b)c = (b - bb) * 60cc = Format(c, "#.000")MsgBox " 弧度 " & x & " 转换为 " & aa & " 度 " & bb & " 分 " & cc & " EndSubVERSION 5.00Begin VB.Form Form1Caption = "Form1"ClientHeight = 5430ClientLeft = 60ClientTop = 450ClientWidth = 6975LinkTopic = "Form1"ScaleHeight = 5430ScaleWidth = 6975StartUpPosition = 3 ' 窗口缺省Begin mandButton Command2Caption = " 结束 "Height = 495Left = 3840 TabIndex = 1Top = 2040Width = 1215EndBegin mandButton Command1Caption = " 计费 "Height = 495Left = 1080TabIndex = 0Top = 2040Width = 1215End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Command1_Click() Dox = Val(InputBox(" 请输入上网时间:", , -1)) If x <> -1 ThenSelect Case x Case Is < 10fei = 25Case 10 To 50fei = x * 2Case 50 To 100fei = x * 1.5Case Is >= 100fei = x * 1End Selectzongfei = zongfei & Space(3) & fei MsgBox zongfei, , " 上网费用为" ElseExit Do End IfLoopEnd SubPrivate Sub Command2_Click()EndEnd Sub实验5VERSION 5.00Begin VB.Form Form1Caption = "Form1" ClientHeight = 3090ClientLeft = 60 ClientTop = 450ClientWidth = 4680LinkTopic = "Form1" ScaleHeight = 3090 ScaleWidth = 4680 StartUpPosition = 3 ' 窗口缺省Begin mandButton Command1 Caption = "Command1"Height = 495Left = 1800TabIndex = 0 Top = 1320Width = 1215EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = FalseAttribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Command1_Click()For n = 1 To 100 s = s + n Next n Print sEnd Sub VERSION 5.00Begin VB.Form Form1 Caption = "Form1" ClientHeight = 3090 ClientLeft = 60 ClientTop = 450 ClientWidth = 4680 LinkTopic = "Form1" ScaleHeight = 3090 ScaleWidth = 4680 StartUpPosition = 3 ' 窗口缺省Begin mandButton Command1Caption = "Command1"Height = 495Left = 1920 TabIndex = 0Top = 1680Width = 1215EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Command1_Click()For i = 0 To 20For j = 0 To 33If i * 5 + j * 3 + 1 / 3 * (100 - i - j) = 100 Then Print i, j, 100 - i - jNextNextEnd SubVERSION 5.00Begin VB.Form Form1Caption = "Form1"ClientHeight = 3090ClientLeft = 60ClientTop = 450ClientWidth = 4680LinkTopic = "Form1"ScaleHeight = 3090ScaleWidth = 4680StartUpPosition = 3 ' 窗口缺省Begin mandButton Command1Caption = "Command1"Height = 495Left = 1800TabIndex = 0Top = 1320Width = 1215EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Command1_Click() n = 0DoIf n Mod 2 = 1 And n Mod 3 = 2 And n Mod 5 = 4 And n Mod 6 = 5 And n Mod 7 = 0 Then Exit Don = n + 1LoopPrint nEnd SubVERSION 5.00Begin VB.Form Form1Caption = "Form1"ClientHeight = 3090ClientLeft = 60ClientTop = 450ClientWidth = 4680LinkTopic = "Form1"ScaleHeight = 3090ScaleWidth = 4680StartUpPosition = 3 ' 窗口缺省Begin mandButton Command2 Caption = " 方法2"Height = 495Left = 2880TabIndex = 1Top = 1320Width = 1215EndBegin mandButton Command1 Caption = " 方法1"Height = 495Left = 2880TabIndex = 0Top = 480Width = 1215End。
实验报告簿(程序设计基础VB答案)
实验日期_____________________实验名称:实验一常用标准控件一【实验目的与要求】1.掌握Visual Basic的启动与退出。
2.熟悉Visual Basic的集成开发环境。
3.掌握在窗体中放置控件的方法。
4.掌握在“属性窗口”中设置控件属性的方法。
5.掌握在“代码编辑器”窗口中输入程序代码的方法。
6.掌握工具栏上启动按钮、结束按钮的使用方法。
7.掌握标签、文本框、命令按钮、列表框等控件的使用方法。
【实验内容与步骤】实验1.1.1 标签的使用(一)1.题目与要求:在名称为Form1、标题为“标签”的窗体上画一个名称为Label1的标签,并设置适当属性以满足以下要求:1)标签的内容为“计算机等级考试”;2)标签可根据显示内容自动调整其大小;3)标签带有边框,且标签内容显示为三号字。
2.实验步骤1)界面设置:在名称为Form1的窗体上放置一个标签控件Label1;2)属性设置(请将表格补充完整)表1.1.1 对象属性文件名为sjt1.frm。
实验1.1.2 标签的使用(二)1.在名称为Form1的窗体上画一个名称为 Label1的标签,标签的宽和高分别为2000、300,有边框,并利用属性窗口设置适当的属性,使其居中显示“等级考试”,并使标签的外观如图所示。
2.属性设置(请将表格补充完整)表1.1.2 对象属性sjt2.frm。
实验1.1.3 文本框的使用1.题目与要求:在名称为Form1的窗体上画两个文本框,名称分别为T1、T2,初始情况下都没有内容。
请编写适当的事件过程,使得在运行时,在T1中输入的任何字符,立即显示在T2中。
程序中不得使用任何变量。
2.实验步骤1)界面设置:在名称为Form1的窗体上放置两个文本框;2)属性设置表1.1.3 对象属性Private Sub T1_Change()T2.Text=T1.Text (T2=T1)End Sub3)保存文件:存盘时必须存放在C:\VB\Sy01文件夹下,工程文件名为sjt3.vbp,窗体文件名为sjt3.frm。
郑州大学VB实验报告书 参考 答案
End Sub Private Sub Command3_Click() Picture1.Visible = False End Sub 2-3 Private Sub Command1_Click() Label3 = Text1 * Text2 End Sub 2-4 Private Sub Command1_Click() Text2 = Text1 End Sub Private Suห้องสมุดไป่ตู้ Command2_Click() Text1 = "" Text2 = "" End Sub Private Sub Text1_Change() Command1.Visible = True Command2.Visible = True End Sub 2-5 Private Sub Command1_Click() Timer1.Interval = 500 End Sub Private Sub Command2_Click()
End If Print x, y, z End Sub 4-4 Private Sub Command1_Click() Dim nettime As Integer, money As Single nettime = Val(InputBox("每月上网时数:", "上网费用")) If nettime = -1 Then money = 0 ElseIf nettime < 10 Then money = 25 ElseIf nettime < 50 Then money = nettime * 2 ElseIf nettime < 100 Then money = nettime * 1.5 ElseIf nettime < 200 Then money = nettime Else money = 200 End If If money <> 0 Then MsgBox "该月上网费用为" & money &"元" 实验五 一 BCBAC 二 (1)for x=1 to 10 s*(1-1/x)
VB实验报告材料(含问题详解)
Else
Text4.Text = a / b
End If
End Select
End Sub
2.模拟简易计算器Command2命令的单击事件的程序代码是什么?
Private Sub Command1_Click()
Dim a!, b!
Dim c As String
a = Val(Text1.Text)
List1.AddItem a(i)
Next i
End Sub
3.单击命令按钮,在文本框中显示结果信息,则程序代码是什么?
Private Sub Command1_Click()
Dim i As Integer, max%, min%, avg!
max = a(1)
min = a(1)
avg = 0
End If
End Sub
实验四循环程序设计
一.实验目的:
1.理解循环程序设计的特点。
2.掌握常用的循环语句。
3.掌握常用的循环算法。
4.掌握图片框、图像框和计时器。
二.实验内容:
1.求
2.设计一条滚动的广告字幕。
三.实验结果:对象属性设置
1.求和结果要求窗体载入时直接显示,设置窗体的某个属性。
对象
b = Val(Text3.Text)
c = Text2.Text
If c =“+”Then
Text4.Text = a + b
ElseIf c =“-”Then
Text4.Text = a - b
ElseIf c =“*”Then
Text4.Text = a * b
ElseIf c =“/”Then
VB实验报告参考答案(本部)
实验报告参考答案(本部)实验一VB集成开发环境实验内容(3):四、设计流程①界面设计:在窗体上画一个标签。
②属性设置:标签的width设为2000,height设为300。
有边框是BordStyle设为1,背景透明是BackStyle设为0。
显示“等级考试”是将caption设为“等级考试”,居中是将Alignment 设为2。
③代码设计:无五、关键代码(注意:解题方法有多种,其它方法只要能完成实验任务也是正确的)无六、调试和测试结果至少要写测试结果正确,如果写了调试中出现的典型问题及解决方法,分数给高些实验二简单的VB程序设计实验内容(3):四、设计流程①界面设计:在窗体上画一个标签、一个命令按钮。
②属性设置:固定边框是BordStyle设为1,背景透明是BackStyle设为0。
③代码设计:分别在3个事件过程form_load(),form_click(),Cmd1_click()中编程。
其中图片从网上下载,与工程文件、窗体文件保存在同一目录,代码中使用相对路径app.path。
五、关键代码(注意:解题方法有多种,其它方法只要能完成实验任务也是正确的)Private Sub Form_Load()Form1.Picture = LoadPicture(App.Path + "\tu.jpg")Form1.Caption = "我的变化"End SubPrivate Sub Form_Click()LBL1.Top = 0LBL1.Left = 0End SubPrivate Sub Cmd1_Click()Cmd1.Height = 1500Cmd1.Width = 2000End Sub六、调试和测试结果至少要写测试结果正确,如果写了调试中出现的典型问题及解决方法,分数给高些实验三数据类型及其运算四、设计流程①界面设计:在窗体上画1个文本框、1个标签、6个命令按钮。
郑州大学VB实验报告简答
过程——指附在该对象上的程序代码,是事件的处理程序。
6、答:
参考课本12页到17页。
实验二问答题:
1、答
通用属性有:Caption标题、Enabled可用性、Visible可见性、ForeColor前景颜色、BackColor背景颜色等。
2、答
标签label是用来显示信息的,不具有输入功能。 属性有Caption、BackStyle、Alignment、BorderStyle、AutoSize。
文本框用来输入、输出数据,编辑文本。 属性有Text、 Maxlength、 MultiLine、 ScrollBars、 Locked 、 PassWord 。
实验一问答题:
1、答:
常见的有visual Basic、C++、Java、SQL。
用途特点:(参考课本4-5页)
2、答:
代码是一行或几行命令。
程序是针对某个任务编写的有序代码的集合。
软件是程序和文档的集合。
它们的关系是:代码 < 程序 < 软件
3、答ห้องสมุดไป่ตู้
面向对象程序设计中的每一个对象都应该能够接受数据、处理数据并将数据传达给其它对象,因此它们都可以被看作一个小型的“机器”,即对象。它能够让人们更简单地设计并维护程序,使得程序更加便于分析、设计、理解。
3、答
结果为:标签里显示一个“abc”,图片框里显示3行“欢迎您”。
4、答
要保存2次,分别是工程文件.vbp和窗体文件.frm。
4、答:
参考课本第9页
VB编程实验报告谜底 完整版
二、填空 1.windows
2. 中断 3.工具箱 4.代码 5.分类
Hale Waihona Puke 6.form2.show 7. 出现语法错误 8. 错 9. 事件 10. 面向对 象 11.工程文件结构 12. 工程 13. 设计程序代码 14. 双击 窗体 15. C:\Program Files\Microsoft Visual Studio\VB98 或者 VB 的安装文件夹 16.属性 17.方法 18.font 19. form_load() 20.对象
4.left top Height、Width twip 5.picture 6.load 7. locked 8. font Alignment 9. GotFocus() LostFocus() 10. 属性窗口 程序代码
实验三: 一、选择 1.A 2.BC 3.BC 4.A 5.A 6.A 7.BCD 8.D 9.B 10. B 11. B 二、判断题 不合法的变量: 3. 4. 5. 6. 8. 10. 11. 14.15. 16. 三、 1、abs(x+y) 2. (3+x*y)^2 3. (-b+sqr(b^2-4*a*c))/(2*a) 4.sin(30*3.14/180)+exp(2) 四、 1. int(rnd* 71+20) 或 int(rnd* 71)+20 2. x<0 and y>0 or x>0 and y<0 或者 x*y<0 3. x mod 3=0 or x mod 7=0 或 x/3=x\3 or x/7=x\7 4. x>=10 and x<20
(整理)大一《VB面向对象程序设计》作业及实验报告书_答案[1].
实验一一DDBAB,CC(D)DDC,ADDCA二windows中断工具箱代码分类form2.show有语法错误错误事件结构化文件名和结构工程代码双击任意控件或右健快捷菜单选“代码窗口”vb的安装文件夹属性方法fontload对象实验二一BCBCC,CBBDA,CCCBA,CBDCC二form_click()interval,5000vbp,frmtop,left,height,width,像素pictureloadlockedfont,alignmentgotfocus,lostfocus属性窗口,代码实验三一A(BC)(BC)AA,A(BCD)DBB,B二3,4,5,6,8,10,11,12,14,15,16 三abs(x+y)(3+x*y)^2(-b+sqr(b^2-4*a*c)/(2*a)sin(30*3.14/180)+exp(2)四int(rnd*71+20)x*y<0x mod 3=0 or xmod 7=0x>=10 and x<20x>="A" and x<="Z"left(s,3) 或者,mid(s,1,3)实验四一CDCDA,DBBAC二(1) 48.71E-01,-4.8712(2) 关系,逻辑,数值(3) 900,100,mid(a,2,1),c(4)m1,2,3print m & "月是第二季度"end select三(1) x=4 y=13(2) 10实验五一BCBAC二(1)for x=2 to 10s*(1-1/x)(2)t<1E-6(3)jt(4)511 5实验六一BCCCD DDDCA实验七一CCDAB DDAAA二(1)n!(2)1到n累加和(3)n是否是素数(4)冒泡排序(5)递归调用实现斐波那契数列(6)求最大公约数和最小公倍数。
vb实验报告答案
vb实验报告答案VB实验报告答案引言:Visual Basic(VB)是一种基于事件驱动的编程语言,广泛应用于Windows平台的软件开发。
本文将就VB实验报告中的几个问题进行解答和讨论,以帮助读者更好地理解和掌握VB编程。
一、VB的特点和应用领域VB作为一种高级编程语言,具有易学易用的特点。
它采用了面向对象的编程思想,提供了丰富的控件库和强大的图形用户界面设计能力,使得开发者可以快速构建出功能完善的Windows应用程序。
VB广泛应用于企业管理系统、数据库应用、游戏开发等领域。
二、VB的开发环境和工具VB的开发环境主要包括Visual Studio和Visual Basic Express两种。
Visual Studio是微软提供的一套集成开发环境(IDE),包含了VB的开发工具和调试器,可用于开发各种类型的应用程序。
而Visual Basic Express则是一款免费的VB开发工具,适合初学者入门使用。
三、VB的基本语法和数据类型VB的基本语法与其他编程语言相似,包括变量声明、条件语句、循环语句等。
VB中的数据类型包括整型、浮点型、字符串型等,开发者可以根据需求选择合适的数据类型来存储和处理数据。
四、VB中的控件和事件VB提供了丰富的控件库,如按钮、文本框、标签等,开发者可以通过拖拽控件到窗体上的方式来构建用户界面。
同时,VB也支持事件驱动编程,即通过响应用户操作或系统事件来触发相应的代码执行。
开发者可以为控件添加事件处理程序,以实现交互功能。
五、VB中的数据操作和数据库连接VB提供了强大的数据操作功能,可以通过ADO(ActiveX Data Objects)技术来连接和操作数据库。
开发者可以使用SQL语句来执行数据库查询、插入、更新和删除等操作,实现对数据的管理和处理。
六、VB的调试和错误处理在开发过程中,调试和错误处理是非常重要的环节。
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实验报告(含答案)分析
实验报告课程名称_程序设计基础Visual Basic_ 班级______ ______姓名_____ ____实验一 VB环境和创建一个简单的VB程序一.实验目的:1.了解VB系统对计算机软件、硬件的要求。
2.掌握启动和退出VB的方法。
3.了解和使用VB集成开发环境各窗口、菜单的一般功能。
4.熟悉建立、编辑、运行、保存一个简单的VB应用程序的全过程。
5.了解文本框、标签框、命令按钮的构造及其属性、事件和方法。
二.实验内容:1.设计一个简单的应用程序,要求在窗体上画一个文本框、一个标签和两个命令按钮编一程序,并把命令按钮分别设置为”显示”和”清除”。
程序运行后,单击”显示”按钮,在文本框中输出一行信息;单击”清除”按钮,则清除文本框中的内容,运行界面如图1.1所示。
图1.1 实验1-1 运行界面三.实验结果:对象属性设置对象属性属性值说明caption 我的第一个vb程序窗体Form1caption 请输入姓名标签Label1text ““文本框Text1caption 显示命令按钮Command1caption 清除命令按钮Command2四.实验思考:1.标签label控件设置的属性代码有哪些?Label1.Caption=“请输入姓名”Label1.fontsize=24Label1.fontbold=True2.两个按钮所使用的是什么事件?代码分别是什么?Private Sub Command1_Click()Text1.text=“姓名”实验二简单程序设计数据类型及常用内部函数的简单应用一.实验目的:1.掌握Visual Basic数据类型的基本概念。
2.掌握用Visual Basic的各种运算符及表达式。
3.学习使用Visual Basic内部函数和数据输入、输出方法。
4.掌握命令按钮、文本框和标签。
5.设计顺序程序。
二.实验内容:1.编写一个华氏温度和摄氏温度之间的转换程序,如图2-2所示,要求用inputbox函数输入华氏温度,用msgbox输出转换后的摄氏温度。
vb实验作业参考答案
vb实验作业参考答案VB实验作业参考答案引言:Visual Basic(VB)是一种基于事件驱动的编程语言,广泛应用于Windows操作系统的软件开发。
在学习VB编程过程中,实验作业是非常重要的一部分,通过实践来巩固所学知识。
本文将提供一些VB实验作业的参考答案,帮助读者更好地理解和掌握VB编程。
一、VB基础知识实验作业参考答案1. 实验题目:编写一个VB程序,实现两个整数的加法运算,并将结果显示在文本框中。
参考答案:```Private Sub btnAdd_Click()Dim num1 As IntegerDim num2 As IntegerDim result As Integernum1 = CInt(txtNum1.Text)num2 = CInt(txtNum2.Text)result = num1 + num2txtResult.Text = CStr(result)End Sub```2. 实验题目:编写一个VB程序,实现输入一个数字,判断该数字是奇数还是偶数,并在消息框中显示结果。
参考答案:```Private Sub btnCheck_Click()Dim num As Integernum = CInt(txtNum.Text)If num Mod 2 = 0 ThenMsgBox "该数字是偶数"ElseMsgBox "该数字是奇数"End IfEnd Sub```二、VB控件应用实验作业参考答案1. 实验题目:编写一个VB程序,实现一个简单的计算器功能,包括加法、减法、乘法和除法操作。
参考答案:```Private Sub btnAdd_Click()Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text) num2 = CDbl(txtNum2.Text)result = num1 + num2txtResult.Text = CStr(result) End SubPrivate Sub btnSubtract_Click() Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text) num2 = CDbl(txtNum2.Text)result = num1 - num2txtResult.Text = CStr(result) End SubPrivate Sub btnMultiply_Click() Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text) num2 = CDbl(txtNum2.Text)result = num1 * num2txtResult.Text = CStr(result) End SubPrivate Sub btnDivide_Click() Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text)num2 = CDbl(txtNum2.Text)If num2 = 0 ThenMsgBox "除数不能为0"Elseresult = num1 / num2txtResult.Text = CStr(result)End IfEnd Sub```2. 实验题目:编写一个VB程序,实现一个简单的登录界面,包括用户名和密码输入框以及登录按钮。
VB实验教材的实验与习题答案
实验4-11
Len(st); Ch=Lcase(ch) ; Case Else ; Mid(Char,I,1)&St
?
实验4-12
i\100 ; (i Mod 100)\10
?
习题
一、 选择题
1.C 2. C 3.A 4. D 5.A 6. B 7. B 8. D 9. B
Const g = 9.8
Dim V0 As Single, t As Single
Dim S As SingFra biblioteke V0 = InputBox("请输入V0的值:")
t = InputBox("请输入时间t的值:")
S = (1 / 2) * g * t ^ 2 + V0 * t
Randomize
a = 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")
List1.AddItem Log(a) / Log(b)
End Sub
‘关系运算
Private Sub Command2_Click()
List1.Clear
List1.AddItem Mid("Visual Basic", 1, 12) = Right("Language Visual Basic", 12)
VB实验报告(含答案)
标签
Label3
Caption
浮点数
标签
Label4
Caption
整除数
标签
Label5
Caption
余数除
标签
Command1
Caption
执行除法运算
命令按钮
四.实验思考:
1.温度转换中的Command1命令的单击事件的程序代码是什么?
Private Sub Command1_Click()
5.了解文本框、标签框、命令按钮的构造及其属性、事件和方法。
二.实验内容:
1.设计一个简单的应用程序,要求在窗体上画一个文本框、一个标签和两个命令按钮编一程序,并把命令按钮分别设置为”显示”和”清除”。程序运行后,单击”显示”按钮,在文本框中输出一行信息;单击”清除”按钮,则清除文本框中的内容,运行界面如图1.1所示。
For i = 1 To 10
If max < a(i) Then max = a(i)
If min > a(i) Then min = a(i)
avg = avg + a(i)
Next i
avg = avg / 10
图5-1窗体界面
三.实验结果:对象属性设置
对象
属性
属性值
说明
Label1
Caption
10个100到200之间的整数
标签
Label2
Caption
最大值
标签
Label3
Caption
最小值
标签
Label4
Caption
平均值
标签
Command1
Caption
计算
命令按钮
VB实验教材习题答案 (1)
第1章VB集成环境与VB概述一、选择题第2章常用控件与界面设计一、选择题第3章数据、表达式与简单程序设计一、选择题第4章选择分支与循环一、选择题二、填空题1.5 7 13 12 14 112. 3 1 5 3 4 13. right(a$,i)4. 45. 6-i6. 6 11 10 21 13 347. 5 14 138. Is else end select9. a*(2*i-1)*(-1)*x/(2*i+2) i+110. 0 n-111. 1 t*(-1)*x^2/((2*k-1)*(2*k)) Abs(t)>eps12. count1=count+1 count1>013. sum=0 sum+j st & k & “+”14. 9 x三、编程题1.Option ExplicitPrivate Sub Command1_Click()Dim s As String, i As Integer, ch As String * 1Dim a As Integer, b As Integer, c As Integers = Text1.TextFor i = 1 To Len(s)ch = Mid(s, i, 1)If (ch >= "0" And ch <= "9") Thena = a + 1ElseIf (ch >= "A" And ch <= "Z") Or (ch >= "a" And ch <= "z") Thenb = b + 1Elsec = c + 1End IfNextPrint "数字个数"; aPrint "字符个数"; bPrint "其他字符"; cEnd Sub2.Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, n As IntegerDim a As Integer, b As Integer, c As IntegerFor i = 1 To 50n = Int(Rnd * 90 + 10)Print n;If i Mod 10 = 0 Then PrintIf n <= 40 Thena = a + 1ElseIf n <= 70 Thenb = b + 1Elsec = c + 1End IfNext iPrint "小于等于40的个数:"; aPrint "大于40小于等于70的个数:"; bPrint "大于70的个数:"; cEnd Sub3.Option ExplicitPrivate Sub Command1_Click()Dim x As SingleDim t As Long, n As Integerx = 1t = 1n = 1Do While 1 / t >= 0.0001x = x + 1 / tn = n + 1t = t * nLoopPrint xEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim k As Integer, sum As Integer, i As Integerk = InputBox("请输入一个正整数k", "输入框")For i = 1 To Len(CStr(k))sum = sum + Mid(k, i, 1)Next iMsgBox k & "的各位数字之和" & sumEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, iSum As LongFor i = 1 To 20iSum = iSum + i ^ 4NextPrint iSumEnd Sub6.Option ExplicitPrivate Sub Command1_Click()Dim a As Integer, b As IntegerDim sum1 As Integer, sum2 As LongDim i As Integer, j As IntegerFor a = 2 To 3000sum1 = 0sum2 = 0For i = 1 To a \ 2If a Mod i = 0 Then sum1 = sum1 + i Next ib = sum1For j = 1 To b \ 2If b Mod j = 0 Then sum2 = sum2 + j Next jIf sum2 = a And a < b Then Print a, bNextEnd Sub7.Private Sub Command1_Click() '打印菱形Dim i As Integer, j As IntegerClsFor i = 1 To 6 '打印菱形上边6行Print Tab(20);Print Spc(6 - i);For j = 1 To 2 * (i - 1) + 1If j = 1 Or j = 2 * (i - 1) + 1 ThenPrint "*";ElsePrint " ";End IfNext jPrintNext iFor i = 5 To 1 Step -1 '打印下半部分Print Tab(20);Print Spc(6 - i);For j = 1 To 2 * (i - 1) + 1If j = 1 Or j = 2 * (i - 1) + 1 ThenPrint "*";ElsePrint " ";End IfNext jPrintNext iEnd Sub8.Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, j As Integer, iSum As IntegerPrint "连续和为1250的正整数是:"For i = 1 To 500iSum = 0For j = i To 500iSum = iSum + jIf iSum >= 1250 Then Exit ForNextIf iSum = 1250 ThenPrint i; " ~"; jEnd IfNextEnd Sub9.Option ExplicitPrivate Sub Command1_Click()Dim a As Integer, b As Integer, c As IntegerFor a = 1 To 50For b = a To 50For c = b To 50If a ^ 2 + b ^ 2 = c ^ 2 ThenPrint a, b, cEnd IfNext cNext bNext aEnd Sub第5章数组一、选择题二、填空题1.Variant2.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.T – 1I + 16.k = 6 - i – jmax = m7.j = 48j = j-38.i + 1i = i + 19. 23710. 3103511.numi + 1a(j)=temp三、编程题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)Print "原数组:";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 IPrint "平移后的数组:";For I = 1 To 10Print A(I);Next IPrintEnd Sub3.Option ExplicitOption Base 1Private Sub Command1_Click()Dim I As Integer, J As Integer, K As IntegerDim a() As Integer, n As Integer, p As Integer Dim 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 IIf S = "" ThenText3.Text = "没有重复"ElseText3.Text = SEnd IfEnd 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 = Val(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 Sub7.Option ExplicitOption Base 1Dim a(5, 5) As IntegerPrivate Sub Command1_Click() '生成数组并显示Dim i As Integer, j As IntegerPicture1.ClsPicture2.ClsPicture3.ClsRandomizeFor i = 1 To 5For j = 1 To 5a(i, j) = Int(90 * Rnd) + 10Picture1.Print a(i, j);NextPicture1.PrintNextEnd SubPrivate Sub Command2_Click()Dim i As Integer, j As Integer, max As IntegerDim b(5) As Integer, c(5) As IntegerFor i = 1 To 5max = a(i, 1)For j = 1 To 5If max < a(i, j) Thenmax = a(i, j)End Ifb(i) = maxIf max = a(i, j) Then c(i) = jNext jNext iFor i = 1 To 5Picture2.Print b(i)Picture3.Print c(i)NextEnd Sub8.Option ExplicitOption Base 1Dim a(5, 5) As IntegerPrivate Sub Command1_Click() '生成数组并显示Dim i As Integer, j As IntegerPicture1.ClsPicture2.ClsLabel3.Caption = "最大值?"Label4.Caption = "最小值?"RandomizeFor i = 1 To 5For j = 1 To 5a(i, j) = Int(90 * Rnd) + 10Picture1.Print a(i, j);NextPicture1.PrintNextEnd SubPrivate Sub Command2_Click() '交换并显示Dim i As Integer, j As Integer, t As IntegerDim maxi As Integer, mini As Integer, max As Integer, min As Integer max = 10: min = 99For i = 1 To 5For j = 1 To 5If max < a(i, j) Thenmax = a(i, j)maxi = iEnd IfIf min > a(i, j) Thenmin = a(i, j)mini = iEnd IfNextNextIf maxi <> mini ThenFor j = 1 To 5t = a(maxi, j)a(maxi, j) = a(mini, j)a(mini, j) = tNext jFor i = 1 To 5For j = 1 To 5Picture2.Print a(i, j);NextPicture2.PrintNextLabel3.Caption = "最大值" & max & "在第" & maxi & "行"Label4.Caption = "最小值" & min & "在第" & mini & "行"ElsePicture2.Print "最小值和最大值在一行"Label3.Caption = "最大值" & max & "在第" & maxi & "行"Label4.Caption = "最小值" & min & "在第" & mini & "行"End IfEnd SubPrivate Sub Form_click()Picture1.ClsPicture2.ClsLabel3.Caption = ""Label4.Caption = ""End Sub9.Option Base 1Private Sub Command1_Click()Dim i As Integer, j As Integer, n As Integer, a() As Integern = InputBox("请输入一个奇数N:")If n Mod 2 = 0 ThenMsgBox ("请重新输入奇数!")End IfReDim a(n, n)For i = 1 To nFor j = 1 To nIf i = (n + 1) / 2 And j = (n + 1) / 2 Thena(i, j) = -1ElseIf i = j Or i + j = n + 1 Thena(i, j) = 1Elsea(i, j) = 0End IfNext jFor i = 1 To nFor j = 1 To nPrint a(i, j);Next jPrintNext iEnd Sub10.Option Base 1Dim a(10) As IntegerPrivate Sub Command1_Click()Dim i As IntegerPrint "生成的数组:"RandomizeFor i = 1 To 10a(i) = Int(Rnd * 90) + 10Print a(i);NextPrintEnd SubPrivate Sub Command2_Click()Dim i As Integerx = InputBox("请输入要删除的数组元素下标:") Print "删除第" & x & "个数组元素后:"For i = x + 1 To 10a(i - 1) = a(i)NextFor i = 1 To 9Print a(i);NextEnd Sub11.Option ExplicitDim a(20) As Integer, i As IntegerPrivate Sub Command1_Click()RandomizeFor i = 1 To 20a(i) = Int(Rnd * 9) + 1Text1 = Text1 & a(i) & " "If i = 10 Then Text1 = Text1 & vbCrLf NextPrivate Sub Command2_Click()Dim j As Integer, k As Integer, b(20) As Boolean 'b(2)用来记录a(2)是否和前面的数相同,相同记为true,不再统计For i = 1 To 20k = 1If b(i) = False Then '如果b(i)=False,表示a(i)没有被统计过For j = i + 1 To 20If a(i) = a(j) Thenk = k + 1b(j) = TrueEnd IfNext jList1.AddItem a(i) & "出现次数:" & kEnd IfNextEnd SubPrivate Sub Command3_Click()Text1 = ""List1.ClearEnd Sub第6章过程一、选择题二、填空题1. 6 .2. 4 20 1013.第一行是 6 26 、第三行是-2 984.第一行10 6 、第二行 5 -55.第一行 6 5 、第三行8 76.第一行11 、第二行77.Fun(i)Fun=p8.第一行 4 、第二行2079.第一行29 、第二行28.710.J=kb( ) As Integerb( k-1) =b(k)i11.第一行gec 、第二行ge 、第四行 312.p1 = True And p2 = True 或p1 And p2= isp(i)Isp = Truem Mod i = 013.Convert(st)Len(s)"A" To "F"k = k + p * h14.isualVisualVisu15.s + an + 1x As Single, n As Integer 、p * (x + i) / ((2 * i - 1) * i * x)16.27617.Left(s, 1)Mid(s, i - 1, 1) = Mid(s, i, 1)n = 1c & CStr(n)18.chtempTrue19.val(mid(s,i,j))n as longprime=True20.A(2,2)的值是 6 ,A(3,1) 的值是8 ;A(4,2) 的值是 321.Option1(i)X22.1023.第一行7 6 ,第二行16 16 ,第三行,4524.第一行15 1 ,第二行35 3 ,第三行,50三、改错题1、Option Base 1Private Sub Command1_Click()Dim A() As Integer, I As Integer, J As Integer, Logic As Boolean Dim 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) 'ByVal 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 Sub4、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.Private Function Prime(a As Integer) As BooleanDim i As IntegerFor i = 2 To Sqr(a)If a Mod i = 0 Then Exit FunctionNext iPrime = TrueEnd Function'方法一Private Sub Command1_Click()Dim m As Integer, i As Integerm = InputBox("请输入一个大于2 的偶数")If m <= 2 Or m Mod 2 <> 0 Then MsgBox "请输入大于2的偶数": Exit Sub If Prime(2) And Prime(m - 2) ThenPrint m & "=2 +" & m - 2ElseDoi = i + 1If Prime(2 * i + 1) And Prime(m - (2 * i + 1)) ThenPrint m & "=" & 2 * i + 1 & "+" & m - (2 * i + 1)Exit DoEnd IfLoop While 2 * i + 1 < m - (2 * i + 1)End If'方法二Private Sub Command2_Click()Dim m As Integer, i As Integer, p() As Integer, n As IntegerDim flg As Booleanm = InputBox("请输入大于2的偶数")If m <= 2 Or m Mod 2 <> 0 Then MsgBox "请输入大于2的偶数": Exit Sub ReDim p(1)p(1) = 2n = 1For i = 3 To m - 2 Step 2If Prime(i) Thenn = n + 1ReDim Preserve p(n)p(n) = iEnd IfNext iFor i = 1 To nFor j = 1 To nIf p(i) + p(j) = m ThenPrint m & "=" & p(i) & "+" & p(j)flg = TrueExit ForEnd IfNext jIf flg = True Then Exit ForNext iEnd Sub2.Private Function Fact(a As Integer) As LongIf a = 0 Or a = 1 ThenFact = 1ElseFact = a * Fact(a - 1)End IfEnd FunctionPrivate Sub Command1_Click()Dim n As Integer, m As Integer, result As Singlen = Val(Text1.Text)m = Val(Text2.Text)If n >= m Thenresult = Fact(n) / Fact(m) / Fact(n - m)Text3.Text = resultMsgBox "要求n>=m,请重新输入"Text1.Text = ""Text2.Text = ""Text1.SetFocusEnd IfEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd Sub3.Private Function Istgs(n As Integer) As BooleanDim s As String, L As IntegerL = Len(CStr(n))s = CStr(n ^ 2)If Right(s, L) = n Then Istgs = TrueEnd FunctionPrivate Sub Command1_Click()Dim n As IntegerFor n = 10 To 300If Istgs(n) Then List1.AddItem n & "^2" & "=" & n ^ 2 Next nEnd SubPrivate Sub Command2_Click()EndEnd Sub4.Private Sub Command1_Click()Dim a(3, 4) As Integer, i As Integer, j As IntegerDim m As Integer, mj As IntegerRandomizeFor i = 1 To 3For j = 1 To 4a(i, j) = Int(900 * Rnd + 100)Print a(i, j);Next jPrintNext iFor i = 1 To 3m = 0Call max(a, i, m, mj)Print "第" & i & "行最大值为" & m & ",在第" & mj & "列"Next iEnd SubPrivate Sub max(a() As Integer, i As Integer, m As Integer, maxj As Integer) Dim j As Integerm = a(i, 1): maxj = 1For j = 2 To UBound(a, 2)If a(i, j) > m Thenm = a(i, j)maxj = jEnd IfNext jEnd SubPrivate Sub Command2_Click()EndEnd Sub5.Private Function Judge(n As Integer) As BooleanDim sum As Integersum = yz(n)If yz(sum) = 2 * n Then Judge = TrueEnd FunctionPrivate Function yz(n As Integer) As IntegerDim i As IntegerFor i = 1 To nIf n Mod i = 0 Then yz = yz + iNext iEnd FunctionPrivate Sub Command1_Click()Dim n As IntegerFor n = 1 To 500If Judge(n) Then Print nNext nEnd SubPrivate Sub Command2_Click()EndEnd Sub6.Private Sub Command1_Click()Dim n As Integer, j As Integer, flg As BooleanFor n = 2 To 30flg = FalseFor j = 2 To nIf pfs(j) And n Mod j = 0 Thenflg = TrueExit ForEnd IfNext jIf flg = False Then Print n;Next nEnd SubPrivate Function pfs(n As Integer) As BooleanIf Sqr(n) = Int(Sqr(n)) Then pfs = TrueEnd Function7.Private Function fxs(n As Long) As LongDim i As Integer, s As StringFor i = 1 To Len(CStr(n))s = Mid(CStr(n), i, 1) & sNext ifxs = sEnd Function'判断某数是否为回文数Private Function Hws(n As Long) As BooleanDim i As Integer, s As String, L As Integers = CStr(n): L = Len(s)For i = 1 To Len(s) / 2If Mid(s, i, 1) <> Mid(s, L + 1 - i, 1) Then Exit Function Next iHws = TrueEnd FunctionPrivate Sub Command1_Click()Dim x As Long, t As Longx = InputBox("请输入一个正整数:")t = xDo While Hws(t) = FalsePrint t; "+"; fxs(t); "="; t + fxs(t)t = t + fxs(t)LoopEnd Sub8.Private Function fxs(n As Long) As LongDim i As Integer, s As StringFor i = 1 To Len(CStr(n))s = Mid(CStr(n), i, 1) & sNext ifxs = sEnd FunctionPrivate Sub Command1_Click()Dim n As Long, t As LongFor n = 1 To 999t = fxs(n)If t ^ 2 = fxs(n ^ 2) And n Mod 10 <> 0 And n < t ThenList1.AddItem n & " " & tList2.AddItem n & "^2" & "=" & n ^ 2 & " " & t & "^2" & "=" & t ^ 2 End IfNext nEnd Sub9.Private Function fxs(n As Long) As LongDim i As Integer, s As StringFor i = 1 To Len(CStr(n))s = Mid(CStr(n), i, 1) & sNext ifxs = sEnd FunctionPrivate Function Judge(n As Integer) As BooleanDim i As Integer, L As Integer, a(9) As Integer, t As IntegerIf Sqr(n) = Int(Sqr(n)) ThenL = Len(CStr(n))For i = 1 To Lt = Mid(CStr(n), i, 1)a(t) = 1Next iFor i = 0 To 9Sum = Sum + a(i)Next iIf Sum = L - 1 Then Judge = TrueEnd IfEnd FunctionPrivate Sub Command1_Click()Dim a As IntegerFor a = 300 To 2000If Judge(a) Then List1.AddItem aNext aEnd Sub10.Private Function F(n As Integer) As BooleanDim i As IntegerFor i = 1 To Len(CStr(n))If i Mod 2 = 1 And Mid(CStr(n), i, 1) Mod 2 <> 1 Then Exit FunctionIf i Mod 2 = 0 And Mid(CStr(n), i, 1) Mod 2 <> 0 Then Exit Function Next iF = TrueEnd FunctionPrivate Sub Command1_Click()Dim a(8) As Integer, i As Integer, j As IntegerRandomizeDot = Int(900 * Rnd + 100)For j = 1 To iIf t = a(j) Then Exit ForNext jIf j = i + 1 Theni = i + 1a(i) = tList1.AddItem a(i)If F(a(i)) Then List2.AddItem a(i)End IfLoop Until i = 8End SubPrivate Sub Command2_Click()List1.ClearList2.ClearEnd SubPrivate Sub CmdEnd_Click()EndEnd Sub11.Private Function prime(a As Integer) As BooleanDim i As IntegerFor i = 2 To Sqr(a)If a Mod i = 0 Then Exit FunctionNext iprime = TrueEnd FunctionPrivate Function nx(n As Integer) As IntegerDim i As Integer, s As StringFor i = 1 To Len(CStr(n))s = Mid(CStr(n), i, 1) & sNext inx = Val(s)End FunctionPrivate Sub Command1_Click()Dim n As Integer, t As IntegerFor n = 100 To 900t = nx(n)If prime(n) And prime(t) And n < t ThenList1.AddItem "(" & n & "," & t & ")"End IfNext nEnd SubPrivate Sub Command2_Click()List1.ClearEnd Sub12.Option Base 1Dim a(4, 5) As IntegerPrivate Sub Command1_Click()Dim i As Integer, j As IntegerRandomizeFor i = 1 To 4For j = 1 To 5a(i, j) = Int(Rnd * 90 + 10)Picture1.Print a(i, j);Next jPicture1.PrintNext iEnd SubPrivate Sub Fp(a() As Integer, i As Integer, maxj As Integer, Flg As Boolean) Dim max As Integer, j As Integer, t As Integermax = a(i, 1): maxj = 1For j = 2 To UBound(a, 2)If a(i, j) > max Thenmax = a(i, j)maxj = jEnd IfNext jFor t = 1 To UBound(a, 1)If a(t, maxj) > max ThenFlg = FalseExit SubEnd IfNextFlg = TrueEnd SubPrivate Sub Command2_Click()Dim i As Integer, m As Integer, mj As Integer, f As BooleanFor i = 1 To 4f = Falsem = 0: mj = 0Call Fp(a, i, mj, f)If f = True ThenText1.Text = Text1.Text & "(" & i & "," & mj & "):" & a(i, mj) & vbCrLf End IfNext iEnd SubPrivate Sub Command3_Click()Picture1.ClsText1 = ""End Sub13.Private Sub Command1_Click()Dim a(30) As Integer, i As Integer, j As IntegerDim Flag As BooleanRandomizeDot = Int(900 * Rnd + 100)For j = 1 To iIf t = a(j) Then Exit ForNext jIf j = i + 1 Theni = i + 1a(i) = tText1.Text = Text1.Text + Str(a(i))If i Mod 10 = 0 Then Text1.Text = Text1.Text + vbCrLfIf IsDown(a(i)) ThenList1.AddItem a(i)Flag = TrueEnd IfEnd IfLoop Until i = 30If Flag = False Then List1.AddItem "无降序数"End SubPrivate Function IsDown(n As Integer) As BooleanDim i As Integer, S As StringS = CStr(n)For i = 1 To Len(S) - 1If Mid(S, i, 1) < Mid(S, i + 1, 1) Then Exit FunctionNext iIsDown = TrueEnd FunctionPrivate Sub Command2_Click()List1.ClearText1 = ""End Sub14.Option ExplicitPrivate Sub CmdFind_Click()Dim i As Integer, p As String, st As String, st1 As StringFor i = 100 To 999st = ""If csum(i) = zyz(i, st) Thenp = CStr(i)st1 = Left(p, 1) & "+" & Mid(p, 2, 1) & "+" & Right(p, 1)List1.AddItem i & ": " & st1 & "=" & Left(st, Len(st) - 1)End IfNext iIf List1.ListCount = 0 ThenList1.AddItem "无满足要求的数!"End IfEnd SubPrivate Function csum(m As Integer) As Integer '求各位数字之和Dim i As Integer, p As Stringp = CStr(m)For i = 1 To Len(p)csum = csum + Val(Mid(p, i, 1))Next iEnd FunctionPrivate Function zyz(ByVal m As Integer, st As String) As Integer '求所有质因子之和Dim i As Integeri = 2DoIf m Mod i = 0 Thenzyz = zyz + ist = st & i & "+"m = m \ iElsei = i + 1End IfLoop Until m = 1End Function15.Private Sub Command1_Click()Dim k As Integer, i As Integerk = InputBox("请输入要求的数列项数:")List1.AddItem "共输出前" & k & "项数列"For i = 0 To kList1.AddItem p(i)NextEnd SubPrivate Function p(n As Integer) As IntegerIf n = 0 Or n = 1 Or n = 2 Thenp = 1Elsep = p(n - 2) + p(n - 3)End IfEnd Function第7章文件一、选择题二、填空题1.顺序文件和随机文件2. EOF3. Write和Print4.返回或设置当前的工作目录5.5116.文件的写语句7.Append8.LOF9.关闭10.Pattern11.【1】For Input 【2】#2 【3】Not EOF(2) 12.【1】”END”【2】Text1.Text 或者Text113.【1】Input 【2】ch 【3】Len(mystr) 14.【1】Number 【2】s15.【1】For Append As #1 【2】"end" 【3】ct,nt 16.【1】For Input 【2】For Output As #2 【3】Not EOF(1) 【4】Line Input #1,str1 【5】Close #1,#2 【6】Kill “C:\old.txt 17.【1】Open "C:StuData.txt" For OutPut As #1 【2】Write 18.【1】"C:\data.txt" 【2】#1, a(i) 【3】k>1 And a(k-1)>b 【4】k = k -1三、综合题1.Option Base 1Dim arr(100) As IntegerPrivate Sub Command1_Click()Dim i As IntegerOpen "c:\in18.txt" For Input As #6For i = 1 To 100Input #6, arr(i)Next iClose #6End SubPrivate Sub Command2_Click()Dim i As IntegerText1.Text = ""Open "c:\out18.txt" For Output As #8For i = 1 To 100If arr(i) Mod 2 <> 0 ThenText1.Text = Text1.Text & Str(arr(i))Write #8, arr(i)End IfNext iClose #8End Sub2.Dim str As StringDim n As LongPrivate Sub Command1_Click()CommonDialog1.Filter = "文本文件(*.txt)|*.txt|All Files(*.*)|*.*"CommonDialog1.FilterIndex = 1CommonDialog1.Action = 1Open CommonDialog1.FileName For Input As #2n = LOF(2)str = Input(n, #2)Text1.Text = strClose #2End SubPrivate Sub Command2_Click()Dim i As IntegerFor i = 1 To Len(str)If Asc(Mid(str, i, 1)) <= Asc("Z") And Asc(Mid(str, i, 1)) >= Asc("A") Then Mid(str, i, 1) = LCase(Mid(str, i, 1))ElseIf Asc(Mid(str, i, 1)) <= Asc("z") And Asc(Mid(str, i, 1)) >= Asc("a") Then Mid(str, i, 1) = UCase(Mid(str, i, 1))End IfNext iText1.Text = strEnd SubPrivate Sub Command3_Click()Open "D:\out.txt" For Output As #3Print #3, strClose #3End Sub第8章程序调试一.选择题二.改错题1.a(i)=int(Rnd*19)+1 →a(i)=int(rnd*20)+1For l=1 to a(i)+1 →for i=2 to a(i)+1If l=a(i) →if l <> a(i)K=k+1 →k=k-1。
大学vb教材参考答案
⼤学vb教材参考答案第1章⼀.单项选择题1-5:DBCAC 6-10:ABCDC 11-15:BCCAB ⼆. 多项选择题1、ACDE2、BCE3、CD4、CE5、AE6、ACE7、ABCD三. 填空题1.事件驱动2.解释编译3.设计、运⾏和中断。
4.属性、事件和⽅法。
5.窗体单击(Form_Click)。
6.(第1个空取消),代码7. MyForm 。
要求复习:教材的例题:P7 例1-1实验教程的练习:P5 第1、2 题习题2参考答案(本章答案请同学们⾃⼰到机器上去验证)⼀.单选题1.①D,②D2.①A,②C3.A4.B5.B8.D9.B 10.B 11.A 12.A 13.B 14.A 15.B 16.B 17.B 18.A 19.B 20.A 21.B 22.B 23.D 24.A 25.B 26.B 27.A 28.B 29.C 30.A ⼆. 多项选择题1.A,B2.A,D3.4.C,D,E5.A,B,D,E6.A,B,C7.A,D,E8.B,C9.A,D,E 10. 11.A,D,E 12.A,B 13.A,B,D,E 14.B,D 15.C,D 16.A,C 17.A,D三. 填空题1、⑴sin(50*3.14/180)⑵(2+x*y)/(2-y^2)⑶a^2-(3*a*b/(3+a))⑷(x^3)^(1/8)+sqr(y^2+4*a^2/(x+y^3))2、int(rnd*(51)+50)3、⑴138 ⑵3 ⑶214 ⑷inchina ⑸70 (6)45 ⑺0第3章⼀.单项选择题1-5: C B D D B 6-10:C B D D A 11-15:A C C B C16-20:A B A A C 21-25:D B B C A 26:B 27:B 28:取消29:A 30:A 31:C⼆.多项选择题1. AC 2. ACE 3. ABCF 4. ABCDE 5. BD三.填空题1. $000, 124 。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
郑州大学VB实验报告书参考答案。
以下内容均来自百度文库,所以仅供参考。
不过经亲自测试习题及实验(一)的答案基本正确,除了实验题的3,4小题没有改字形字体颜色什么的。
实验一一、选择题DDBAB,C(CD)DDC,ADDCA二、填空题Windows中断工具箱代码分类form2.show有语法错误错误事件结构化文件名和结构工程编写代码双击任意控件或右健快捷菜单选“代码窗口”vb的安装文件夹属性方法fontload对象三、编程1-1Private Sub Command1_Click() Print Sqr(8), 8 ^ (1 / 3)End Sub1-2Private Sub Command2_Click() For i = 100 To 110Print Sqr(i)Next iEnd Sub1-3(基本设置在属性窗口完成!)Private Sub Command3_Click() Print "郑州大学在前进!"End Sub1-4(基本设置在属性窗口完成!)Private Sub Command4_Click() Label1 = "蓝天、白云、绿水、青山" End Sub实验二一BCBCC,CBBDA,CCCBA,CBDCC 二form_click()interval,5000vbp,frmtop,left,height,width,像素pictureloadlockedfont,alignmentgotfocus,lostfocus属性窗口,代码三2-1Private Sub Command1_Click() Label3 = Text1 * Text2End SubPrivate Sub Command2_Click() Label3 = Text1 / Text2End Sub2-2Private Sub Command1_Click() Picture1.Visible = TruePicture1 = LoadPicture("C:\Documentsand Settings\All Users\Documents\My Pictures\示例图片\Water lilies.jpg")End SubPrivate Sub Command2_Click()Picture1.Visible = TruePicture1 = LoadPicture("C:\Documentsand Settings\All Users\Documents\My Pictures\示例图片\Winter.jpg")End SubPrivate Sub Command3_Click()Picture1.Visible = FalseEnd Sub2-3Private Sub Command1_Click()Label3 = Text1 * Text2End Sub2-4Private Sub Command1_Click()Text2 = Text1End SubPrivate Sub Command2_Click()Text1 = ""Text2 = ""End SubPrivate Sub Text1_Change()Command1.Visible = TrueCommand2.Visible = TrueEnd Sub2-5Private Sub Command1_Click()Timer1.Interval = 500End SubPrivate Sub Command2_Click()Timer1.Interval = 0End SubPrivate Sub Timer1_Timer()Image1.Left = Int(Rnd * (Form1.ScaleWidth -Image1.Width)) Image1.Top = Int(Rnd * (Form1.ScaleHeight -Image1.Height)) End Sub实验三一A(BC)(BC)AA,A(BCD)DBB,B二3,4,5,6,8,10,11,12,14,15,16三abs(x+y)(3+x*y)^2(-b+sqr(b^2-4*a*c)/(2*a)sin(30*3.14/180)+exp(2)四int(rnd*71+20)x*y<0x mod 3=0 or xmod 7=0x>=10 and x<20x>="A" and x<="Z"left(s,3) 或者,mid(s,1,3)五3-2Private Sub Command1_Click()Dim x As Singlex = Val(Text1)Print Format(x ^ 2, "##.000"),Format(Sqr(x), "##.000"), Format(x ^ 3, "##.000"), Format(x^ (1 / 3), "##.000")End Sub3-3Private Sub Command1_Click()Dim x As Integerx = Int(Rnd * 900 + 100)Text1 = Trim(Str(x))Text2 = Right(Text1, 1) + Mid(Text1, 2, 1)+ Left(Text1, 1)End Sub3-4Private Sub Command1_Click()Dim max, min As Integermin = Val(Text1)max = Val(Text2)RandomizePrint Int(Rnd * (max - min + 1) + min),Int(Rnd * (max - min + 1) + min), Int(Rnd * (max - min + 1) + min)End Sub3-5Private Sub Command1_Click()Text1 = DateText2 = TimeText3 = WeekdayName(Weekday(Date)) End Sub实验四一CDCDA,DBBAC二(1) 48.71E-01,-4.8712(2) 关系,逻辑,数值(3) 900,100,mid(a,2,1),c(4)m1,2,3print m & "月是第二季度"end select三(1) x=4 y=13(2) 10四4-1Private Sub Command1_Click()Dim num, a1, a2, a3 As Singlenum = Val(Text1) * 180 / 3.14a1 = Int(num)num = num - a1a2 = Int(num * 60)num = num * 60 - a2a3 = Format(num * 60, "##.000")Print a1, a2, a3End Sub4-2Private Sub Command1_Click()Dim y As Integery = Val(Text1)If (y Mod 400 = 0 Or y Mod 4 = 0 And y Mod100 <> 0) Then MsgBox y & "是闰年"ElseMsgBox y & "不是闰年"End IfEnd Sub4-3Private Sub Command1_Click()Dim x, y, z, t As Integerx = Val(InputBox("input x:"))y = Val(InputBox("input y:"))z = Val(InputBox("input z:"))If x > y Then t = x: x = y: y = tIf y > z Thent= y: y = z: z = tIf x > y Then t = x: x = y: y = tEnd IfPrint x, y, zEnd Sub4-4Private Sub Command1_Click()Dim nettime As Integer, money As Singlenettime = Val(InputBox("每月上网时数:", "上网费用")) If nettime = -1 Thenmoney = 0ElseIf nettime < 10 Thenmoney = 25ElseIf nettime < 50 Thenmoney = nettime * 2ElseIf nettime < 100 Thenmoney = nettime * 1.5ElseIf nettime < 200 Thenmoney = nettimeElsemoney = 200End IfIf money <> 0 Then MsgBox "该月上网费用为" & money &"元"实验五一BCBAC二(1)for x=1 to 10s*(1-1/x)(2)t<1E-6(3)jt(4)5三5-1Private Sub Command1_Click()Dim i, sum As Integersum = 0For i = 1 To 100sum = sum + iNext iPrint "1+2+...+100="; sumEnd Sub5-2Private Sub Command1_Click()Dim x, y As IntegerFor x = 0 To 20For y = 0 To 33If 5 * x + 3 * y + (100 - x - y) / 3 = 100 ThenPrint x, y, 100 - x - yEnd IfNext yNext x5-3Private Sub Command1_Click()Dim i As Integeri = 7DoIf i Mod 2 = 1 And i Mod 3 = 2 And i Mod 5= 4 And i Mod 6 = 5 And i Mod 7 = 0 ThenPrint iExit DoElsei= i + 7End IfLoopEnd Sub5-4Private Sub Command1_Click()Dim x, y, z As IntegerFor x = 1 To 9For y = 1 To 9For z = 0 To 9If 100 * x + 10 * x + z + 100 * y + 10 * z + z = 532 Then Print x, y, zEnd IfNext zNext yNext xEnd Sub5-5Private Sub Command1_Click()Dim sum As Single, n As Integersum = 1Do While sum <= 4sum = sum * 1.1n= n + 1LoopPrint "经过"; n; "年销售收入翻两番"End Sub5-6Private Sub Command1_Click() Dim sum, i, n As Integersum = 0n = Val(InputBox("请输入n的值:")) For i = 1 To nsum = sum + i * (-1) ^ (i + 1) Next iPrint "1-2+3-4+...="; sumEnd Sub5-7Private Sub Command1_Click() Dim sum, isum, i, n As Integer sum = 0isum = 0n = Val(InputBox("请输入n的值:")) For i = 1 To nisum = isum + isum = sum + isumNext iPrint "1+(1+2)+(1+2+3)+...="; sum End Sub5-8Private Sub Command1_Click() Dim pi, ti As SingleDim i As Integerpi = 0ti = 1i = 1Do While Abs(ti) >= 0.0001ti = (-1) ^ (i + 1) / (2 * i - 1)pi = pi + tii= i + 1LoopEnd Sub5-9Private Sub Command1_Click()Dim i, j, k As IntegerPrint "水仙花数有:"For i = 1 To 9For j = 0 To 9For k = 0 To 9If i * 100 + j * 10 + k = i ^ 3 + j ^ 3+ k ^ 3 Then Print i, j, kEnd IfNext kNext jNext iEnd Sub5-10Private Sub Command1_Click()Dim i, j, k As Integerk = 0For i = 999 To 100 Step -1For j = 2 To Int(Sqr(i))If i Mod j = 0 Then Exit ForNext jIf j = Int(Sqr(i)) + 1 Then k = k + 1: Print i If k = 3 Then Exit ForNext iEnd Sub5-11Private Sub Command1_Click()Dim i, n, min, max As IntegerDim aver As Singlemin = 100max = 50For i = 1 To 20n= Int(Rnd * (99 - 51) + 51)Print n;If i Mod 5 = 0 Then PrintIf n > max Then max = nIf n < min Then min = naver = aver + nNext iPrint "max="; maxPrint "min="; minPrint "average="; aver / 20 End Sub5-12Private Sub Command12_Click() Dim i, j As IntegerFor i = 1 To 5For j = 1 To (2 * i - 1)Print Tab(20 - i + j); "*"; Next jNext iEnd Sub实验六一BCCCD DDDCA二、6-1Option Base 1Private Sub Command1_Click() Dim ia(10) As IntegerDim Max, min, aver As Integer, iMax, iminAs Integer For i = 1 To 10ia(i) = Int(Rnd * 51 + 50)Print ia(i);Next iPrintMax = ia(1): iMax = 1min = ia(1): imin = 1aver = ia(1)For i = 2 To 10aver = aver + ia(i)If ia(i) > Max Then Max = ia(i): iMax = iIf ia(i) < min Then min = ia(i): imin = iNext iPrint "max="; Max,"imax="; iMaxPrint "min="; min,"imin="; iminPrint "aver="; aver / 10End Sub6-2Private Sub Command1_Click()Dim ia(20), num(5) As IntegerDim Max, min, aver As Integer, iMax, iminAs IntegerFor i = 1 To 20ia(i) = Int(Rnd * 101)Print ia(i);Select Case ia(i)Case Is < 60num(1) = num(1) + 1Case60 To 69num(2) = num(2) + 1Case 70 To 79num(3) = num(3) + 1Case 80 To 89num(4) = num(4) + 1Case 90 To 100num(5) = num(5) + 1End SelectNext iPrintPrint "各分数段的人数分别是(0~59,60~69,70~79,80~89,90~100):" For i = 1 To 5Print num(i);End Sub6-3Private Sub Command1_Click()Dim a(10) As Integer, t%For i = 1 To 10a(i) = Int(Rnd * 51)Print a(i);Next iPrintFor i = 1 To 9For j = i + 1 To 10Ifa(i) < a(j) Then t = a(i): a(i) = a(j): a(j) = t Next jNext iPrint "排序后:"For i = 1 To 10Print a(i);Next i6-4Private Sub Command1_Click() Dim a(20) As Integer, t%For i = 1 To 20a(i) = Int(Rnd * 51)Print a(i);If (i + 1) Mod 5 = 0 Then Print Next iEnd Sub6-5Private Sub Command1_Click() Dim a(9), b(3, 3) As Integer, s%, t% For i = 1 To 9a(i) = Int(Rnd * 101)Print a(i);Ifi Mod 3 = 0 Thent = 3: s = i / 3Elset = i Mod 3: s = i \ 3 + 1 End Ifb(s, t) = a(i)Next iPrintFor i = 1 To 3For j = 1 To 3Print b(i, j);Next jPrintNext iEnd Sub6-6Private Sub Command1_Click() Dim a() As Integern = InputBox("n=?")ReDim a(n, n)For i = 1 To nFor j = 1 To na(i, j) = Int(Rnd * 10)Print a(i, j);Next jPrintNext iEnd Sub6-7Private Sub Command1_Click() Dim a() As Integern = InputBox("n=?")ReDim a(n, n)For i = 1 To na(i, i) = 1Next iFor i = 1 To nFor j = 1 To nPrint a(i, j);NextjPrintEnd Sub6-8Private Sub Command1_Click()Dim ia() As IntegerDim Max As Integer, iMax, jmax As Integerm = InputBox("m=?")n = InputBox("n=?")ReDim ia(m, n)Max = 0: iMax = 0: jmax = 0For i = 1 To mFor j = 1 To nia(i, j) = Int(Rnd * 101)Print ia(i, j);If ia(i, j) > Max Then Max = ia(i, j): iMax = i: jmax = j Next jPrintNext iPrint "max="; Max,"imax="; iMax, "jmax="; jmax实验七一CCDAB DDAAA二(1)n!(2)1到n累加和(3)n是否是素数(4)冒泡排序(5)递归调用实现斐波那契数列(6)求最大公约数和最小公倍数三7-1Private Sub Command1_Click() Dim n, sum As Integern = Val(InputBox("n=?"))sum = jsh(n)Print "1!+2!+...+"; n;"!="; sum End SubPublic Function jsh(n) As Integer Dim i, s, t As Integers = 0t = 1For i = 1 To nt= t * is= s + tNext ijsh = sEnd Function7-2Private Sub Command1_Click()Dim n, flag As Integern = Val(InputBox("n=?"))flag = 1sushu n, flagPrint "n="; flagEnd SubPublic Sub sushu(n, flag)Dim i As IntegerFor i = 2 To n - 1If n Mod i = 0 Then flag = 0: Exit For Next iEnd Sub7-3Private Sub Command1_Click()Dim flag As Integer, str As Stringstr = InputBox("n=?")flag = huiwen(str)If flag = 1 Then Print str; "是回文数" Else Print str; "不是回文数" End SubPublic Function huiwen(str) As IntegerDim lens, m, i As Integerlens = Len(str)For i = 1 To Int(lens / 2)If Mid(str, i, 1) <> Mid(str, lens - i + 1, 1) Then Exit For Next iIf i = Int(lens / 2) + 1 Then huiwen = 1Else huiwen = 0End Function7-4Private Sub Command1_Click()Dim n, m, c1, c21, c22, c23 As Integer n = Val(InputBox("n=?"))m = Val(InputBox("m=?"))c1 = jc1(n) / (jc1(m) * jc1(n - m))Print "函数计算c1="; c1jc2 n, c21jc2 m,c22jc2 n - m, c23Print "子过程计算c2="; c21 / (c22 * c23) End SubPublic Sub jc2(n, c)Dim i As Integerc = 1For i = 1 To nc= c * iNext iEnd SubPublic Function jc1(n)Dim i As Integers = 1For i = 1 To ns= s * iNext ijc1 = sEnd Function7-5Private Sub Command1_Click() Dim str1 As Stringstr1 = InputBox("请输入一个实数:") MsgBox sum(str1)End SubPublic Function sum(str As String) Dim lens, i, n As IntegerDim c As String * 1lens = Len(str)n = 0c= Mid(str, i, 1)If c <= "9" And c >= "0" Thenn = n + Val(c)End IfNext isum = nEnd Function7-6Private Sub Command1_Click()Dim str1 As Stringstr1 = InputBox("请输入一个字符串:") Print str1; "中有数字字符"; num(str1); "个。