VB实验任务11答案

合集下载

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

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

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

vb实验报告(答案)

vb实验报告(答案)
1)界面设计
2)属性设置
控件对象属性属性值
Text1 Name Txt1
Command1 Name Cmd1
Cmd1 Caption计算
Txt1 Caption全国计算机等级考试二级
3)代码设计
Private Sub Cmd1_Click()
Print Txt1.SelText
End Sub
17、在名称为Form1的窗体上画一个文本框,其名称为Text1,编写适当的事件过程。程序运行后,如果单击窗体,则可使文本框移到窗体的左上角;而如果改变文本框中的内容,则可使文本框移到窗体的右上角。
2、已知字符串A的值为“AbcDe“,现在把它全部转换为大写字母,正确的语句是______Ucase(“AbcDe“)________。
3、有如下程序
a=300 : b=20
a=a + b : b=a–b
a=a–b
print a
print b
分析该程序的功能是_____a与b互换______
4、可以同时删除字符串前导和尾部空白的函数是(C)。
A. ShowB. Hide C. LoadD. Unload
3、在窗体上有多个控件,要实现程序运行后焦点默认在某一控件上,应该设置的属性是(C)。
A.设置Enabled的值为TrueB.设置TabIndex的值为1
C.设置TabIndex的值为0D.设置Index的值为0
4、设窗体上有一个文本框Text1,要求只能显示信息,不能输入,则应设置(B)。
Text1.Left = Text1.Left + 50
End Sub
14、在窗体上部设置一个文本框(text1),文本框的下面设置3个命令按钮,其中左边按钮(command1)中标有“单击此按钮”,中间按钮(command2)中标有“清除”,右边按钮(command3)中标有“程序结束”。当程序运行时,用鼠标单击左边按钮时,屏幕上部的文本框中显示“欢迎使用vb6.0”;如果单击中间按钮,则清除文本框中显示的内容;而如果单击右边的按钮,则结束程序。

VB实验报告参考答案(本部)

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实验报告答案-推荐下载

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

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

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

A.1Private Sub Command1_Click()Label3 = Text1End SubA.2Private Sub Form_Load()Timer1.Interval = 0End SubPrivate Sub Command1_Click() '自动Timer1.Interval = 200End SubPrivate Sub Command2_Click() '手动Timer1.Interval = 0Call MyMoveEnd SubPrivate Sub Timer1_Timer()Call MyMoveEnd SubSub MyMove()Label1.Move Label1.Left - 50If Label1.Left < 0 Then Label1.Left = Form1.Width End SubA.3Private Sub Form_Click()Text1 = Val(Text1) + 1End SubPrivate Sub Form_Load()Text1 = 0End SubA.4Private Sub Form_Click()Caption = "单击窗体,改变图片"Picture = LoadPicture(App.Path + "\n_015.bmp")Print "欢迎使用VB"End SubPrivate Sub Form_DblClick()ClsCaption = "双击窗体,卸去图片"Picture = LoadPicture("") 'End SubPrivate Sub Form_Load()Caption = "装入窗体"Picture = LoadPicture(App.Path + "\n_016.bmp")Print "装入图"End SubPrivate Sub Form_Resize() ' 该事件的作用窗体始终与图一样大'Caption = "窗体大小不变"'Form1.Width = 260 * 16 ' 260 是Tongji-2.bmp 图的宽度,象素单位'Form1.Height = 260 * 16 + 200 ' 260 是图的高度,象素单位,200 是窗体的标题栏高度End SubA.5Sub Command1_Click()Text1.FontName = "隶书"Text1.FontSize = 25End SubSub Command2_Click()Text2.Text = Text1.SelTextText2.FontName = Text1.FontNameText2.FontSize = Text1.FontSizeEnd SubB.1Private Sub Command1_Click()Text2 = Format(5 / 9 * (Val(Text1) - 32), "0.00")End SubPrivate Sub Command2_Click()Text1 = Format(9 / 5 * Val(Text2) + 32, "0.00")End Sub或Private Sub Command1_Click()Dim f!, c! ' 声明两个变量f = Val(Text1)c = 5 / 9 * (f - 32)Text2 = Format(c, "0.00") ' 保留两位小数End SubPrivate Sub Command2_Click()Dim ff!, cc! ' 声明两个变量cc = Val(Text2)ff = 9 / 5 * cc + 32Text1 = Format(ff, "0.00") ' 保留两位小数End SubB.2Label2 = Format(Val(Text1) * Val(Text1) * 3.14, "0.00") End SubPrivate Sub Command2_Click()Label3 = Format(Val(Text1) * 3.14 * 2, "0.00")End SubPrivate Sub Text1_LostFocus()If Not IsNumeric(Text1.Text) ThenMsgBox "输入有非数字字符,请重新输入", , "警告"Text1.Text = ""Text1.SetFocusEnd IfEnd Sub或Private Sub Command1_Click()Label2 = Format(Val(Text1) * Val(Text1) * 3.14, "0.00") End SubPrivate Sub Command2_Click()Label3 = Format(Val(Text1) * 3.14 * 2, "0.00")End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii = 13 ThenIf Not IsNumeric(Text1.Text) ThenText1.Text = ""End IfEnd IfEnd SubB.3Private Sub Command1_Click()n = Int(Log(2) / Log(1.008) + 1)Label1 = n & "年后人数超过26 亿"End SubB.4Private Sub Command1_Click()Dim x, dx, cdx = Text1.Textdx = UCase(x)cd = Len(x)Print "大写字母为:"; dxPrint "字符串长度为:"; cdEnd SubB.5Text1 = Int(Rnd * 900 + 100)End SubPrivate Sub Command2_Click()Dim x%, x1%, x2%, x3%x = Val(Text1)x1 = x Mod 10 ' 分离出的个位数x2 = (x Mod 100) \ 10 ' 分离出的十位数x3 = x \ 100 ' 分离出的百位数Label1 = x1 * 100 + x2 * 10 + x3End SubB.6Private Sub Form_Click()Label1 = Left(Text1, 11)Label2 = Mid(Text1, 12, 6)Label3 = Right(Text1, 5)End SubB.7Private Sub Command1_Click()PrintFor i = 1 To 5Print Tab(15 - i * 2); String(2 * i - 1, "★"); Spc(18 - 4 * (i - 1)); String(2 * i - 1, "★")Next iEnd SubPrivate Sub Command2_Click()ClsEnd Sub进一步要求:Private Sub Command1_Click()PrintFor i = 1 To 5Print Tab(15 - i * 2); String(2 * i - 1, "★"); String(10 - (2 * i - 1), "☆"); String(2 * i - 1, "★") Next iEnd SubPrivate Sub Command2_Click()ClsEnd SubB.8Private Sub Form_Click()x = Val(InputBox("输入一正实数", "计算", 0))pf = Format(x * x, "0.000")pfg = Format(Sqr(x), "0.000")lf = Format(x * x * x, "0.000")lfg = Format(x ^ (1 / 3), "0.000")Print "平方为:"; pf; Space(5); "平方根为:"; pfg; Space(5); "立方为:"; lf; Space(5); "立方根为:"; lfgEnd SubC.1Private Sub Form_Click()Dim x!, y!x = Val(InputBox("输入x 的值"))If x < 1000 Theny = xElseIf x < 2000 Theny = 0.9 * xElseIf x < 3000 Theny = 0.8 * xElsey = 0.7 * xEnd IfPrint yEnd SubC.2Private Sub Form_Click()Dim x!, y!x = Val(InputBox("输入上网时间"))If x < 10 Theny = 30ElseIf x < 50 Theny = 30 + 2.5 * (x - 10)Elsey = 30 + 2.5 * 40 + 2 * (x - 50)End IfIf y > 150 Theny = 150End IfPrint yEnd SubC.3Private Sub Command1_Click()Dim x!, y!, z!x = InputBox("input x")y = InputBox("input y")z = InputBox("input z")Print " x y z"Print " 排序前"; x; " "; y; " "; z Ifx < y Then t = x: x = y: y = tIf x < z Then t = x: x = z: z = tIf y < z Then t = y: y = z: z = tPrint " 排序后" & x & " " & y & " " & z End SubPrivate Sub Command2_Click()Dim x!, y!, z!x = InputBox("input x")y = InputBox("input y")z = InputBox("input z")Print " x y z"Print " 排序前"; x; " "; y; " "; z Ifx < y Then t = x: x = y: y = tIf y < z Thent = y: y = z: z = tIf x < y Thent = x: x = y: y = tEnd IfEnd IfPrint " 排序后" & x & " " & y & " " & z End SubC.4Dim a(3) As IntegerPrivate Sub Command1_Click()Picture1.ClsFor i = 0 To 2a(i) = Int(Rnd * 100 + 200)Picture1.Print a(i)Next iEnd SubPrivate Sub Command2_Click()Picture2.ClsDim z As IntegerFor i = 0 To 1If a(i) > a(i + 1) Thenz = a(i + 1)a(i + 1) = a(i)a(i) = zEnd IfNext iPicture2.Print a(0)Picture2.Print a(1)Picture2.Print a(2)End SubC.5Private Sub Text2_LostFocus()Dim m%, n%, y%m = Val(Text1)n = Val(Text2)If n Mod 2 <> 0 ThenMsgBox ("脚数必定为偶数")Text2 = ""Text2.SetFocusElsey = n / 2 - mIf y < 0 ThenMsgBox ("脚数必须≥2 倍的头数,请重新输入")Text2 = ""Text2.SetFocusElsex = n / 2 - mLabel2 = yLabel3 = m - yEnd IfEnd IfEnd SubC.6Private Sub Command1_Click()Dim a!, b!, c!, x1!, x2!, de!a = Text1b = Text2c = Text3de = b * b - 4 * a * ct = 2 * aIf de = 0 ThenText4 = Format(-b / t, "0.00")Text5 = Format(-b / t, "0.00")ElseIf de > 0 ThenText4 = Format((-b + Sqr(de)) / t, "0.00")Text5 = Format((-b - Sqr(de)) / t, "0.00")ElseText4 = Format(-b / t, "0.00") & "+" & Format(Sqr(Abs(de)) / t, "0.00") & "i" Text5 = Format(-b / t, "0.00") & "-" & Format(Sqr(Abs(de)) / t, "0.00") & "i" End IfEnd SubPrivate Sub Command2_Click()Text1 = ""Text2 = ""Text3 = ""Text4 = ""Text5 = ""End SubC.7Private Sub Text3_LostFocus()Select Case Trim(Text3)Case "+"Text4 = Val(Text1) + Val(Text2)Case "-"Text4 = Val(Text1) - Val(Text2)Case "*"Text4 = Val(Text1) * Val(Text2)Case "/"If Val(Text2) = 0 ThenMsgBox "分母为零,重新输入"Text2 = ""Text2.SetFocusElseText4 = Val(Text1) / Val(Text2)End IfEnd SelectEnd SubC.8Private Sub Text1_LostFocus()Select Case Trim(Text1)Case 1Text2 = "Monday"Case 2Text2 = "Tuesday"Case 3Text2 = "Wednesday"Case 4Text2 = "Thursday"Case 5Text2 = "Friday"Case 6Text2 = "Saturday"Case 7Text2 = "Sunday"Case Is > 7, Is < 1MsgBox "数字为1~7,重新输入"Text1 = ""Text1.SetFocusEnd SelectEnd Sub或者Private Sub Text1_LostFocus()If Text1 > 7 Or Text1 < 1 ThenMsgBox "数字为1~7,重新输入"Text1 = ""Text1.SetFocusElseText2 = Choose(Text1, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")End IfEnd SubD.1Private Sub Form_Click()For i = 1 To 9Print Tab(10 - i); String(2 * i - 1, Trim(Str(i)))Next iEnd SubD.2Private Sub Form_Click()For i = 1 To 10 Step 1Print Tab(i); String((20 - 2 * i), Chr(64 + i))Next iEnd SubD.3Private Sub Command1_Click()Dim s!, t!, i&s = 1t = 1For i = 1 To 100000t = t + is = s + 1 / tIf 1 / t < 0.00001 Then Exit ForNext iPrint "For 结构"; s, i; "项"End SubD.4Private Sub Command1_Click()Dim n&, pi#, i&n = InputBox("输入n 值")pi = 2For i = 1 To npi = pi * (2 * i) / (2 * i - 1) * (2 * i) / (2 * i + 1) Next iPrint "当n=" & n & "时,pi="; piEnd SubD.5Private Sub Form_Click()Dim s!, t!, i!, a%, n%a = Int(Rnd * 9 + 1)n = Int(Rnd * 6 + 5)t = 0: s = 0Print "a="; a, "n="; nFor i = 1 To nt = t * 10 + as = s + tPrint t;Next iPrintPrint "s="; sEnd SubD.6Private Sub Command1_Click()Dim s As Integers = 0For i = 1 To 9For j = 0 To 9For k = 0 To 9s = i * 100 + j * 10 + kIf s = i ^ 3 + j ^ 3 + k ^ 3 ThenPrint sEnd IfNext kNext jNext iEnd SubPrivate Sub Command3_Click()formd6.Hidemain.ShowEnd SubD.7Private Sub Command1_Click()Dim a!, x0!, x1!a = 27x0 = 2i = 0Doi = i + 1x1 = 2 * x0 / 3 + a / (3 * x0 * x0)If Abs(x1 - x0) < 0.00001 Then Exit Dox0 = x1LoopPrint x1, iEnd SubD.8Private Sub Command1_Click()s = 0x0 = 0.01For i = 1 To 30s = s + x0x0 = x0 * 2Next iPrint sEnd SubD.9Private Sub Command4_Click()Picture1.ClsPicture1.Print "x 课安排在"; "y 课安排在"; "z 课安排在"Picture1.Print ""For z = 5 To 6For x = 1 To z - 2For Y = x + 1 To z - 1X1 = Choose(Weekday(x), "周一", "周二", "周三", "周四", "周五", "周六", "周日")Y1 = Choose(Weekday(Y), "周一", "周二", "周三", "周四", "周五", "周六", "周日") z1 = Choose(Weekday(z), "周一", "周二", "周三", "周四", "周五", "周六", "周日") Picture1.Print " "; X1; " "; Y1; " "; z1Next YNext xNext zEnd SubE.1Private Sub Form_Click()Dim a(1 To 10) As IntegerFor i = 1 To 10a(i) = Int(Rnd * 71 + 30)Print a(i); " ";Next iMax = a(1)Min = a(1)Avg = a(1)For i = 2 To 10If a(i) > Max Then Max = a(i)If a(i) < Min Then Min = a(i)Avg = Avg + a(i)Next iAvg = Avg / 10PrintPrint "Max="; Max; " Min="; Min; " Avg="; AvgEnd SubE.2Private Sub Form_Click()Dim aa = Array(56, 78, 98, 88, 76, 78)For i = 0 To 5Print String(a(i) \ 5, "◆"); a(i)PrintNext iEnd SubE.3Dim a%(19)Private Sub Command1_Click()Picture1.ClsFor i = 0 To 19a(i) = Int(Rnd * 101)Picture1.Print a(i); " ";If (i + 1) Mod 4 = 0 Then Picture1.PrintNext iEnd SubPrivate Sub Command2_Click()Picture2.ClsDim s(5 To 9)For i = 0 To 19k = a(i) \ 10Select Case kCase 0 To 5s(5) = s(5) + 1Case 9 To 10 '90~100 分的人数s(9) = s(9) + 1Case 6 To 8 ' 存放其他三个分数段的下标有规律,根据K 获得s(k) = s(k) + 1End SelectNext iFor i = 5 To 9If s(i) <> 0 Then Picture2.Print "s("; i; ")的人数有"; Format(s(i), "0"); "个" Next iEnd SubE.4Private Sub Command1_Click()Picture1.ClsDim d%(1 To 10)For i3 = 1 To 10Randomized(i3) = Int(Rnd * 91 + 10)Next i3For i = 1 To 10For j = 1 To 10 - iIf d(j) < d(j + 1) Thent = d(j): d(j) = d(j + 1): d(j + 1) = tEnd IfNext jNext iFor i = 1 To 10: Picture1.Print d(i);If i Mod 5 = 0 Then Picture1.PrintNext iEnd SubE.5Dim a%(3, 3), b%(3, 3)Private Sub Form_Load()For i = 0 To 3For j = 0 To 3a(i, j) = Int(Rnd * 36 + 35)b(i, j) = Int(Rnd * 41 + 100)Next jNext iEnd SubPrivate Sub Command1_Click()Picture1.ClsFor i = 0 To 3For j = 0 To iPicture1.Print a(i, j); " ";Next jPicture1.PrintNext iEnd SubPrivate Sub Command2_Click()Picture2.ClsFor i = 0 To 3For j = i To 3Picture2.Print Tab(j * 6); b(i, j);Next jPicture2.PrintNext iEnd SubPrivate Sub Command3_Click()Picture3.Clssa = 0For i = 0 To 3sa = sa + a(i, i)Next isb = 0For i = 0 To 3sb = sb + b(i, 3 - i)Next iPicture3.Print "A 数组主对角线元素和为:"; sa Picture3.Print "B 数组副对角线元素和为:"; sb End SubE.6Private Sub Form_Click()n = InputBox("输入n 值")ReDim a6%(n + 1, n + 1)a6(0, 0) = 1: a6(1, 1) = 1: a6(1, 0) = 1For i = 2 To n + 1For j = 2 To ia6(i, j) = a6(i - 1, j - 1) + a6(i - 1, j) Picture1.Print a6(i, j); "";Next jPicture1.PrintNextEnd SubE.7Private Sub Form_Load()List1.ClearList1.AddItem "大学计算机基础"List1.AddItem "C/C++程序设计"List1.AddItem "VB 程序设计"List1.AddItem "Web 程序设计"List1.AddItem "多媒体技术与应用"List1.AddItem "数据库技术与应用"List1.AddItem "网络技术与应用"List1.AddItem "硬件技术基础"List1.AddItem "软件技术技术基础"End SubPrivate Sub List1_Click()If List2.ListCount >= 5 ThenMsgBox ("超过5 门课程,不能再选")Exit SubElseList2.AddItem List1.TextList1.RemoveItem List1.ListIndexEnd IfEnd SubE.8Sub Combo1_KeyPress(KeyAscii As Integer) Select Case KeyAsciiCase 48 To 57, 13Case ElseKeyAscii = 0End SelectIf KeyAscii = 13 ThenCombo1.AddItem Combo1.TextCombo1.Text = ""End IfEnd SubPrivate Sub Command1_Click()Dim min%, max%min = Val(Combo1.List(0))max = Val(Combo1.List(0))imin = 0imax = 0For i = 1 To Combo1.ListCount - 1If Val(Combo1.List(i)) > max Thenimax = imax = Combo1.List(i)ElseIf Val(Combo1.List(i)) < min Thenimin = imin = Combo1.List(i)End IfNext it = Combo1.List(0)Combo1.List(0) = Combo1.List(imin)Combo1.List(imin) = tt = Combo1.List(Combo1.ListCount - 1)Combo1.List(Combo1.ListCount - 1) = Combo1.List(imax) Combo1.List(imax) = tEnd SubE.9Private Sub Form_Click()For i = 0 To Screen.FontCount - 1If Asc(Left(Screen.Fonts(i), 1)) < 0 ThenPicture1.Print Screen.Fonts(i)Picture2.FontName = Screen.Fonts(i)Picture2.Print "商丘师范学院"End IfNext iEnd SubE.10Private Type clerknumber As String * 3name As String * 5salary As IntegerEnd TypeDim a(0 To 4) As clerk, n%Private Sub Command1_Click()If n >= 5 ThenMsgBox ("输入人数超过数组声明的个数")ElseWith a(n).number = Text1.name = Text2.salary = Text3Picture1.Print a(n).number, a(n).name, a(n).salary PrintEnd Withn = n + 1Text1 = ""Text2 = ""Text3 = ""End IfEnd SubPrivate Sub Command2_Click()Dim t As clerk, i%, j%For i = 0 To n - 1For j = i To n - 1If a(i).salary < a(j + 1).salary Thent = a(i): a(i) = a(j + 1): a(j + 1) = tEnd IfNext jNext iPicture1.ClsPicture1.Print "工号姓名工资" For i = 0 To n - 1Picture1.Print a(i).number, a(i).name, a(i).salaryPrintNext iEnd SubF.1Private Sub Form_Click()Dim a(1 To 10), amin, i%For i = 1 To 10a(i) = -Int(Rnd * 101 + 300)Print a(i);Next iCall s(a(), amin)PrintPrint "min="; aminEnd SubSub s(b(), min)Dim i%min = b(LBound(b))For i = LBound(b) + 1 To UBound(b)If b(i) < min Then min = b(i)Next iEnd SubF.2Private Sub Command1_Click()Dim mm%, nn%mm = Val(Text1)nn = Val(Text2)Picture1.Print mm; Tab(6); nn; Tab(12); gcd(mm, nn) End SubFunction gcd%(ByVal m%, ByVal n%)If m < n Then t = m: m = n: n = tr = m Mod nDo While (r <> 0)m = n: n = r: r = m Mod nLoopgcd = nEnd FunctionF.3Dim x!Private Sub Command1_Click()Print "调用标准函数Sin 的结果"; Sin(x)End SubPrivate Sub Command2_Click()Print "调用自定义函数MySin 的结果"; MySin(x) End SubFunction MySin(x!) As DoubleDim i%, t!, s!t = xs = ti = 1Do While Abs(t) > 0.00001t = -1 * t * x * x / ((i + 1) * (i + 2))s = s + ti = i + 2LoopMySin = sEnd FunctionPrivate Sub Command3_Click()x = InputBox("输入要计算正弦函数的角度值x") x = x * 3.14 / 180End SubF.4Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 ThenIf Not IsNumeric(Text1) ThenMsgBox "输入非数字串,重新输入"Text1.Text = ""Text1.SetFocusElseIf IsH(Text1) ThenPicture1.Print Text1; " ★"ElsePicture1.Print Text1End IfText1 = ""End IfEnd IfEnd SubFunction IsH(ss As String) As BooleanDim i%, Ls%IsH = Truess = Trim(ss)Ls = Len(ss)For i = 1 To Ls \ 2If Mid(ss, i, 1) <> Mid(ss, Ls + 1 - i, 1) ThenIsH = FalseExit FunctionEnd IfNext iEnd FunctionF.5Function prime(ByVal m As Integer) As Booleanprime = TrueDim i%For i = 2 To m - 1If (m Mod i) = 0 Then prime = False: Exit Function '注意冒号和exit 的范围Next iEnd FunctionPrivate Sub Command1_Click()n = 0For i = 6 To 100 Step 2For j = 3 To i \ 2If prime(j) ThenIf prime(i - j) ThenList1.AddItem i & " =" & j & " +" & i - jn = n + 1End IfEnd IfNext jNext iPicture1.Print " 6 和100 之间共有"; n; "对素数和"End SubF.6Dim a%()Private Sub Form_Click()Print "1000 以内的完数为:"For i = 1 To 1000If IsWs(i) ThenPrint i; "=1";For j = 1 To UBound(a)Print "+"; a(j);Next jPrintEnd IfNext iEnd SubFunction IsWs(m) As BooleanDim s%s = 0For i = 1 To m \ 2If m Mod i = 0 ThenReDim Preserve a(j)a(j) = ij = j + 1s = s + iEnd IfNext iIf m = s Then IsWs = TrueEnd FunctionF.7Private Sub DeleStr(s1 As String, ByVal s2 As String)Dim i%ls2 = Len(s2)i = InStr(s1, s2)Do While i > 0s1 = Left(s1, i - 1) + Mid(s1, i + ls2) ' 在s1 中去除s2 子串i = InStr(s1, s2)LoopEnd SubPrivate Sub Command1_Click() ' 调用DeleStr 子过程Dim ss1 As Stringss1 = Text1Call DeleStr(ss1, Text2)Text3 = ss1End SubPrivate Sub Command2_Click()End SubF.8Private Sub Command1_Click()Dim maxw$maxlen Text1 & " ", maxwText2 = maxwEnd SubSub maxlen(s$, maxw$)Dimword$ maxw = ""Do While s <> ""i = InStr(s, " ")word = Left(s, i - 1)If Len(word) > Len(maxw) Then maxw = words = Mid(s, i + 1)LoopEnd SubG.1Private Sub Command1_Click()List1.ClearList1.AddItem Combo1If Option1 Then List1.AddItem "Pentium II"If Option2 Then List1.AddItem "Pentium I"If Option3 Then List1.AddItem "Celeron"List1.AddItem Text1If Check1 Then List1.AddItem "声卡"If Check2 Then List1.AddItem "Modem"If Check3 Then List1.AddItem "网络适配器"End SubPrivate Sub Text1_LostFocus()st = UCase(Trim(Text1))le = Len(st)If Not IsNumeric(Left(st, le - 2)) Or Right(st, 2) <> "MB" Then MsgBox "有不合法字符!"Text1 = ""Text1.SetFocusEnd IfEnd SubG.2Private Sub Check1_Click()Picture1.Font.Bold = Not Picture1.Font.BoldEnd SubPrivate Sub Check2_Click()Picture1.Font.Italic = Not Picture1.Font.BoldEnd SubPrivate Sub Command1_Click()Picture1.ClsIf Option1 ThenPicture1.Print Sin(Val(Text1))ElseIf Option2 ThenPicture1.Print Exp(Val(Text1))ElseIf Option3 ThenPicture1.Print Sqr(Val(Text1))End IfEnd SubPrivate Sub return_Click(Index As Integer)Form6.ShowUnload Form2End SubG.3Private Sub HScroll1_Change()Text1 = VScroll1.ValueText2 = HScroll1.ValueText3 = HScroll2.ValueText4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), "0.00") Text5 = Format(Val(Text4) + Val(Text1), "0.00")End SubPrivate Sub HScroll2_Change()Text1 = VScroll1.ValueText2 = HScroll1.ValueText3 = HScroll2.ValueText4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), "0.00") Text5 = Format(Val(Text4) + Val(Text1), "0.00")End SubPrivate Sub VScroll1_Change()Text1 = VScroll1.ValueText2 = HScroll1.ValueText3 = HScroll2.ValueText4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), "0.00") Text5 = Format(Val(Text4) + Val(Text1), "0.00")End SubG.4Dim t As SinglePrivate Sub Command1_Click()t = InputBox("输入倒计时分钟数")t = t * 60ProgressBar1.Min = 0ProgressBar1.Max = tProgressBar1.Value = tEnd SubPrivate Sub Command2_Click()Timer1.Interval = 1000ProgressBar1.Visible = TrueEnd SubPrivate Sub Timer1_Timer()Dim m%, s%t = t - 1ProgressBar1.Value = tm = t \ 60s = t Mod 60Label1 = m & "分" & s & "秒"If t = 0 ThenMsgBox " 时间到!"Timer1.Interval = 0ProgressBar1.Visible = FalseEnd IfEnd SubG.5Private Sub Command1_Click()CommonDialog1.ShowColorLabel1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Command2_Click()CommonDialog1.ShowOpeni = Shell("C:\WINDOWS\NOTEPAD.exe " + CommonDialog1.FileName, vbNormalFocus) End SubG.6rivate Sub bold_Click()Text1.FontBold = Not Text1.FontBoldbold.Checked = Not bold.CheckedEnd SubPrivate Sub del_Click()Text1 = ""End SubPrivate Sub end_Click()EndEnd SubPrivate Sub font12_Click()Text1.FontSize = 12End SubPrivate Sub font16_Click()Text1.FontSize = 16End SubPrivate Sub Form_Load()bold.Checked = Falseitalic.Checked = FalseEnd SubPrivate Sub italic_Click()Text1.FontItalic = Not Text1.FontItalicitalic.Checked = Not italic.CheckedEnd SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then PopupMenu menu2End SubG.7Private Sub Command1_Click()CommonDialog1.ShowColorLabel1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Command2_Click()CommonDialog1.ShowOpeni = Shell("C:\WINDOWS\NOTEPAD.exe " + CommonDialog1.FileName, vbNormalFocus) End SubPrivate Sub return_Click(Index As Integer)Form6.ShowUnload Form5End SubG.8G.9Private Sub 结束_Click()EndEnd SubPrivate Sub 删除最大值_Click()max = List1.List(0)For i = 1 To List1.ListCount - 1If max < List1.List(i) Then max = List1.List(i): j = i Next iList1.RemoveItem jEnd SubPrivate Sub 删除最小值_Click()min = List1.List(0)For i = 1 To List1.ListCount - 1If min > List1.List(i) Then min = List1.List(i): j = i Next iList1.RemoveItem jEnd SubPrivate Sub 随机产生_Click()RandomizeFor i = 0 To 9List1.List(i) = Int(Rnd * 30 + 70)Next iEnd SubPrivate Sub 添加数据_Click()List1.AddItem Int(Rnd * 30 + 70)End SubPrivate Sub 统计_Click()Dim max%, min%, ave!, m%, n%max = List1.List(0)min = List1.List(0)ave = List1.List(0)m = 0n = 0For i = 1 To List1.ListCount - 1If max < List1.List(i) Then max = List1.List(i): m = i If min > List1.List(i) Then min = List1.List(i): n = i ave = ave + List1.List(i)Next iForm2.Text1 = List1.List(n)Form2.Text2 = List1.List(m)Form2.Text3 = Format(ave / List1.ListCount, "0.00") Form2.ShowEnd SubG.10Private Sub experimentG2_Click()Form2.ShowEnd SubPrivate Sub experimentG3_Click()Form3.ShowEnd SubPrivate Sub experimentG4_Click()Form4.ShowEnd SubPrivate Sub experimentG5_Click()Form5.ShowEnd SubPrivate Sub font_12_Click()Text1.FontSize = 12End SubPrivate Sub font_16_Click()Text1.FontSize = 16End SubPrivate Sub rnd10_Click()RandomizeFor i = 0 To 9List1.List(i) = Int(Rnd * 30 + 70)Next iEnd SubPrivate Sub stat_Click()Dim max%, min%, ave!, m%, n%max = List1.List(0)min = List1.List(0)ave = List1.List(0)m = 0n = 0For i = 1 To List1.ListCount - 1If max < List1.List(i) Then max = List1.List(i): m = i If min > List1.List(i) Then min = List1.List(i): n = i ave = ave + List1.List(i)Next istat2.Text1 = List1.List(n)stat2.Text2 = List1.List(m)stat2.Text3 = Format(ave / List1.ListCount, "0.00")stat2.ShowEnd SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then PopupMenu caidan2, vbPopupMenuCenterAlignEnd SubPrivate Sub xie_Click()Text1.Font.Italic = Not Text1.Font.BoldEnd SubH.1Private Sub Command1_Click()Open "c:\score" For Output As #1Print #1, "051023", "王海涛", 66Print #1, "052498", "周文英", 88Print #1, "050992", "陈建东", 77Open "c:\score1" For Output As #2Write #2, "051023", "王海涛", 66Write #2, "052498", "周文英", 88Write #2, "050992", "陈建东", 77Closei1 = Shell("NOTEPAD.exe" + " c:\score", vbNormalNoFocus)i2 = Shell("NOTEPAD.exe" + " c:\score1", vbNormalNoFocus)End SubPrivate Sub Command2_Click()Dim no As String, name As String, s As IntegerOpen "c:\score" For Input As #1Do While Not EOF(1)Line Input #1, linedataList1.AddItem linedataLoopOpen "c:\score1" For Input As #2Do While Not EOF(2)Input #2, no, name, sList2.AddItem no & name & sLoopCloseEnd SubH.2Private Sub Command1_Click()Dim fib%(0 To 9), i%Open "c:\fb.dat" For Output As #1For i = 0 To 9If i = 0 Or i = 1 Thenfib(i) = iElsefib(i) = fib(i - 1) + fib(i - 2)End IfPrint #1, """Fib(" & i & ")""," & fib(i)Next iClose #1i = Shell("NOTEPAD.exe" + " c:\fb.dat", vbNormalNoFocus) End SubPrivate Sub Command2_Click()Dim st$, n%, sum%Open "c:\fb.dat" For Input As #1Do While Not EOF(1)Input #1, st, nsum = sum + nList1.AddItem st & "=" & nLoopClose #1List1.AddItem " 合计:" & sumList1.AddItem "平均:" & sum / 10End SubH.3H.4Private Type studtypeno As String * 4name As String * 6mark As SingleEnd TypeDim student As studtype, stud(1 To 5) As studtype, t As studtypePrivate Sub Command1_Click()Open "d:\score.dat" For Random As #1 Len = Len(student) With student.no = "0001".name = "星期一"。

VB编程实验报告答案 完整版

VB编程实验报告答案 完整版

实验一:一、选择1.D2.D3.B4.A5.B6.C7.CD8.D9.D 10. BC11. A 12.D 13. D 14. C 15. A二、填空1.windows2. 中断3.工具箱4.代码5.分类6.form2.show7. 出现语法错误8. 错9. 事件10. 面向对象11.工程文件结构12. 工程13. 设计程序代码14. 双击窗体15. C:\Program Files\Microsoft Visual Studio\VB98 或者VB的安装文件夹16.属性17.方法18.font 19. form_load() 20.对象实验二:一、选择1.B2.C3. B4.C5.C6.C7.B8.B9.D 10. A11. C 12.C 13. C 14. B 15. A16.C 17.B 18.D 19.C 20. C二、填空1. Form_Click()2. Interval、50003..vbp .frm4.left top Height、Width twip5.picture6.load7. locked8. font Alignment9. GotFocus() LostFocus() 10. 属性窗口程序代码实验三:一、选择1.A2.BC3.BC4.A5.A6.A7.BCD8.D9.B 10. B11. B二、判断题不合法的变量:3. 4. 5. 6. 8. 10. 11. 14.15. 16.三、1、abs(x+y)2. (3+x*y)^23. (-b+sqr(b^2-4*a*c))/(2*a)4.sin(30*3.14/180)+exp(2)四、1. int(rnd* 71+20) 或int(rnd* 71)+202. x<0 and y>0 or x>0 and y<0 或者x*y<03. x mod 3=0 or x mod 7=0或x/3=x\3 or x/7=x\74. x>=10 and x<205. x>="A" and x<="Z"6. left(s,3)实验四:一、选择1.C2.D3. C4.D5.A6.D7.B8.B9.A 10. C二、填空1. 48.71E-01, -4.87122. 关系、逻辑、算术3. 900,100,mid(s,2,1)4.m、1,2,3 、print m & "月是第二季度"、end select 三、1. X=4 y=132. 10实验五一、选择B C B A C二、填空(1)for x=2 to 10s*(1-1/x)(2) 1 t>1E-6(3) j t(4) 5 11 5实验六一、选择B C C C D D D D C A实验七一、选择1C 2C 3D 4A 5B 6D 7AB 8A 9A 10A 二、填空(1)n!(2)1+1+2+3+4+……+n(3)n是否是素数(4)冒泡排序(5)递归调用产生斐波那契数列(6)求最大公约数和最小公倍数第八页编程2-1Private Sub Command1_Click()Label3 = Val(Text1) * Val(Text2)End SubPrivate Sub Command2_Click()Label3 = Val(Text1) / Val(Text2)End Sub2-2Private 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 = FalseEnd Sub2-5Private Sub Form_Load()Image1.Picture = LoadPicture("C:\Documents and Settings\All Users\Documents\My Pictures\示例图片\Sunset.jpg")End SubPrivate Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Image1_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第11页编程2-3Private Sub Command1_Click()Dim x%, y%x = Int(Rnd * 900 + 100)Print "产生的随机数:"; xy = (x Mod 10) * 100 + (x \ 10 Mod 10) * 10 + x \ 100Print "反序数:"; Format(y, "000")End SubPrivate Sub Command2_Click()Dim x%, y As Stringx = Int(Rnd * 900 + 100)Print "产生的随机数:"; xy = Trim(Str(x))Print "反序数:" & Right(y, 1) & Mid(y, 2, 1) & Left(y, 1)End SubPrivate Sub Form_Load()End Sub2-4Private Sub Command1_Click()Dim m%, n%Randomizem = Val(Text1): n = Val(Text2)x = Int(Rnd * (n - m + 1) + m)y = Int(Rnd * (n - m + 1) + m)z = Int(Rnd * (n - m + 1) + m)Label3 = m & "到" & n & "之间的3个随机数为: " & x & Space(3) & y & Space(3) & zEnd SubPrivate Sub Form_Load()End Sub2-5Private Sub Command1_Click()Label1.Caption = DateEnd SubPrivate Sub Command2_Click()Label2.Caption = TimeEnd SubPrivate Sub Command3_Click()Label3.Caption = WeekdayName(Weekday(Date)) End SubPrivate Sub Form_Load()End Sub第十五页2-1方法一Private Sub Command1_Click()Dim x!, a!, aa%, b!, bb%, c!, cc$x = Val(Text1)a = x * 180 / 3.14aa = Int(a)b = (a - aa) * 60bb = Int(b)c = (b - bb) * 60cc = Format(c, "#.000")Label2 = "弧度" & Text1 & "转换为" & aa & "度" & bb & "分" & cc & "秒"End Sub方法二Private Sub Command1_Click()x = InputBox("请输入弧度数值", "弧度转换", 0)xx = Val(x)a = x * 180 / 3.14aa = Int(a)b = (a - aa) * 60bb = Int(b)c = (b - bb) * 60cc = Format(c, "#.000")MsgBox "弧度" & x & "转换为" & aa & "度" & bb & "分" & cc & "秒"End Sub2-2Private Sub Command1_Click()Dim x%x = Val(Text1)If x / 400 = x \ 400 Or x Mod 4 = 0 And x Mod 100 <> 0 ThenLabel2 = Text1 & "年是闰年"ElseLabel2 = Text1 & "年不是闰年"End IfEnd Sub2-3方法二Private 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, zEnd SubPrivate Sub Form_Load()End Sub方法一Private Sub Command1_Click() Dim x%, y%, z%x = Val(Text1)y = Val(Text2)z = Val(Text3)If x > y Then t = x: x = y: y = t If y > z Thent = y: y = z: z = tIf x > y Thent = x: x = y: y = tEnd IfLabel1 = x & Space(5) & y & Space(5) & z End Sub2-4方法一Private Sub Command1_Click()x = Val(InputBox("请输入上网时间:"))If x <> -1 ThenSelect Case xCase Is < 10fei = 25Case 10 To 50fei = x * 2Case 50 To 100fei = x * 1.5Case Is >= 100fei = x * 1End SelectMsgBox "上网费用为:" & fei & "元"End IfPrivate Sub Command2_Click()EndEnd SubPrivate Sub Form_Load()End Sub方法二Private Sub Command1_Click()Dox = Val(InputBox("请输入上网时间:", , -1)) If x <> -1 ThenSelect Case xCase Is < 10fei = 25Case 10 To 50fei = x * 2Case 50 To 100fei = x * 1.5Case Is >= 100fei = x * 1End Selectzongfei = zongfei & Space(3) & fei MsgBox zongfei, , "上网费用为" ElseExit DoEnd IfLoopEnd SubPrivate Sub Command2_Click() EndEnd SubPrivate Sub Form_Load()End Sub2-5第18页2-3Private 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 Sub]2-5Private Sub Command1_Click()x = Val(Text1)y = x * 4n = 0Do While x <= yx = x * (1 + 0.1)n = n + 1Print xLoopPrint x, nEnd Sub2-6Private Sub Command1_Click()n = Val(InputBox("输入计算到第几项:", , 0)) For i = 1 To ns = s + (-1) ^ (i + 1) * iNextPrint n, sEnd SubPrivate Sub Form_Load()-8End Sub2-8Private Sub Command1_Click()Dim s As Double, pi As Doublen = 1: s = 0Do While 1 / (2 * n - 1) >= 0.0001s = s + (-1) ^ (n + 1) * 1 / (2 * n - 1)n = n + 1Looppi = 4 * sPrint piEnd Sub2-9Private Sub Command1_Click()For n = 100 To 999k = Trim(Str(n))If n = Left(k, 1) ^ 3 + Mid(k, 2, 1) ^ 3 + Right(k, 1) ^ 3 Then Print nNextEnd Sub2-11Private Sub Command1_Click()s = 0: Max = 0: Min = 1000For i = 1 To 20Randomizex = Int(Rnd * 50 + 51)Print x;If x > Max Then Max = xIf x < Min Then Min = xs = s + xNext iaver = s / 20PrintPrint "max="; Max, "min="; Min, "aver="; aver End SubPrivate Sub Form_Load()End Sub。

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_ 班级______ ______姓名_____ ____实验一 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实验作业参考答案VB实验作业参考答案引言:Visual Basic(VB)是一种基于事件驱动的编程语言,广泛应用于Windows操作系统的软件开发。

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

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

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

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

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

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

VB实验报告(含答案)

VB实验报告(含答案)
除数
标签
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程序设计学习与实验指导书答案(包含实验答案)

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

VB学习与实验指导测试题参考答案第一章第二章第三章第四章第五章第六章第七章第八章第九章综合测试题一综合测试题二下篇实验教程实验2 Visual Basic 变量、函数与表达式的使用实验2-1 算术运算符的使用13178332262-2-22007-10-153 2.857143 2.85714285714286实验2-2 字符运算符的使用20071020071020172007-10-10102007-10-20出错,类型不匹配实验2-3 关系运算符的使用FalseFalseFalseFalseFalseFalseFalseTrueFalseTrue实验2-4 逻辑运算符的使用TrueTrueFalseTrueFalseFalseTrueTrueFalse5-59实验2-5 常用函数的使用3.14 3.147.389056098930651 -1 .999999998205103 4-1 1 0.70554755825 251250 0A a65 9748 688 -98 -89 -9aaa 4.5 aaa4.516 5Visua 6.0sua Basic Basic 6.0abcde EFGBasic Basic BasicVisual Basic 6.0 Basic8 8aaa dd2011-3-152011-3-15 14:35:5215320113001.731.731.7317.32E-010173%实验3 算法基础及程序控制结构实验3-1 三个数的交换A=CC=BB=TBC实验3-2 求周长和面积Const PI=3.14159262*PI*RPI*R*RPicture1.ClsFormat(L, ".00")Format(M, ".00")实验3-3 求分段函数的值x=Val(Text1.Text)y=1+Sin(x)y=Log(x)Text1.Text = ""Text2.Text = ""实验3-4 求一元二次方程的根Val(Text2.Text)Val(Text3.Text)b ^ 2 - 4 * a * c"x1=" & (-b + Sqr(delt)) / (2 * a)"x2=" & (-b - Sqr(delt)) / (2 * a)Text2.Text = ""Text3.Text = ""End实验3-5 判断素数N Mod k = 0k=NN Mod i=0k=2实验3-6 求最大公约数和最小公倍数M<NL=ML=NM Mod k = 0 And N Mod k = 0Text3.Text = kExit ForM>NL=ML=Nk Mod M = 0 And k Mod N = 0Text4.Text = kExit For实验3-7 判断升序数、降序数CStr(N)Len(S) – 1Mid(S, k, 1) >= Mid(S, k + 1, 1)k = Len(S)N = Val(Text1.Text)S = CStr(N)For k = 1 To Len(S) - 1If Mid(S, k, 1) <= Mid(S, k + 1, 1) Then Exit For Next kk = Len(S)实验3-8 判断回文数1Len(s)\2-1Mid(S, k, 1) <> Mid(S, Len(S) - k + 1, 1)k = Len(S) \ 2Mid(S, k, 1) + S1S = S1实验3-9 求级数的值Val(Text1.Text)1x ^ ns * nt / s <= 10 ^ -6Text2.Text = y实验3-10 查找数字串并求和Text1.Text = ""Text2.Text = ""List1.ClearText1.TextFalseWhile Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" Flag = Truek = k * 10 + Mid(s, i, 1)i = i + 1Flag = Truesum + kText2.Text = sum实验3-11 随机产生20个奇数Int((99 - 10 + 1) * Rnd) + 10a Mod 2 = 1n Mod 5 = 0Picture1.Cls实验3-12 加密解密Chr(Asc("a") + (Asc(c) - Asc("a") + 3) Mod 26)c = Chr(Asc("A") + (Asc(c) - Asc("A") + 3) Mod 26) c & s2Text2.TextLen(s2)Mid(s2, i, 1)c = Chr(Asc("a") + (Asc(c) - Asc("a") + 23) Mod 26) c = Chr(Asc("A") + (Asc(c) - Asc("A") + 23) Mod 26) c & s1s1Text1.Text = ""Text2.Text = ""实验3-13 统计单词个数Text1.TextMid(s, i, 1) <> " " And i <= Len(s)i = i + 1Mid(s, start, i - start)nText1.Text = ""List1.Clear实验4 数组的使用实验4-1 一维数组的产生及输出i = 1 To 20Int((9 - 0 + 1) * Rnd + 0)i = 1 To 20Print a(i);Printi = 1 To 20Picture1.Print a(i);If i Mod 5 = 0 Then Picture1.Printi = 1 To 20Text1.Text & Space(2) & a(i)If i Mod 5 = 0 Then Text1.Text = Text1.Text & vbCrLf v In aIf i Mod 5 = 0 Then Picture2.Print实验4-2 选手得分Int((50 - 10 + 1) * Rnd + 10) / 10i = 1 To 6sum = sum + score(i)max = score(1)min = score(1)score(i) > max Then max = score(i)score(i) < min Then min = score(i)(sum - max - min) / 4实验4-3 产生10个互不相同的整数Int((999 - 10 + 1) * Rnd + 10)t Mod 10 = 5Then Exit Forn= n + 1a(i) = tFor i = 1 To 10Print a(i);If i Mod 5 = 0 Then PrintNext i实验4-4 统计数字出现的次数IsNumeric(S) = FalseExit SubLen(S)c >= "0" And c <= "9"A(c) = A(c) + 1A(k) <> 0m = m + 1实验4-5 排序1 To 10Int((99 - 10 + 1) * Rnd + 10)Text1.Text & A(n) & " "1 To 9i + 1 To 10A(i) > A(j)T = A(j)A(j) = A(i)A(i) = T1 To 910 - iA(j) > A(j + 1)T = A(j + 1)A(j + 1) = A(j)A(j) = T1 To 10Text3.Text = Text3.Text & A(i) & " "10T = A(i)ji - 1k + 11 To 10Text4.Text = Text4.Text & A(i) & " "实验4-6 二维数组的产生及输出1 To 41 To 5Int((9 - 0 + 1) * Rnd + 0)1 To 41 To 5Print A(i, j);Print1 To 41 To 5Picture1.Print A(i, j);Picture1.Print1 To 41 To 5Text1.Text = Text1.Text & A(i, j) & " "Text1.Text = Text1.Text & vbCrLf实验4-6 查找最大和最小元素及其位置1 To 31 To 4A(i, j) = Int((99 - 10 + 1) * Rnd + 10)Picture1.Print A(i, j);Picture1.PrintA(1, 1), 1, 1A(1, 1), 1, 1A(i, j)ijA(i, j) < minA(i, j)ij"最大元素" & "A(" & maxi & "," & maxj & ")=" & max "最小元素" & "A(" & mini & "," & minj & ")=" & min实验4-7 矩阵转置Dim A() As Integer"请输入N的值"ReDim A(N, N) As IntegerFor i = 1 To NFor j = 1 To NA(i, j) = Int((99 - 10 + 1) * Rnd + 10)Text1.Text = Text1.Text & A(i, j) & " "Next jText1.Text = Text1.Text & vbCrLfNext it = A(i, j)A(i, j) = A(j, i)A(j, i) = tFor i = 1 To NFor j = 1 To NText2.Text = Text2.Text & A(i, j) & " "Next jText2.Text = Text2.Text & vbCrLfNext i实验5 过程实验5-1 孪生素数和降序素数Dim i As IntegerFor i = 2 To N - 1If N Mod i = 0 Then Exit FunctionNext iPrime = TrueDim a As IntegerDim b As Integera = N \ 10b = N Mod 10If a > b ThenDecNumber = TrueElseDecNumber = FalseEnd If10 To 100Prime(i) = True And Prime(i + 2) = TrueList2.AddItem i & "和" & i + 2DecNumber(i) = True And Prime(i) = TrueList3.AddItem i实验5-2 求多项式和k = 1a = f(x, k)S + ak = k + 1Single As SingleDim i As Integer, a As Singlea = (x + 1) / xFor i = 2 To ka = a * (x + i) / ((2 * i - 1) * x)Next ia实验5-3 进制转换Asc(C) - Asc("A") + 10Left(S, k - 1)Mid(S, k + 1)Change(Mid(S2, i, 1)) * N ^ (0 - i)T1 + T2Tran(8, S)Tran(16, S)Not (C >= "0" And C <= "7" Or C >= "A" And C <= "F" Or C = ".")实验5-4 Armstrong数i As Long, a As Long, b As LongCombo1.Text实验5-5Option Base 1Dim a(5) As IntegerDim b(5) As Integerb(i) = i * i + 1Text2.Text = Text2.Text & b(i) & " "1 To 51 To 5Gcd(a(i), b(j)) = 1Gcd = KExit For实验5-6Create(a)Output(a)Sort(a)Output(a)GetMaxMin(a, MaxData, MinData)MaxDataMinDataAverage(a)Int((99 - 10 + 1) * Rnd + 10)1 To UBound(a)a(i);a(i) > a(j)t = a(j)a(j) = a(i)a(i) = t2 To UBound(a)a(i) > MM = a(i)a(i) < NN = a(i)s = s + a(i)Average = s / UBound(a)实验6 界面设计实验6-1 用户登陆MsgBox "请登录!"PassWordInput=TxtPassW.TextUserIdInput=UserId And PassWordInput=PassWordCmdReset_Click实验6-2 学籍登记OptXb(0).Value = TrueList1.AddItem Space(4) & xh & Space(6) & xm & Space(6) & xb & Space(12) & xy & Space(16) & zy & Space(4)List1.RemoveItem List1.ListIndex实验6-3 字体格式设置Select Case OpFontCheck2.Value = 1OpColor = IndexOpFont = Index实验6-4 兴趣调查List1.AddItem ItemEndSelect Case IndexItem = Text1.Text实验6-5 调色板。

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

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

自测1程序代码Private Sub Command1_Click() = + 3End 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() = + 30= + 20= 1End Sub初始窗口:单击缩小两倍之后的窗口:单击向右下角移动之后的窗口:自测题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 Command1_Click() = ""= ""End SubPrivate Sub Command2_Click() = Val + ValEnd SubPrivate Sub Command3_Click() EndEnd Sub初始化窗口:单击运算之后窗口:单击清除之后的窗口:单击退出之后的窗口:自测练习1Private Sub Command1_Click() Dim a$a == Left(a, 2)End SubPrivate Sub Command2_Click() a == Right(a, 2)End SubPrivate Sub Command3_Click()= &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 + i= FalsePrint "加密前的4位整数是7439"; (Chr(10)); "加密后的结果是"; l End Sub初始界面单击窗体运行后的界面自测练习1Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox("输入第一个数", "输入一个数", 8))b = Val(InputBox("输入第一个数", "输入一个数", 7))c = a + bd = a - be = a * bf = a / bf = Fix(f * 100 + / 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 Then Print "直角"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 = 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:自测练习1Option Base 1Private Sub Form_Click() Dim i%, a(1 To 20) As Integera(1) = 1: a(2) = 1 Print 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() = 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 4a(i, j) = Int(Rnd * 10) + 1a(i, j);Next jNext i"对角线的元素如下"For i = 1 To 4a(i, i);Next iFor i = 1 To 4a(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 4 For j = 1 To 4a(i, j);Next jNext iEnd Sub运行初始界面:运运行结果界面:自测练习1Sub itostr(a As Integer) Dim b%, c$a = ValWhile a >= 1c = Chr(a Mod 10 + 48) & ca = a \ 10Wend= cEnd SubPrivate Sub Command1_Click() Dim a As Integera = ValCall itostr(a)End Sub运行初始界面:运行结果界面:验证其他数字:自测练习2:Public Function area(n) As Double Dim c#, d#, e#, s#n = Valc = (1 - 0) / nWhile e <= 1d = I * c:e = (I + 1) * cs = s + (Sin(d) + Sin(e)) * c / 2I = I + 1Wendarea = sEnd FunctionPrivate Sub Command1_Click() Dim s As DoubleCall area(n)= 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运行初始界面:插入数据:运行结果:蓝志鹏资源1102 实验8自测练习1:Private Sub Command1_Click()If = 1 Then= "报名参加羽毛球比赛"End IfIf = 1 Then= "报名参加乒乓球比赛"End IfIf = 1 And = 1 Then= "报名参加羽毛球,乒乓球比赛" End IfEnd Sub运行初始界面:运行结果:自测练习4:Private Sub Form_Load() = 2= 24= "黑体"= &HFF&End SubPrivate Sub Option1_Click() = "我是学生"End SubPrivate Sub Option2_Click() = "我是教师"End SubPrivate Sub Option3_Click() = "我是工人"End SubPrivate Sub Option4_Click() = "我是农民"End Sub运行初始界面:运行结果:。

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实验11 Sub过程

VB实验11 Sub过程

下一页
退 出
第4 页 Visual Basic程序设计实验指导
二、预备知识
目的和要求 预备知识
上一页
下一页
退 出
定义Sub过程的一般形式如下: [Private | Public] [Static] Sub <过程名 >([<形式参数列表>]) [过程级变量和常量声明] 语句块 [Exit Sub] 语句块 End Sub
第8 页 Visual Basic程序设计实验指导
二、预备知识
目的和要求 预备知识
上一页
下一页
退 出
通常情况下(指没有可选参数的情况下),实 参与形参的个数必须相等,实参与形参的数据传 递是按位置传递的,而不是按名字传递的,即第1 个实参传递给第 1个形参,第 2 个实参传递给第 2 个形参,……。 按数值方式传递的形参,其对应的实参的数据 类型只要与形参相匹配即可,而按地址方式传递 的形参,其对应的实参变量的数据类型必须与形 参相同。
下一页
退 出
【要求】 ( 1 )通过文本框 Text1 输入一个含有数字的 字符串,通过文本框Text2输出结果。 ( 2 )程序运行时, Text1 中有初始字符串: 31A9R100YRW12.7ds6。 ( 3 )单击“求数字和”按钮,分离出其中的 数字并按指定格式在 Text2 中显示数字和;单击 “清除”按钮,将清除两个文本框中的内容,并 将焦点置于 Text1 中;单击“退出”按钮,结束 程序的运行。
第25页 Visual Basic程序设计实验指导
实验11-4
目的和要求 预备知识
上一页
下一页
退 出
【题目】 输出最长单词。 在一个文本框中 输入一串单词 (单词之间用空 格隔开),在另 一个文本框中输 出所有的最长单 词,如图11-4所 示。

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

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

习题一答案在教材上找。

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

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

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

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

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

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

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

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

VB中常用的对象是控件。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

VB实验作业参考答案

VB实验作业参考答案
2.编程题:
1)单击窗体后在窗体上显示“您好!×××同学”。
要求:(1)程序中用自己的姓名替代“×××”。(2)文字以红色、仿宋体、加粗、三号字显示,并在字下加横线。(3)建立一个命令按钮,结束时单击此按钮退出。
答案参照课本P27的例1-6。
2)设计一窗体,窗体上有1个文本框(Text1)、1个命令按钮(Command1),运行时文本框中显示“Visual Basic程序设计”,命令按钮标题为“结束”,文本框及命令按钮能随窗体大小的调整而自动调整大小及位置,其中调整文本框使其:Left=0,Top=0,宽度和高度都为窗体的一半;命令按钮:始终位于窗体右下角位置。请编写:
Command1.Top = Form1.ScaleHeight - Command1.Height
End Sub
Private Sub Form_Resize()
Call Form_Load
End Sub
Private Sub Command1_Click()
End
Dim r1 As Single, r2 As Single, Rp As Single, Rs As Single
r1 = InputBox("请输入第一个电阻值:")
r2 = InputBox("请输入第二个电阻值:")
Rp = (r1 * r2) / (r1 + r2)
Rs = r1 + r2
程序代码:
Private Sub Command1_Click()
Dim sg As String, tz As String, bz As String
sg = Text1.Text

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

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

实验任务11课程名称:程序设计基础VB实验名称——实验十一数组(1)一、实验目的:1.掌握数组的声明和数组元素的引用2.掌握定长数组使用3.掌握一维数组的基本操作算法二、实验内容(包括实验要求(题目)、实验步骤、程序清单、运行情况):注意:其中每个同学....实验1自行写结果验证,实验2-实验6发老师邮箱,尽量课上发。

实验1人工写出如下程序的运行结果,并利用单步调试工具验证执行流程和运行结果,进一步深入弄清和理解数组的访问。

(1)在窗体上画一个命令按钮(其Name属性为Command1),然后编写如下代码:Private Sub Command1_Click()Dim a(5) As Integer, i As Integer, t As IntegerFor i = 0 To 4a(i) = i + 1t = i + 1If t = 3 ThenPrint a(i);a(t - 1) = a(i - 2)Elsea(t) = a(i)End IfIf i = 3 Then a(i + 1) = a(t - 4) : Exit Fora(4) = 1Print a(i);Next IEnd Sub运行程序,单击命令按钮,输出结果是。

(2)下面的事件过程执行结束后,K的值是,A(2)的值是,A(7)的值是,程序中第二个循环被执行了次,程序中第三个循环被执行了次。

Option ExplicitOption Base 1 ‘将数组的下界的默认值设为1Private Sub Command1_Click()Dim A(10) As Integer, i As Integer, K As IntegerFor i = 1 To 10A(i) = 1Next iK = 1For K = 1 To K Step KA(K) = 0K = K + 2Next KFor K = K To 10 Step -1A(K) = KK = K + 2Next KEnd Sub(3)执行下面程序,单击命令按钮Command1后,数组元素A(1, 2)的值是,数组元素A(2, 2)的值是,数组元素A(3, 3)的值是。

Private Sub Command1_Click()Dim A(3, 3) As Integer, i As Integer, j As Integer, k As IntegerDim Bi = 3: j = 1A(i, j) = 1For k = 2 To 9If i + 1 > 3 Or j + 1 > 3 ThenIf j = 1 Theni = i - 1ElseIf A(i - 1, j - 1) = 0 Theni = i - 1: j = j - 1ElseIf j = 3 Theni = i - 1Elsej = j + 1End IfElseIf j = 1 Or i = 1 ThenIf A(i + 1, j + 1) = 0 Theni = i + 1: j = j + 1Elsej = j + 1End IfElseIf A(i - 1, j - 1) = 0 Theni = i - 1: j = j - 1End IfEnd IfA(i, j) = kNext kFor Each B In APrint BNextEnd Sub实验2实验7-1随机生成12个二位正整数,分别赋值给一个3×4的数组,找出每一行中的最大元素,运行后界面如图7-6所示。

(参看例7-10)部分程序代码如下请填空。

Option ExplicitOption Base 1 ‘将数组的下界的默认值设为1Dim a(3, 4) As IntegerPrivate Sub Form_Click()Dim i As Integer, j As Integer, mmax As IntegerRandomizePrint "数组:"For i = 1 To 3For j = 1 To 4a(i, j) = Int(Rnd*(99-10+1)+10)Print a(I,j);Next jPrintNext iPrint "其中:"For i = 1 To 3mmax = a(I,1)For j = 2 To 4If mmax < a(i, j) Then mmax=a(I,j)Next jPrint "第" + Str(i) + "行中的最大元素为:"; mmaxNext iEnd Sub实验3利用数组存放Fibonacci数列的前20项,并显示输出(每4个一行)。

说明:Fibonacci数列的前两项为1,从第三项开始,每项数据都等于前两项数据之和,即数列为:1,1,2,3,5,8,13,……图实验3运行效果分析:像Fibonacci数列一般采用一维数组存放,根据题意可知数列中的每项数据是通过前两项数据之和推导而出,因此可依据上述规律给数组赋值,完成数组的生成。

注意:输出采用标准格式,每4个一行。

实验步骤:(1)填写程序代码,完成下列代码:Option ExplicitPrivate Sub Form_Click()Dim i As Integer, Fibo(1 to 20) As IntegerFibo(1) = 1Fibo(2)=1For i = 3 To 20Fibo(i)= Fibo(i-1)+Fibo(i-2)Next iPrint "Fibonacci数列的前20项:"For i = 1 To 20Print Fibo(i),If I mod 4=0 then printNext iPrintEnd Sub(2)调试程序,并保存文件。

实验4 如图所示由用户输入生成10个自然数,分别显示其中的偶数、奇数以及它们的和。

∙图按下“单击输入一组自然数”按钮弹出输入对话框∙图实验9-3 运行结果分析:采用一维数组存放用户输入的10个数据,并结合累加求和算法完成。

注意:①数组声明的位置;②文本框中单行和多行显示数据的方法实验步骤:(1)界面设计在窗体上按照图所示界面排放好各个控件。

(2)属性设置请根据程序代码,设置好各个控件对象的名称属性;请根据图设置多行文本框的MultiLine和ScrollBars属性。

(3)填写程序代码,完成下列代码:Option ExplicitConst n = 10Dim a(1 to n) As integer‘定义数组Private Sub CmdCreate_Click()Dim i As IntegerText1 = ""For i = 1 To na(i) = val(Inputbox(“请输入第”, & I & “个数”,”project1”))Text1.Text = Text1.text & a(i) & ””Next iEnd SubPrivate Sub CmdDisp_Click()Dim I As Integer, odd As Integer, even As IntegerTxteven = "" : Txtodd = ""even = 0 : odd = 0For i=1 to nIf a(i) mod 2=0 ThenTxteven= Txteven & a(i) & vbcrlfeven = even + a(i)ElseTxtodd= Txtddd & a(i) & vbcrlfOdd=odd+a(i)End IfNext iTxteven = Txteven & "偶数和为" & evenTxtodd = Txtodd & "奇数和为" & oddEnd Sub(4)调试程序,并保存文件。

课外实验实验5教材p177练习7Option Base 1Dim a(5, 5) As Integer, UpSum As Integer, DownSum As IntegerPrivate Sub CmdCal_Click()TxtUpDown = Abs(UpSum - DownSum)End SubPrivate Sub CmdCreate_Click()Dim i As Integer, j As IntegerPicture1.ClsFor i = 1 To 5For j = 1 To 5a(i, j) = Int(Rnd * 9 + 1)Picture1.Print a(i, j);Next jPicture1.PrintNext iEnd SubPrivate Sub CmdDownSum_Click()Dim i As Integer, j As IntegerDownSum = 0For i = 1 To 5For j = 1 To i - 1DownSum = DownSum + a(i, j)Next jNext iTxtDownSum = DownSumEnd SubPrivate Sub CmdUpSum_Click()Dim i As Integer, j As IntegerUpSum = 0For i = 1 To 5For j = i + 1 To 5UpSum = UpSum + a(i, j)Next jNext iTxtUpSum = UpSumEnd Sub实验6教材p177练习8Option Base 1Private Sub Form_Click()Dim a() As Integer, i As Integer, j As IntegerDim col() As Integer, max As Integer, n As Integern = InputBox("请输入方阵的大小:")ReDim a(n, n), col(n)Print n & "阶方阵:"For i = 1 To nFor j = 1 To na(i, j) = Int(Rnd * 101) - 50 '产生[-50,50]闭区间内的随机整数Print a(i, j),Next jPrintNext iFor j = 1 To ncol(j) = 0 '累加器清零For i = 1 To ncol(j) = col(j) + Abs(a(i, j)) '第j列元素绝对值求和Next iNext jmax = col(1): maxcol = 1 '求出各列和的最大值和所在列For j = 2 To nIf col(j) > max Thenmax = col(j): maxcol = jEnd IfNext jPrint "方阵的范数(各列元素的绝对值之和中的最大值)为" & max & ",第("; maxcol & ")列"End Sub三、实验体会(包括对于本次实验的小结,实验过程中碰到的问题等)。

相关文档
最新文档