vb 程序设计教程(机械工业出版社)习题答案 实验6

合集下载

《Visual Basic程序设计基础》教材习题参考答案第六章

《Visual Basic程序设计基础》教材习题参考答案第六章

第6章图形控件和图形方法一、判断题1.√2.×3.√4.×5.√6.×7.×8.×9.√10.√二、选择题1.C 2.B 3.C 4.A 5.A 6.C 7.A 8.C 9.C 10.B 11.A 12.B 13.B 14.C 15.C三、填空题1.Circle (ScaleLeft + ScaleWidth / 2, ScaleTop + ScaleHeight / 2), 8002.LoadPicture 3.AutoSize、Stretch、False、False 4.选中、属性5.形状、矩形6.Picture1.Picture=LodePicture("C:\Windows\Cloud.bmp")7.图片框、其他控件8.缇、SclaeMode 9.颜色10.颜色、圆弧起点处转角、圆弧终点处转角、椭圆纵轴与横轴长度之比四、程序阅读题程序1. 转动一条红色直线,其轨迹形成一个圆程序2. 在窗体上随机的位置、用随机的颜色、半径绘制1000个空心的圆。

程序3. 在图片框内绘制多个黄色边框矩形,填充样式在“实心”、“透明”间交替变换。

五、程序填空题1.(1)Combo1.ListIndex (2)Shape1.BorderStyle (3)Combo2.AddItem Str(i) 2.(1)Call pic (2)False (3)n = n + 1 (4)LoadPicture("c:\windows\1.bmp") (4)LoadPicture(fn)六、程序设计题程序1.界面设计略,过程设计如下:Private Sub Form_Load()Picture1.ScaleMode = 3End SubPrivate Sub Command1_Click()Dim x1 As Single, y1 As Single, x2 As Single, y2 As Singlex1 = InputBox("x1="): y1 = InputBox("y1=")x2 = InputBox("x2="): y2 = InputBox("y2=")Picture1.Line (x1, y1)-(x2, y2), , BEnd Sub程序2.界面设计略,过程设计如下:Private Sub Form_click()Dim r As Single, xo As Single, yo As SingleIf Form1.ScaleHeight < Form1.ScaleWidth Thenr = Form1.ScaleHeight / 3Elser = Form1.ScaleWidth / 3End Ifxo = Form1.ScaleLeft + Form1.ScaleWidth / 2yo = Form1.ScaleTop + Form1.ScaleHeight / 2Form1.FillStyle = 0: Form1.FillColor = vbBlueForm1.DrawWidth = 2: Form1.ScaleMode = 6Form1.Circle (xo, yo), r, vbYellowEnd Sub程序3.界面设计略,过程设计如下:Private Sub Form_Load()Dim i As IntegerFor i = 1 To 7: List1.AddItem i: Next iForm1.ScaleMode = 1End SubPrivate Sub List1_Click()Form1.Cls: Form1.ScaleMode = List1.TextForm1.Circle (Form1.ScaleLeft + Form1.ScaleWidth / 2, _ Form1.ScaleTop + Form1.ScaleHeight / 2), 50End Sub。

《VB程序设计教程》答案汇总

《VB程序设计教程》答案汇总

随机数产生Private Sub Form_Click()For i = 101 To 200 Step 2For j = 2 To i - 1If i Mod j = 0 Then Exit ForNext jIf j >= i Then List1.AddItem i Next iEnd Sub四实验21Private Sub Command1_Click()For i = 100 To 200For j = 10 To 14If i = j ^ 2 Thenn = n + 1m = iEnd IfNext jNext iText1 = mText2 = nEnd Sub4 实验16Private Sub Form_Click()s = 1While s <= 100000i = i + 1s = s * (2 * i)WendPrint "s="; sEnd Sub4 实验17Private Sub Form_Click()Do While Sum <= 5000i = i + 1Sum = Sum + i ^ iLoopPrint "sum="; Sum - i ^ iEnd Sub 4 实验23Private Sub Form_Click()Dim a As Intege r, b As Integera = Int(100 * Rnd + 1)b = Int(100 * Rnd + 1)Text1 = aText2 = br = a Mod bWhile r <> 0a = bb = rr = a Mod bWendText3 = bc = (Val(Text1) * Val(Text2)) / bText4 = cEnd Sub6 实验8Private Sub Form_Click()RandomizeDim a(8, 8) As IntegerFor i = 1 To 8For j = 1 To 8a(i, j) = Int((999 - 100 + 1) * Rnd + 100)Print a(i, j);If Max < a(i, j) ThenMax = a(i, j)n = im = jEnd IfNext jPrintNext iPrint "最大值的元素是:"; Max Print "行号:"; nPrint "列号:"; mEnd Sub4 实验24Private Sub Form_Click()For i = 1 To 9For j = 1 To 9Print Trim(i); "*"; Trim(j); "="; Format(i * j, "!@@@");Next jPrintNext iEnd Sub4实验27Private Sub Command1_Click()Dim a As IntegerRandomizea = Int(101 * Rnd + 0)Text1.Text = aEnd SubPrivate Sub Command2_Click()For i = 2 To a - 1If a Mod i = 0 Then Exit ForNext iIf i >= a - 1 ThenText2.Text = "是素数"ElseText2.Text = "不是素数"End If5.6Private Sub Option1_Click()Shape1.Shape = 3End SubPrivate Sub Option2_Click()Shape1.Shape = 1End SubPrivate Sub Option3_Click()Shape1.Shape = 4End SubPrivate Sub Option4_Click()Shape1.Shape = 2 End Sub5.9Private Sub Command1_Click()For i = o To List1.ListCount - 1If List1.List(i) = Text1.Text Then Exit ForNext iIf i >= List1.ListCount ThenList1.AddItem Text1.TextEnd IfText1.SetFocusText1.SelStart = 0Text1.SelLength = Len(Text1) End SubPrivate Sub Command2_Click()If List1.ListIndex = -1 ThenMsgBox "请选择要删除的项" ElseList1.RemoveItem List1.ListIndex End IfEnd SubPrivate Sub Command3_Click()List1.ClearEnd Sub5.10Private Sub Combo1_Click()Select Case Combo1.ListIndexCase 0Text1.ForeColor = vbWhiteCase 1Text1.ForeColor = vbBlackCase 2Text1.ForeColor = vbRedCase 3Text1.ForeColor = vbGreenCase 4Text1.ForeColor = vbBlueCase 5Text1.ForeColor = vbYellow End SelectEnd SubPrivate Sub Combo2_Click()Select Case Combo2.ListIndexCase 0Text1.BackColor = vbWhiteCase 1Text1.BackColor = vbBlackCase 2Text1.BackColor = vbRedCase 3Text1.BackColor = vbGreenCase 4Text1.BackColor = vbBlueCase 5Text1.BackColor = vbYellow End SelectEnd SubPrivate Sub Combo3_Click()Select Case Combo3.ListIndexCase 0Text1.Alignment = 0Case 1Text1.Alignment = 2Case 2Text1.Alignment = 1End SelectEd Sub5.13Private Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = flaseEnd SubPrivate Sub Timer1_Timer()Label2.Caption = TimeEnd SubPrivate Sub Timer2_Timer()If Text1 = Hour(Time) ThenIf Text2 = Minute(Time) ThenBeepEnd IfEnd IfEnd Sub5.14Private Sub Timer1_Timer()Static i As IntegerSelect Case i Mod 2Case 0Text1.BackColor = vbRedCase 1Text1.BackColor = vbGreen End Selecti = i + 1End Sub5.15Private Sub Command1_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Command2_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Timer1_Timer()If Label1.Left < Form1.Width Then Label1.Move Label1.Left + 50 ElseLabel1.Left = -Label1.Width End IfEnd Sub5.17Private Sub Form_Click()Static i As IntegerIf Text1 = "111111" ThenLabel2.Caption = "恭喜!你已成功进入本系统"ElseLabel2.Caption = "口令错误!请重新输入"If i = 3 ThenMsgBox "对不起,你不能使用本系统"End IfEnd IfEnd Sub5 实验3Private Sub Combo1_Click()Select Case Combo1.ListIndexCase 0MsgBox "我的兴趣爱好是阅读"Case 1MsgBox "我的兴趣爱好是听音乐"Case 2MsgBox "我的兴趣爱好是美术"Case 3MsgBox "我的兴趣爱好是踢足球"Case 4MsgBox "我的兴趣爱好是旅游"End SelectEnd Sub5 实验11Private Sub List1_DblClick()Dim a As IntegerFor i = 0 To List1.ListIndexa = List1.List(i)Sum = Sum + aNext iList1.AddItem SumEnd Sub矩阵Dim a(), b(), c() As IntegerDim m, n As IntegerPrivate Sub Command1_Click()Rem 距阵的产生与相加Randomizem = Val(InputBox("num"))n = Val(InputBox("num"))ReDim a(n, m), b(n, m)For i = 1 To nFor j = 1 To ma(i, j) = Int(10 * Rnd)b(i, j) = Int(10 * Rnd)Picture1.Print a(i, j);Picture2.Print b(i, j);Next jPicture1.PrintPicture2.PrintNext iEnd SubPrivate Sub Command2_Click()ReDim c(n, m)For i = 1 To nFor j = 1 To mc(i, j) = a(i, j) + b(i, j)Picture3.Print c(i, j);Next jPicture3.PrintNext iEnd Sub练习1Private Sub Form_Click()Dim score(1 To 10) As SingleMin = 101For i = 1 To 10score(i) = Val(InputBox("请输入分数"))If score(i) > 100 ThenMsgBox "输入有误,请重新输入"End IfList1.AddItem score(i)Sum = Sum + score(i)Next iFor Each x In scoreIf Max < x Then Max = xIf Min > x Then Min = xNext xFor j = 1 To 9For k = j + 1 To 10If score(j) < score(k) Thent = score(j)score(j) = score(k)score(k) = tEnd IfNext kNext jFor Each y In scoreList2.AddItem yNext yText1 = Sum / 10Text2 = MaxText3 = MinEnd Sub练习2Private Sub Command1_Click()Dim a(1 To 10) As Integer, b(1 To 10) As IntegerFor i = 1 To 10a(i) = Int(91 * Rnd + 10)Next iFor i = 1 To 10List1.AddItem a(i)Next iFor i = 10 To 1 Step -1List2.AddItem a(i)Next iEnd Sub排序Dim a(1 To 10) As IntegerPrivate Sub Command1_Click() RandomizeFor i = 1 To 10a(i) = Int((99 - 10 + 1) * Rnd + 10)Text1 = Text1 & a(i) & " "Next iEnd SubPrivate Sub Command2_Click()Rem 比较法排序For i = 1 To 9For j = i + 1 To 10If a(i) < a(j) Thent = a(i)a(i) = a(j)a(j) = tEnd IfNext j Next iFor i = 1 To 10Text2 = Text2 & a(i) & " " Next iEnd SubPrivate Sub Command3_Click() Rem 冒泡法排序For i = 1 To 9For j = 1 To 10 - iIf a(j) < a(j + 1) Thent = a(j)a(j) = a(j + 1)a(j + 1) = tEnd IfNext jNext iFor i = 1 To 10Text3 = Text3 & a(i) & " " Next iEnd SubPrivate Sub Command4_Click() For i = 1 To 9k = iFor j = i + 1 To 10If a(k) < a(j) Then k = j Next jIf a(k) <> a(i) Thent = a(k)a(k) = a(i)a(i) = tEnd IfNext iFor i = 1 To 10Text4 = Text4 & a(i) & " " Next iEnd SubPrivate Sub Form_Load()Text1 = ""Text2 = ""Text3 = ""升序排序Dim a() As IntegerDim n As IntegerPrivate Sub Command1_Click() Randomizen = Val(InputBox("number")) ReDim a(n)For i = 1 To na(i) = Int(90 * Rnd + 10)List1.AddItem a(i)Next iEnd SubPrivate Sub Command2_Click()(比较法)For i = 1 To n - 1For j = i + 1 To nIf a(i) > a(j) Thent = a(i)a(i) = a(j)a(j) = tEnd IfNext jNext iFor i = 1 To nList2.AddItem a(i)Next iEnd SubPrivate Sub Command2_Click()(冒泡法)For i = 1 To n - 1For j = 1 To n - iIf a(j) > a(j + 1) Thent = a(j)a(j) = a(j + 1)a(j + 1) = tEnd IfNext jNext iFor i = 1 To nList2.AddItem a(i)Next iEnd Sub习题6.3Private Sub Command1_Click() RandomizeFor i = 1 To 4For j = 1 To 4a(i, j) = Int((999 - 100 + 1) * Rnd + 100)Picture1.Print a(i, j);If i = j Or i + j = 5 Then s = s + a(i, j)Next jPicture1.PrintNext iText1 = sEnd SubPrivate Sub Command2_Click()RemFor j = 1 To 4t = a(1, j)a(1, j) = a(3, j)a(3, j) = tNext jFor i = 1 To 4For j = 1 To 4Picture2.Print a(i, j);Next jPicture2.PrintNext iEnd SubPrivate Sub Command3_Click()For i = 1 To 4Picture2.Print Tab(5 * i);For j = i To 4Picture2.Print a(i, j);Next jPicture2.PrintNext iEnd SubPrivate Sub Command4_Click()For i = 1 To 4For j = 1 To iPicture2.Print a(i, j);Next jPicture2.PrintNext iEnd Sub习题7.1Function sum(n) As IntegerFor i = 1 To ns = s + iNext isum = sEnd FunctionPrivate Sub Command1_Click()i = Text1j = Text2k = Text3y = (sum(i) + sum(j)) / sum(k)Text4 = Format(y, "0.00000")End Sub杨辉三角Private Sub Form_Click()(等腰)Dim a() As Integern = Val(InputBox("num"))ReDim a(n, n)For i = 1 To nFor j = 1 To ia(i, j) = a(i - 1, j) + a(i - 1, j - 1)a(i, 1) = 1Next jNext iFor i = 1 To nPrint Tab(3 * n - 3 * i);For j = 1 To iPrint Format(a(i, j), "!@@@@@@");Next jPrintNext iEnd Sub Private Sub Form_Click()(直角)Dim a() As Integern = Val(InputBox("num"))ReDim a(n, n)For i = 1 To nFor j = 1 To ia(i, j) = a(i - 1, j) + a(i - 1, j - 1)a(i, 1) = 1Next jNext iFor i = 1 To nFor j = 1 To iPrint Format(a(i, j), "!@@@@@@");Next jPrintNext iEnd Sub。

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.当建立好一个简单的应用程序后,假定该工程仅有一个窗体模块。

问该工程涉及到几个文件要保存?若要保存该工程中的所有文件,正确的操作应先保存什么文件?再保存什么文件?若不这样做,系统会出现什么信息?答:涉及到两个文件要保存。

先保存窗体文件(.frm),再保存工程文件(.vbp)。

若先保存工程文件,系统也会先弹出“文件另存为”对话框,要求把窗体文件先保存。

3.假定在W indows环境中,要保存工程文件时,若不改变目录名,则系统默认的目录是什么?答:VB984.当标签框的大小由Caption属性的值进行扩展和缩小,应对该控件的什么属性进行何种设置?答:将标签的Autosize设置为True.5.VB6.0提供的大量图形文件在哪个目录下?若你的计算机上没有安装,则怎样安装这些图形文件?答:VB6.0提供的图形文件在Graphics目录。

6.在VB6.0中,命令按钮的显示形式可以有标准和图形两种选择,这通过什么属性来设置?若选择图形的,则通过什么属性来装入图形?若已在规定的属性里装入了某个图形文件,但该命令按钮还是不能显示该图形,而显示的是Caption属性设置的文字,怎样改正?答:按钮Style的属性设置为Graphical(或1)。

通过Picture属性来装入图形。

不能显示图形是因为Style的属性设置为Standard(或0),只要改为Graphical(或1),一般还将Caption 属性的值设置为空。

7.标签和文本框的区别是什么?答:文本是否可编辑。

8.当窗体上有三个文本框和一个命令按钮,若程序运行时,需把焦点定位在第三个文本框处,应对何控件的什么属性进行何种设置?答:应对Text3控件进行Text3.TabIndex=0的设置。

9.简述文本框的change与keypress事件的区别。

答:文本框内容变化,change与keypress事件都会发生,所不同的是Keyprees还将返回一个Keyasii参数10.当某文本框输入数据后(按了回车键),进行判断认为数据输入错,怎样删除原来数据?怎样使焦点回到该文本框重新输入?答:假定文本框的名称为Text1,则事件过程如下:Private Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii = 13 ThenIf 出错条件判断成立ThenText1=””…先删除原来数据Text1.SetFocus …焦点回到Text1End If……End IfEnd Sub11.在程序运行前,对某些控件设置属性值,除了在窗体中直接设置外,还可以通过代码设置,这些代码一般放在什么事件中?例如,程序要将命令按钮定位在窗体的中央,请写出事件过程。

vb程序设计书习题和参考答案

vb程序设计书习题和参考答案

vb程序设计书习题和参考答案练习题习题⼀⼀、判断题1.Visual Basic是以结构化的Basic语⾔为基础、以事件驱动作为运⾏机制的可视化程序设计语⾔。

2.⾯向对象的程序设计是⼀种以对象为基础,由事件驱动对象的编程技术。

3.事件是由Visual Basic预先定义的对象能够识别的动作。

4.新建⼯程时系统会⾃动将窗体标题设置为Form1。

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

6.决定对象是否可见的属性为Visible属性,决定对象可⽤性的属性是Enabled属性。

7.保存Visual Basic⽂件时,若⼀个⼯程包含多个窗体或模块,则系统先保存⼯程⽂件,再分别保存窗体或模块⽂件。

8.单击“启动”菜单项将窗体装⼊内存时,⼀定触发窗体的Load事件。

9.“事件过程”是⽤来完成事件发⽣后所要执⾏的程序代码。

10.在打开某窗体时,初始化该窗体中的各控件,应选⽤Load事件。

⼆、选择题1.⼯程⽂件的扩展名为。

A、.frxB、.basC、.vbpD、.frm2.下列不属于对象的基本特征是。

A、属性B、⽅法C、事件D、函数3.在设计模式双击窗体将显⽰的窗⼝是A、⼯程窗⼝B、⼯具箱C、代码窗⼝D、属性窗⼝4.VB中运⾏程序的快捷键是A、F2B、F5C、Alt+F35.改变控件在窗体中的上下位置应修改该控件的属性。

A、TopB、LeftC、WidthD、Right6.窗体模块的⽂件扩展名是A、.exeB、.basC、.frxD、frm7.设置窗体的字体⽤属性。

A、FontNameB、FontSizeC、FontBoldD、FontItalic8.设置窗体的字号⽤属性。

A、FontNameB、FontSizeC、FontBoldD、FontItalic9.下列选项中不属于事件的是。

A、DblclickB、LoadC、ShowD、KeyUp10.VB编制的程序保存在磁盘上,⾄少会产⽣何种⽂件。

A、.doc与.txtB、.com与.exe.C、.bat与.frmD、.vbp与.frm三、程序设计题1.新建⼀个⼯程,单击窗体时,在窗体上显⽰“欢迎使⽤Visual Basic程序”。

vb6.0实验六习题与答案

vb6.0实验六习题与答案

实验六专业_____________ 班级________年级________姓名______________学号_______________一、实验目的1、认识常用控件:单选按钮、复选框、框架、列表框、组合框、滚动条、滑动器(Slider)、时钟、图形控件;2、学习在窗体中创建常用控件2、学习在属性窗口和在程序代码中设置属性3、学习调用控件的方法4、学习编写各控件和鼠标与键盘的事件过程二、实验内容1、单选按钮、复选框、框架1)设置窗体F1的标题为“复选框、框架和单选按钮”;在窗体中设置复选框Ch1、Ch2 Ch1和Ch2的高度和宽度分别为360和1000;并程序运行时,Check2处于非少许状态。

框架Fr1包含单选按钮Op1和Op2。

2)设计窗体,要求①标题为“设置字体”;②在窗体中设置有边框的标签控件Label1,高度和宽度分别为450和3800,标题为“欢迎使用VB”,字号为“四号”,居中显示;③标题为“字体”框架包含两个标题分别为“楷体_GB2312”和“华文新魏”的单选按钮Op1和Op2;④标题为“斜体”框架包含两个标题分别为“是”和“否”的单选按钮。

⑤编写相应控件的事件过程,使得程序运行时,单击“楷体_GB2312”,标签控件的字体为楷体_GB2312,单击“华文新魏”,标签控件的字体为华文新魏;单击“是”,标签控件的字体为斜体,单击“否”,标签控件的字体取消斜体。

Private Sub Option1_Click()Label1.FontName = Option1.CaptionEnd SubPrivate Sub Option2_Click()Label1.FontName = Option2.CaptionEnd SubPrivate Sub Option3_Click()Label1.FontItalic = TrueEnd SubPrivate Sub Option4_Click()Label1.FontItalic = FalseEnd Sub3)在窗体是设置设置框Text1,其中文字为:黑体、四号、居中;设置单选按钮Option1和Option2,标题分别为“福州大学”和“阳光学院”,编写行当的事件过程,使得程序时,单击“福州大学”或“阳光学院”,在文本框中显示“福州大学”或“阳光学院”。

vb程序设计教程参考答案

vb程序设计教程参考答案

1、B2、A3、B4、答:属性:红色、充满氢气;事件:松手、针刺;方法:飞走、爆破。

5、答:事件是指对象能够识别并作出反映的外部刺激。

事件驱动又称消息驱动,事件驱动程序设计是指每个事件对应有相应的程序代码,仅在该事件发生时,该段代码才会被执行。

事件发生的顺序决定了代码执行的顺序,因此每次执行应用程序时,程序代码并不是按照程序编写的顺序来执行的。

6、答:VB是一个包括界面设计、程序编码、调试、编译并创建可执行程序的集成开发环境。

VB的集成开发环境的主界面中包含:标题栏、菜单栏、工具栏、控件箱、工程资源管理器、属性窗口、“窗体布局”窗口、窗体设计器、代码编辑器等元素组成。

7、答: VB菜单条通常情况下有:文件、编辑、视图、工程、格式、调试、运行、查询、图表、工具、外接程序、窗口、帮助等13项菜单项组成。

8、答:工具栏可自行定义。

标准工具栏中通常情况下有:添加标准exe工程、添加窗体、菜单编辑器、打开工程、保存工程、剪切、复制、粘贴、查找、撤消、重复、启动、中断、结束、工程资源管理器、属性窗口、窗体布局窗口、对象浏览器、工具箱、数据视图窗口、可视化元件管理器等按钮组成。

9、答:创建VB应用程序的一般步骤为:创建界面;设置窗体和控件属性;编写代码;保存工程;运行并调试程序;检查并排除错误;创建可执行文件。

10、Private Sub Command1_Click()Label1.Caption = "I love vb,I hate vb"End Sub1、2、3、S1 输入待判断自然数: N(N>=2);S2 i=2;S3 判断i是否小于N-1,若不是转S5S4 判断N除以i的余数是否为0,如果不是则i=i+1转S3;S5 判断i是否等于N,若是输出“是素数”,否则输出“不是素数”。

4、S1 输入待判断自然数: N;S2 将N转换成字符S,计算S的长度K;S3 i=1;S4 判断i是否小于K-1,若不是转S6;S5 判断S中的第i位和第K-i+1位是否相等,如果是则i=i+1转S4,如果不是则转S6;S6 判断i是否是中间位数,若是输出“是回文数”,否则输出“不是回文数”。

VB程序设计教程课后参考答案概要

VB程序设计教程课后参考答案概要

VB程序设计教程课后参考答案习题一一、填空题1.对象、事件驱动2.窗体、控件3.属性4.属性窗口、编程设置5.事件过程6.对象名、下划线、事件名7.Form_click8.Print form1.print “我的VB”9.主窗口、属性、工具箱、代码、窗体、工程资源管理10.菜单、快捷键二、选择题1.C 2. A 3. B 4. B 5. D 6. B C 7. A 三、简答题(略)习题二一、选择题1. D2. C3. C4. B5. C6. B7. C8. B 9. A 10. B 11. B 12. C 13. D 14. B15. A 16. A 17. A 18. A 19. B 20. C 21. A22. B 23. B 24. A 25. C 26. A 27. B 28. B29. C 30. B 31. D 32. D 33. C二、填空题1.Controlbox、Maxbutton、Minbutton2.Multiline TRUE3.******4.单文档界面(SDI)多文档界面(MDI)5.窗体显示6.Passwordchar7._change()三、编程题(略)习题三一、基础知识题(略)二、填空题1.整型、长整型、单精度、双精度2.(x mod 10)*10+x\103.Sin(3.14*15/180)+sqr(x+exp(3))/abs(x-y)-log(3*x)4.(a+b)/(1/(c+5)-c*d/2)5.X mod 5=0 or x mod 9=06.False7.-4、3、-3、3、-4、48.CDEF10.TRUE11.变量、属性12.‘_ :13.(略)14.“”#15.Public、通用/模块、Dim、static、private16.+ 、&、+17.Now() 、time()、日期18.Inputbox()、字符串、val()19.Msgbox()三、选择题1.B 2. C 3. A 4. B D此题有误 5. B 6. A7. D 8. B 9. B 10. C 11. D 12. B13. C 14. B 15. A 16. C 17.A 18. D19. A 20. D 21. A 22. C 23. C 24. D25. A 26. D 27. D 28. B 29. C 30. B31. C 32. B 33. C D此题有误34. C 35. A36. D 37. C 38. A 39. B 40. A 41. C42. C 43. D 44. C 45. D 46. A四、编程题1.Option ExplicitPrivate Sub Command1_Click()Dim a%, b%, c%, delta%Dim x1#, x2#, x#a = Val(InputBox("please input data to a:", "info", 1))b = Val(InputBox("please input data to b:", "info", 1))c = Val(InputBox("please input data to c:", "info", 1))If a = 0 And b <> 0 Thenx = -c / bPrint "所构成的方程是:" & b & "x" & "+" & c & "=0"Print "该一元一次方程的根是:", xEnd IfIf a = 0 And b = 0 ThenPrint "很抱歉,不能构成合法的方程!"End IfIf a <> 0 Thendelta = b * b - 4 * a * cIf delta >= 0 Thenx1 = (-b + Sqr(delta)) / (2 * a)x2 = (-b - Sqr(delta)) / (2 * a)Print "所构成的方程是:" & a & "x2" & "+" & b & "x" & "+" & c & "=0"Print "该方程的根是:"Print "第一个根是:", x1Print "第二个根是:", x2Else2Print "该方程有两个虚根:"Print "第一个虚根是:" & -b / (2 * a) & "+" & Sqr(Abs(delta)) / (2 * a) & "i"Print "第二个虚根是:" & -b / (2 * a) & "-" & Sqr(Abs(delta)) / (2 * a) & "i" End IfEnd IfEnd Sub2.Option ExplicitPrivate Sub Command1_Click()Dim i%, s%s = 0For i = 1 To 99 Step 2s = s + iNextPrint sEnd Sub3.Option ExplicitPrivate Sub Command1_Click()Dim i%Dim s#s = 0For i = 1 To 100s = s + 1 / i * (-1) ^ (i + 1)NextPrint sEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim i%, n%Dim t#, s#n = Val(InputBox("please input data:", "info", 5))s = 0t = 1For i = 1 To nt = t * is = s + tNextPrint sEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim a%, b%, c%Dim p#, s#a = Val(InputBox("please input data to a:", "info", 3))b = Val(InputBox("please input data to b:", "info", 4))c = Val(InputBox("please input data to c:", "info", 5))If (a + b > c And Abs(a - b) < c) Or (a + c > b And Abs(a - c) < b) Or ((b + c) > a And Abs(b - c) < a) Thenp = (a + b + c) / 2s = Sqr(p * (p - a) * (p - b) * (p - c))Print "三角形的面积是:" & sElsePrint "很抱歉,不能构成合法的△三角形!"End IfEnd Sub6.Option ExplicitPrivate Sub Command1_Click()Dim ji%, tu%For ji = 1 To 27For tu = 1 To 27If ji * 2 + tu * 4 = 78 And ji + tu = 27 ThenPrint "鸡的个数是:" & jiPrint "兔的个数是:" & tuEnd IfNextNextEnd Sub7.Option ExplicitPrivate Sub Command1_Click()Dim i%Dim s#, t#s = 10t = 10For i = 1 To 7t = t * 0.4s = s + t * 2NextEnd Sub8.Option ExplicitPrivate Sub Command1_Click()Dim i%, fs%, max%, min%, s%Dim ave#fs = Val(InputBox("please input score:", "info", 90))s = fsmax = fsmin = fsFor i = 2 To 7fs = Val(InputBox("please input score:", "info", 90))If max < fs Thenmax = fsEnd IfIf min > fs Thenmin = fsEnd Ifs = s + fsNextave = (s - max - min) / 5Print "该运动员的平均成绩是:" & aveEnd Sub9. ‘同学们,这道题方法很多,主要考察你对选择结构的理解,我给出其中一种方法。

VB程序设计课后习题答案

VB程序设计课后习题答案

VB课后习题解答第一、二章:1、简述VB6.0的主要特点答:方便、直观的可视化设计工具;面向对象程序设计方法;事件驱动的编程机制;易学易用的应用程序集成开发环境;结构化程序设计语言;完备的联机帮助功能;强大的多媒体、数据库和网络功能。

2、当正常安装VB6.0后,误把Windows子目录删除。

当重新安装Windows后,是否需要再次安装VB6.0?答:要重新安装的。

因为安装VB6.0时,有些VB程序被系统自动安装在Windows目录下,所以一旦删除Windows子目录,就必须重新安装VB6.0。

3、Visual Basic 6.0分为学习版、专业版和企业版,如何知道所安装的是哪个版本?答:在VB6.0的启动界面上,能显示对应的版本。

4、叙述建立一个完整应用程序的过程答:首先建立用户界面的控件对象(简称控件);然后对控件属性进行设置;再对控件事件过程及编程;保存应用程序;程序调试和运行。

5、Visual Basic 6.0有多种类型窗口,若要在设计时看到代码窗口,应怎样操作?答:选择“视图”—>“代码窗口”命令或单击“工程资源管理器”窗口中的“查看代码”按钮。

6、当建立好一个简单的应用程序后,假定该工程仅有一个窗体模块。

试问该工程涉及多少个要保存的文件?若要保存该工程的所有文件,应先保存什么文件?再保存什么文件?若不这样做,系统会出现什么信息?答:涉及两个文件要保存。

先保存窗体文件(.frm),再保存工程文件(.vbp)。

若先保存工程文件,系统也会先弹出“文件另存为”对话框,要求先保存窗体文件。

7、保存文件时,若不改变目录名,则系统默认的目录是什么?答:系统默认的目录是VB988、安装Visual Basic 6.0后,帮助系统是否也已安装?答:没有。

VB6.0的帮助系统在两张光盘上,即MSDN Library,其中还包含了VC、VFP等其他语言的帮助系统。

9、如何使用Visual Basic 6.0的帮助系统?答:最方便的方法是选定要帮助的内容,然后按F1功能键,这时系统打开MSDN Library查阅器,直接显示与选定内容有关的帮助信息。

VB程序设计教材习题及参考解答

VB程序设计教材习题及参考解答

第 1 章概述一、叙述题1.简述VB具有哪些特点。

(1)面向对象的可视化设计工具(2)事件驱动的编程机制(3)易学易用的应用程序集成开发环境(4)结构化的程序设计语言(5)充分利用Windows资源(6)开放的数据库功能与网络支持2.简述事件驱动的程序设计原理。

解答:VB程序的运行没有固定的顺序,它通过事件来激活某个对象,随着该对象的活动,会引发新的事件,这个事件又可能使另一个对象激活,对象之间就是以这种方式联系在一起的。

每个事件都可以通过一段程序(称为“事件过程”)来响应,在事件发生时,系统将自动执行相应的事件过程,用以实现指定的操作并达到运算、处理的目的。

为不同对象响应不同事件编写的事件过程构成了一个完整的应用程序,这就是VB事件驱动的程序设计原理。

3.VB的集成开发环境由哪些元素组成?解答:标题栏、菜单栏、工具栏、工具箱、窗体窗口、代码窗口、工程资源管理器窗口、属性窗口及窗体布局窗口等。

4.VB集成开发环境的工具栏能否自行定义?标准工具栏中包含一些什么按钮?解答:VB集成开发环境的工具栏可以自定义,方法是:用鼠标右击标准工具栏的任意位置,可以打开或关闭其余工具栏。

标准工具栏中包含的按钮有:添加Standard EXE工程、添加窗体、菜单编辑器、打开工程、保存工程、剪切、复制、粘贴、查找、撤销、重复、启动、中断、结束、工程资源管理器、属性窗口、窗体布局窗口、对象浏览器、工具箱、数据视图窗口、可视组件管理器及窗体位置与大小等。

5.当创建只有一个窗体的应用程序后,该工程涉及多少个要保存的文件?若要保存该工程中的所有文件,应先保存什么文件?后保存什么文件?解答:涉及两个文件要保存。

先保存窗体文件(.frm),再保存工程文件(.vbp)。

6.简述用VB开发应用程序的一般步骤。

(1)创建应用程序界面(2)设置界面上各个对象的属性(3)编写对象响应事件的程序代码(4)保存工程(5)运行和调试应用程序(6)创建可执行程序二、单选题1.D VB是一种面向对象的可视化程序设计语言。

VB程序设计教程 习题解答

VB程序设计教程 习题解答

VB程序设计教程习题解答vb程序设计教程习题解答《VB编程课程》(第三版)问题解决习题1答案一、多项选择题1.1visualbasic6.0分为3种版本,不属于这3种版本的是a)学习版b)专业版c)企业版d)业余版【答】d。

1.2在以下方法中,无法退出Visual Basic的方法是a)按Alt+Qb)按下alt+f组合键,然后按esc键c)按f10键,然后按f键,再按x键d)打开“文件”菜单→“退出”命令【答】b。

1.3 visual basic集成的主窗口不包括a)属性窗口b)标题栏C)菜单栏d)工具栏[answer]a。

1.4下列操作可以打开立即窗口的是a)ctrl+db)ctrl+fc)ctrl+gd)ctrl+e【答】c。

二、填空题1.5与传统编程语言相比,Visual Basic最突出的特点是。

[答:]事件驱动编程机制。

1.6如果不使用鼠标,用键盘打开菜单和执行菜单命令,第一步应按____键。

[答:]功能键F10或alt。

1.7建立一个新的标准模块,应该选择____菜单下的“添加模块”命令。

【答】“工程”菜单。

三、思考问题1.8简述visualbasic的特点。

[答:]与通用编程语言相比,VB具有以下特点:(1)可视化设计平台;(2)面向对象设计方法;(3)事件驱动编程机制;(4)结构化设计语言;(5)充分利用windows资源;(6)开放数据库功能和网络支持。

1.9简述visualbasic集成开发环境的组成。

[答:]VB6 0集成开发环境不仅有标准Windows环境的标题栏、菜单栏和工具栏,还有工具箱、属性窗口、项目管理器窗口、表单设计器、即时窗口和表单布局窗口等有用的开发工具。

(1)标题栏和菜单栏:标题栏中显示的有窗体控制菜单图标、当前激活的工程名称、当前工作模式以及最小化、最大化m还原、关闭按钮。

菜单栏中显示了“文件”、“编辑”、“视图”、“工程”、“格式”等菜单项,其中包含了vb编程的常用命令。

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章概述二.选择题:1.C2. B.3.C.4.C.5.A6.C7.D8.B9.B 10.B11.A12.C 13.D 14.C 15.D16.A17.C 18.A19.A20.D 21.B三.填空题:1.面向对象,事件驱动2.编译,解释3.设计,运行,中断4.F55.调试6.切换文件夹四.编程及上机调试:1.略2.Sub Form_Click( )Label1.Caption = “你单击了窗体”End SubSub Form_DblClick( )Label1.Caption = “你双击了窗体”End Sub第2章面向对象编程基础二.选择题:1.C2. C.3.B.4.B.5.D6.D7.B8.B9.C 10.D11.B 12.B 13.B 14.C 15.A16.B 17.B 18.B 19.C 20.B三.填空题:1.窗体,控件2.属性,事件,方法mand2_click4.picture5.中部,代码四.编程及上机调试:1.Private Sub Command1_Click()Form1.WindowState = 2End SubPrivate Sub Command2_Click()Form1.WindowState = 0Private Sub Command3_Click()Form1.WindowState = 1End Sub2.Private Sub Command1_Click()Form1.Picture = LoadPicture("d:\picture\flower.wmf")Command1.V isible = FalseCommand2.V isible = FalseEnd SubPrivate Sub Command2_Click()EndEnd SubPrivate Sub Form_DblClick()Form1.Picture = LoadPicture("")Command1.V isible = TrueCommand2.V isible = TrueEnd Sub第3章常用标准控件二.选择题:1.C2. B3.C.4.D5.B6.B7.A8.C9.B 10.C11.C 12.A13.C 14.B 15.D16.D 17.C 18.A19.D 20.A21.B三.编程及上机调试:1.Private Sub Check1_Click()If Check1.V alue = 1 ThenText1.FontBold = TrueElseText1.FontBold = FalseEnd IfEnd SubPrivate Sub Check2_Click()If Check2.V alue = 1 ThenText1.FontItalic = TrueElseText1.FontItalic = False End IfEnd SubPrivate Sub Check3_Click()If Check1.V alue = 1 ThenText1.FontUnderline = True ElseText1.FontUnderline = False End IfEnd SubPrivate Sub Command1_Click() Text1.Text = " "End Sub2.Private Sub Command1_Click() Text2.Text = List1.ListCount End SubPrivate Sub Command2_Click() List1.AddItem Text1.TextText1.Text = " "End SubPrivate Sub Command3_Click() Dim i As Integeri = List1.ListIndexList1.RemoveItem iCommand3.Enabled = FalseText1.SetFocusText2.Text = List1.ListCount End SubPrivate Sub Form_Load()Command3.Enabled = False End SubPrivate Sub List1_Click()Command3.Enabled = True End Sub第4章VB语言基础二.选择题:1.A2. D3.D.4.A5.A6.A7.C8.D9.C 10.B11.A 12.D 13.C 14.A15.A16.C 17.D 18.A19.B 20.D21.C 22.A23.B 24.C 25.C三.编程及上机调试:1.Private Sub Form_Load()Dim x As Integer, s As String, d As IntegerRandomizex = Int(Rnd * 9000 + 1000)s = Trim(CStr(x))d = V al(Right(s, 1) + Mid(s, 3, 1) + Mid(s, 2, 1) + Left(s, 1))ShowPrint "产生的数;"; x; "倒序数"; dEnd Sub2.Private Sub Form_KeyPress(KeyAscii As Integer)Print "输入字符:"; Chr(KeyAscii), "ASCII码为:"; KeyAsciiEnd SubPrivate Sub Form_DblClick()ClsEnd Sub3.Private Sub Form_Click()MsgBox "在这里显示提示" & vbCrLf & "提示信息", 2 + 16, "请确认"End Sub或Private Sub Form_Click()MsgBox "在这里显示提示" + Chr(13) + "提示信息", vbAbortRetryIgnore _ + vbCritical, "请确认"End Sub第5章程序控制结构二.单选题1.D2. C3.C.4.D.5.B6.C7.A8.A9.D 10.C11.C 12.C 13.B 14.B四.编程及上机调试1. Private Sub Form_Click()Dim x As Integer, y As Integerx = InputBox("请输入一个数值")If x > 20 Theny = x ^ 2 + 3 * x + 2ElseIf x >= 10 Theny = Sqr(3 * x) - 2ElseIf x > 0 Theny = 1 / x + Abs(x)End IfPrint "x="; x, "y="; yEnd Sub(2)Select Case实现:Private Sub Form_Click()Dim x As Integer, y As Integerx = InputBox("请输入一个数值")Select Case xCase Is > 20y = x ^ 2 + 3 * x + 2Case Is >=10y = Sqr(3 * x) - 2Case Is > 0y = 1 / x + Abs(x)End SelectPrint "x="; x, "y="; yEnd Sub2.Private Sub Form_Click()Dim a As Integer, b As Integer, c As IntegerFor i = 100 To 999a = i \ 100b = (i - a * 100) \ 10c = i Mod 10If a ^ 3 + b ^ 3 + c ^ 3 = i ThenPrint i;k = k + 1If k Mod 2 = 0 Then PrintEnd IfNext iEnd Sub3.Private Sub Command1_Click()p = 60: r = 0.014Dop = p * (1 + r)n = n + 1Loop Until p >= 70Print n; "年后世界人口达到"; p; "亿"End Sub4.Private Sub Command1_Click()Dim s As Single, x As Integer, t As Single, n As Integer x = V al(InputBox("请输入x的值", , 2))s = 1n = 1m = 1Don = n + 1m = -mt = m * n / x ^ (n - 1)If Abs(t) < 0.00001 Then Exit Dos = s + tLoopPrint sEnd Sub第6章数组二.单选题:1.A2.A.3.A4.C5.D6.D7.A8.D9.B 10.B四.编程及上机调试:1.Option Base 1Private Sub Form_Click()Dim a(10) As IntegerDim i As Integer, t As IntegerPrint "数组的原始数据为:";For i = 1 To 10a(i) = Int(11 * Rnd) + 10Print a(i);Next iPrintPrint "变化后数组数据为:";For i = 1 To 5t = a(i)a(i) = a(10 - i + 1)a(10 - i + 1) = tNext iFor i = 1 To 10Print a(i);Next iEnd Sub2.Option Base 1Private Sub Form_Click()Dim a(3, 4) As Integer, i As Integer, j As Integer, k As Integer, p As Integer RandomizeFor i = 1 To 3For j = 1 To 4a(i, j) = Int(90 * Rnd + 10)Print a(i, j);Next jPrintNext iMax = a(1, 1): k = 1: p = 1For i = 1 To 3For j = 1 To 4If a(i, j) > Max ThenMax = a(i, j)k = ip = jEnd IfNext jNext iPrint "最大的数为第" & k & "行,第" & p & "列的数:" & MaxEnd Sub3.Option Base 1Dim a(4, 5) As Integer '在窗体声明段声明数组Dim i As Integer, j As IntegerPrivate Sub cmdmatrix_Click() '"生成数组"按钮RandomizeFor i = 1 To 4For j = 1 To 5a(i, j) = Int(Rnd * 10) '一位的随机数Picture1.Print a(i, j); '输出元素Next jPicture1.PrintNext iEnd SubPrivate Sub cmdcol_Click() '"求列和"按钮Dim colsum As Integertxtcol.Text = ""For j = 1 To 5 '列变量先循环colsum = 0For i = 1 To 4colsum = colsum + a(i, j)Next itxtcol.Text = txtcol.Text & Str(colsum)Next jEnd SubPrivate Sub cmdrow_Click() '"求行和"按钮Dim rowsum As Integertxtrow.Text = ""For i = 1 To 4 '行变量先循环rowsum = 0For j = 1 To 5rowsum = rowsum + a(i, j)Next jtxtrow.Text = txtrow.Text & CStr(rowsum) & vbCrLf Next iEnd SubPrivate Sub cmdclear_Click() '"清除"按钮Picture1.Clstxtcol.Text = ""txtrow.Text = ""End SubPrivate Sub cmdexit_Click() '"结束"按钮EndEnd Sub4. Option Base 1Private Sub Form_Click()Dim a() As Integer, b() As Integer, i As Integer, j As Integer, x As Integer, y As Integer x = InputBox("第一维上界")Do While Not IsNumeric(x)x = Int(InputBox("第一维上界"))Loopy = InputBox("第二维上界")Do While Not IsNumeric(x)y = Int(InputBox("第二维上界"))LoopReDim a(x, y)Print "原数组元素为:"For i = 1 To xFor j = 1 To ya(i, j) = Int(90 * Rnd) + 10Print a(i, j);Next jPrintNext iPrint "转置后数组元素为:"For i = 1 To yFor j = 1 To xPrint a(j, i);Next jPrintNext iEnd Sub5. Option Base 1Private Sub Form_Click()Dim a(10, 10) As Integer, i As Integer, j As IntegerFor i = 1 To 10For j = 1 To 10If i = j Or i + j = 11 Thena(i, j) = 0Elsea(i, j) = 1End IfPrint a(i, j);Next jPrintNext iEnd Sub6. Option ExplicitOption Base 1Private Sub Command1_Click()Dim i As Integer, j As Integer, n As Integer, k As Integer, a(11) As Integerj = 1For i = 3 To 21 Step 2a(j) = iPrint a(j);j = j + 1Next iPrintn = InputBox("请输入一个数")For i = 1 To 10If n = a(i) ThenFor j = i To 10a(j) = a(j + 1)k = k + 1Next jEnd IfNext iFor i = 1 To 9Print a(i);Next iEnd Sub7. Option Base 1Private Sub Form_Click()Dim a As V ariant, k As Integer, i As Integer, j As IntegerDim b As V ariantb = Array(17, 35, 128, 235, 89, 121, 143, 189, 231, 94)a = Array(11.3, 12.3, 12#, 11.8, 12.6, 11.6, 12.8, 11.8, 12.4, 12.1)For i = 1 To 9 '对数组a的元素排序k = iFor j = i + 1 To 10If a(k) > a(j) Then k = jNext jIf k <> i Then '数组b的元素随数组a的元素一起变动t = a(i)a(i) = a(k)a(k) = tt = b(i)b(i) = b(k)b(k) = tEnd IfNext iPrint "按名字的排列顺序为:"For i = 1 To 10If Len(b(i)) = 2 Then b(i) = "0" & b(i) '补上数组b中长度为2的编号前的"0"Print "第" & i & "名的号码为:" & b(i) & ",成绩为:" & a(i)Next iEnd Sub第7章过程二、单选题1.C2. D3.C4.D5. B6.A7. B8.B9.C 10.D11.C 12.D 13.B 14.B 15.C16.A17.B 18.B三、填空题1.52 512.4 118 353.1 3 5四.编程及上机调试:1. Private Sub Command1_Click()Dim n As IntegerFor n = 100 To 1600 Step 500Print "n="; n; "时π的近似值是:"; pi(n)Next nEnd SubPrivate Function pi(x As Integer) As SingleDim s As Single, k As Integer, m As Integers = 0k = 1m = 1Dos = s + m / km = -mk = k + 2Loop While k <= xpi = 4 * sEnd FunctionPrivate Sub Command2_Click()EndEnd Sub2. Private Sub Command1_Click()Dim x As Integer, i As Integerx = V al(Text1)For i = 1 To xIf prime(i) And prime(x - i) ThenLabel2 = Str(x) & "是" & Str(i) & "和" & Str(x - i) & "两个素数之和"Exit SubEnd IfNext iEnd SubPrivate Function prime(x As Integer) As BooleanFor i = 2 To Int(Sqr(x))If x Mod i = 0 Thenprime = FalseExit FunctionEnd IfNext iprime = TrueEnd FunctionPrivate Sub Command2_Click()EndEnd Sub3. Option ExplicitOption Base 1Dim a(10) As IntegerPrivate Sub Command1_Click()RandomizeDim i As IntegerFor i = 1 To 10a(i) = Int(Rnd * 90) + 10Text1 = Text1 + Str(a(i))Next iCall sort(a)For i = 1 To 10Text2 = Text2 + Str(a(i))Next iEnd SubPrivate Sub sort(a() As Integer)Dim k As Integer, i As Integer, j As Integer, t As Integer k = UBound(a)For i = 1 To k - 1For j = i + 1 To kIf a(i) < a(j) Thent = a(i)a(i) = a(j)a(j) = tEnd IfNext jNext iEnd SubPrivate Sub Command2_Click()EndEnd Sub4. Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, j As Integer, s As IntegerFor i = 2 To 1000S=0For j=1 To i - 1If I mod j=0 Then s=s+jNext jIf s=i Then Print I,Next iEnd Sub5. Public a(10) As IntegerPublic Sub sort(a() As Integer)Dim i As Integer, j As Integer, t As IntegerFor i = 1 To UBound(a) - 1For j = i + 1 To UBound(a)If a(i) > a(j) Thent = a(i)a(i) = a(j)a(j) = tEnd IfNext jNext iEnd SubPublic Function max(a() As Integer) As Integermax = a(1)For i = 2 To UBound(a)If max < a(i) Thenmax = a(i)End IfNext iEnd Function窗体Form1代码Private Sub Command1_Click()Dim i As IntegerRandomizeFor i = 1 To UBound(a)a(i) = Int(Rnd * 90) + 11Text1 = Text1 & Str(a(i))Next iEnd SubPrivate Sub Command2_Click()Form1.HideForm2.ShowEnd SubPrivate Sub Command3_Click()Text2 = max(a)End SubPrivate Sub Command4_Click()EndEnd Sub窗体Form2代码Private Sub Command1_Click()Call sort(a)For i = 1 To UBound(a)Text1 = Text1 & Str(a(i))Next iEnd SubPrivate Sub Command2_Click()Form2.HideForm1.ShowEnd Sub第8章程序调试二.上机调试题1. Option ExplicitPrivate Sub Form_Click()Dim a() As Single, i As IntegerDim y As Singlei = 1DoReDim a(i) …改为ReDim Preserve A(I) a(i) = 1 / fib(i)If a(i) <= 0.0001 Then Exit Do …改为a(i) < 0.0001 y = y + a(i)i = i + 1LoopPrint "y="; yFor i = 1 To UBound(a)Print a(i);Next iEnd SubPrivate Function fib(i As Integer) As IntegerIf i = 1 Thenfib = 1ElseIf i = 2 Thenfib = 2ElseFib(i)= fib(i - 1) + fib(i - 2) …改为Fib=Fib(I-1)+Fib(I-2) End IfEnd Function2. Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, k As Integer, st As StringFor i = 10 To 500If wanshu(i) Thenst = CStr(i)Text1.Text = Text1.Text & stCall test(st)Text1.Text = Text1.Text & Chr(13) & Chr(10)End IfNext iEnd SubPrivate Function wanshu(n As Integer) As BooleanDim i As Integer, sum As IntegerFor i = 2 To n – 1 …改为i=1If n Mod i = 0 Thensum = sum + iEnd IfNext iIf sum = n Then wanshu = TrueEnd FunctionPrivate Sub test(s As String)Dim i As Integer, sum As Integersum = 0 …位置错,和for 语句位置调换Do While Len(s) > 1For i = 1 To Len(s)sum = sum + V al(Mid(s, i, 1))Next iText1.Text = Text1.Text & "->" & Str(sum)s = Str(sum) … 改为s = CStr(sum) LoopEnd Sub第9章数据文件一、单选题1.B 2.C 3.A 4.B 5.C6.B 7.C 8.B 9.10.A11. 12.A13. 14. 15.A16.B二、编程及上机调试1.Private Sub Form_Load()Open "d:\my\text2.txt" For Output As #1End SubPrivate Sub Text1_keyPress(KeyAscii As Integer)If KeyAscii = 13 ThenIf Trim(Text1) = "0000" ThenClose #1EndEnd IfWrite #1, Text1Text1.Text = ""End IfEnd Sub2.Option ExplicitPrivate Type Studentname As String * 10age As IntegerEnd TypePrivate Sub Command1_Click()Dim Stu As StudentOpen "d:\my\text2.txt" For Random As #1 Len = Len(Stu) = "WangY ing"Stu.age = 20Put #1, , StuClose #1Open "d:\my\text2.txt" For Random As #1 Len = Len(Stu)Get #1, , StuPrint "姓名:", Print "年龄:", Stu.ageClose #1End Sub第10章其它控件二、选择题1.B 2.B 3.B 4.C 5.6.A,C 7.A 8.9.10.11. 12.B 13.三、填空题1.菜单编辑器2.下拉式菜单弹出式3.顶4.PopupMenu5.多文档窗体6.MDIChild7.Private Sub HScroll1_Change()text1 = HScroll1.V alueEnd SubPrivate Sub HScroll1_Scroll()text1 = HScroll1.V alueEnd Sub8.Private Sub Toolbar1_ButtonClick(ByV al Button As MSComctlLib.Button) Select Case Button.IndexCase 1Form1.BackColor = vbRedCase 2Form1.BackColor = vbGreenCase 3Form1.BackColor = vbBlueEnd SelectEnd Sub四、编程及上机调试1.Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, _X As Single, Y As Single)If Button = 1 ThenPicture1.PSet (X, Y)StatusBar1.Panels(1) = "X=" & XStatusBar1.Panels.Item(2) = "Y=" & YEnd IfEnd Sub2.Private Sub Command1_Click()CommonDialog1.FileName = ""CommonDialog1.InitDir = "D:\"CommonDialog1.Filter = "Word Files|*.doc|文本文件|*.Txt" '设置过滤器CommonDialog1.DialogTitle = "打开文件" '设置打开对话框的标题CommonDialog1.Action = 1 '创建"打开"对话框If CommonDialog1.FileName = "" Then '判断文件名是否为空MsgBox "没有选择文件", 37, "检查" '若为空,则显示信息ElseOpen CommonDialog1.FileName For Input As #1 '打开选定的文件Do While Not EOF(1)Line Input #1, a$ '读文件的一行Text1 = Text1 & a$ & vbCrLf '输出所读的内容LoopEnd IfEnd SubPrivate Sub Command2_Click()CommonDialog1.Flags = 3 '列出打印机和屏幕字体CommonDialog1.Action = 4 '打开"字体"对话框Text1.FontName = CommonDialog1.FontName '改变文本框的字体Text1.FontSize = CommonDialog1.FontSizeText1.FontBold = CommonDialog1.FontBoldText1.FontItalic = CommonDialog1.FontItalicText1.FontUnderline = CommonDialog1.FontUnderline End SubPrivate Sub Command3_Click()EndEnd Sub11章略。

VB教材习题_参考答案1-6章

VB教材习题_参考答案1-6章

Visual Basic程序设计教程(李杰主编清华大学出版社 2011.2)习题答案习题2参考答案2.2 单选题1、B2、C3、A4、D5、A6、B7、D8、C9、B 10、D2.3 填空题1、事件驱动2、Cancel3、Name4、Private Sub Form1_Click()5、运行程序6、代码窗口7、Text1.Text = "我是一个学生"8、LostFocus()事件9、Label1.Caption = "请输入用户名"Label1.ForeColor = vbGreen10、(Text1.Text)*22.4 事件练习题1、①该事件的对象是标签Label1,单击标签触发该事件。

②缺省Label1对象的代码是针对窗体,其余有Label1对象的代码是针对标签的。

③Label1.AutoSize = True语句使标签的大小自动随文字的多少而改变。

2、程序运行后,单击命令按钮,在Text1文本框显示"知音海外版",在Text2文本框显示"计算机世界"。

3、单击“显示文本框”命令按钮触发的事件过程Private Sub Command1_Click()Text1.Visible = TrueText1.ForeColor = vbRedText1.Text = "VB程序设计"End Sub单击“隐藏文本框”命令按钮触发的事件过程Private Sub Command2_Click()Text1.Visible = FalseEnd Sub习题3参考答案3.2 单选题1 C2 C3 D4 B5 B6 B7 B8 C9 D3.3填空题1.REM(或‘) _ :2 双引号(“”)#3 $ %4 UCASE()5.(log(1+d*d)-exp(2))^(5/2) [ 还有一种理解方式:(log(1+d*d)-e*e)^(5/2)]6. &O113 &H4B习题4参考答案4.2 单选题BDCBD4.3 填空题1.MsgBox("是否删除? ", vbOkCancel + vbQuestion, "删除")2.The Length of 12345=53. 变量或表达式4. 15. loop4.4 程序设计题1.Private Sub Command1_Click()If Text1.Text = "asdf" ThenMsgBox "密码正确!"ElseMsgBox "密码错误", vbRetryCancel, "错误"End IfEnd Sub2. < 题目中的“连续产生n*n个字母”应该改为“连续产生n个字母”> Private Sub Command1_Click()Dim n%, y%, i%n = Val(Text1.Text)If n > 10 Or n<=0 ThenMsgBox "数据超界!"Text1.Text=””Text1.SetFocusElsey = Int((90 - 65 + 1) * Rnd) + 65For i = 1 To nPrint Chr(y + i)Next iEnd IfEnd Sub3.Private Sub Form_Click()Dim a!, b!, c!, x1!, x21, d!a = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)d = b * b - 4 * a * cIf d >= 0 Thenx1 = (-b + Sqr(d)) / (2 * a)X2 = (-b - Sqr(d)) / (2 * a)Print x1; X2ElsePrint "没有实根"End IfEnd Sub4.Private Sub Form_Click()Dim i%, j%, s%, n%,q%n = InputBox("enter n:")q = 0For i = 1 To ns = 0For j = 1 To is = s + jNext jq = q + sNext iPrint qEnd Sub5.Private Sub Form_Click()Dim i%, j%, n%, k%n = 0For i = 1 To 3For j = 1 To 3For k = 1 To 3Print i & j & k,n = n + 1If n Mod 5 = 0 Then PrintNext kNext jNext iPrintPrint "n="; nEnd Sub6.Private Sub Form_Click()Dim i%, j%, n%, k%For i = 1 To 9For j = 0 To 9For k = 0 To 9n = i * 100 + j * 10 + kIf n = i ^ 3 + j ^ 3 + k ^ 3 Then Print n,Next kNext jNext iEnd Sub习题5参考答案5.2 单选题1 A2 B3 C4 C5 D6 D7 A8 C9 D 10 A 11 A 12 B 5.3 填空题1.False2.Caption3.0 ListCount-14.Print List1.List(3)5.Combo1.ReMoveItem 36.LargeChange7.Timer8.5009.Shape10.Borderstyle5.4 程序设计题1.Dim op1, op2, result As SingleDim operator As IntegerPrivate Sub Command1_Click(Index As Integer)If Index >= 0 And Index <= 10 ThenIf txt1.Text = "" Thentxt1.Text = CStr(Index + 1)Elsetxt1.Text = txt1.Text + CStr(Index + 1) End IfEnd IfIf Index >= 12 And Index <= 15 Thenop1 = CDbl(txt1.Text)operator = Indextxt1.Text = ""End IfIf Index = 11 Thenop2 = CDbl(txt1.Text)Select Case operatorCase 12result = op1 + op2Case 13result = op1 - op2Case 14result = op1 * op2Case 15result = op1 / op2End Selecttxt1.Text = CStr(result)End IfEnd SubPrivate Sub Command2_Click()op1 = 0op2 = 0result = 0txt1.Text = ""End SubPrivate Sub Command3_Click()EndEnd Sub2.Private Sub chkBold_Click()If chkBold.Value = vbChecked ThenTxt1.FontBold = TrueElseTxt1.FontBold = FalseEnd IfEnd SubPrivate Sub chkUnderline_Click()If chkUnderline.Value = vbChecked Then Txt1.FontUnderline = TrueElseTxt1.FontUnderline = FalseEnd IfEnd SubPrivate Sub Opt18_Click()Txt1.FontSize = 18End SubPrivate Sub Opt22_Click()Txt1.FontSize = 22End Sub3.Private Sub Form_Load()List1.AddItem "上海"List1.AddItem "北京"List1.AddItem "天津"List1.AddItem "广东"List1.AddItem "辽宁"List1.AddItem "陕西"List1.AddItem "河南"List1.AddItem "深圳"List1.AddItem "四川"List1.AddItem "重庆"End SubPrivate Sub List1_DblClick()For i = 0 To 9If List1.ListIndex = i ThenList2.AddItem List1.List(i)List1.RemoveItem iEnd IfNext iEnd Sub4.Private Sub Command1_Click()Timer1.Enabled=TrueTimer1.Tag=Text1.Text*60Frame1.Caption=“现在开始倒计时”End SubPrivate Sub Timer1_ Timer()Timer1.Tag=Timer1.Tag-1If m<0 ThenTimer1.Enabler=FalseMsgBox“预定的时间到了!”,0,“倒计时”Frame1.Caption=“请输入计时的分钟数:”Text1.Text=0Exit SubEnd Ifn1=Format(m Mod 60,“00”)n2=Format(m \ 60)Mod 60,“00:”)n3=Format(m \ 3600),“00:”)Text1.Text=n3&n2&n1End Sub习题6参考答案6.1单选题1.C2.C3.B4.B5.B6.D7.B8.B9.A 10.A6.2 填空题1.Option Base 12.变体类型3.preserve (注意:教材上面写成perserve, 教材错误)4.Variant变体类型5.96.相同,索引号7.1).通过复制粘贴的方式创建控件数组2).在设计时候添加多个同类型的类型控件,然后通过“属性”窗口将这些控件的名称改为相同,并把Index属性设为不同的下标值。

VB程序设计练习册参考答案

VB程序设计练习册参考答案

参考答案第1章Visual Basic 简介一、选择题1、B2、C3、A4、D5、C6、A7、D8、C9、D 10、B11、C 12、B二、填空题1 过程对象事件驱动2 学习版专业版企业版企业版3 Alt+F4 Alt+Q4 设计运行中断5 设置在应用程序运行时,各窗体在屏幕上的显示位置6 内部(标准)7 资源管理器8 编译方式解释方式9 选择“视图/工具箱”命令10 print 或?“大家都来学用Visual Basic”11按字母序按分类序12编辑代码三、思考题略第2章Visual Basic程序设计概述一、选择题1、A2、A3、D4、D5、D6、C7、A 8、C 9、A 10、C 11、B 12、D13、C 14、C 15、B 16、B 17、D 18、B三、编程题1、(1)建立应用程序用户界面。

选择”新建”工程,进入窗体设汁器,在窗体中增加一个标签控件Labe11和两个命令按钮 Commandl 、 Comlnand2。

(2)设置对象属性,见表。

(可自由设置)3编写代码private sub command1_clicklabel1.visible=false1 窗体 控件2 Left Top Width Height3 Ctrl 或shift4 Scrollbars Multiline True Passwordchar5 事件过程6 在属性窗口设置 在代码窗口设置7 对象名 下划线 事件名8 Form_Click9 Form1.Hide10 界面设计 属性设置 代码编写 保存运行11 窗体文件 工程文件12 部件13 窗体文件 模块文件 类模块文件private sub command2_clicklabel1.visible=trueend sub2、Private Sub Command1_ClickIf Text1.Text<>””And Text2.Text<>””Then ′组合条件判断文本框是否为空Form1.Caption=Text1.Text & ″,″& Label2.Caption & ″″& Text2.Text End IfEnd Sub第3章Visual Basic程序设计基础一选择题1.B2.C3.D4.B5.B6.B7.D8.D9.C10.C11.D 12.C 13.D 14.D 15.A 16.D 17.D 18.D 19.C 20.C21.A22.D23.B24.A 25.B 26.A二、填空题1 our name is2 13 True4 字母数字下划线2555 56 07 Logx/log10/0.5+x^2或者Logx/log10/0.5+x*x8 0,1,2,3,49 x>=0 and x<10010 511 false12 6三、编程题1.提示:Ucase、Lcase的使用2.提示:属性设置中,“计算”按钮的default属性设为True.“清除”按钮的Cancel属性设为True.第4章数据输入输出一、选择题1、D2、A3、A4、B5、D6、B7、C 8、C 9、D 10、D二、填空题1. 1+1= 22+2=42. 500.00%3.将当前字体放大两倍4. 20-11-025. 11 1三、编程题1.提示:(1)流程图。

VB程序设计课后习题答案

VB程序设计课后习题答案

VB课后习题解答第一、二章:1、简述VB6.0的主要特点答:方便、直观的可视化设计工具;面向对象程序设计方法;事件驱动的编程机制;易学易用的应用程序集成开发环境;结构化程序设计语言;完备的联机帮助功能;强大的多媒体、数据库和网络功能。

2、当正常安装VB6。

0后,误把Windows子目录删除。

当重新安装Windows后,是否需要再次安装VB6。

0?答:要重新安装的。

因为安装VB6。

0时,有些VB程序被系统自动安装在Windows目录下,所以一旦删除Windows子目录,就必须重新安装VB6。

0。

3、Visual Basic 6。

0分为学习版、专业版和企业版,如何知道所安装的是哪个版本?答:在VB6.0的启动界面上,能显示对应的版本.4、叙述建立一个完整应用程序的过程答:首先建立用户界面的控件对象(简称控件);然后对控件属性进行设置;再对控件事件过程及编程;保存应用程序;程序调试和运行。

5、Visual Basic 6。

0有多种类型窗口,若要在设计时看到代码窗口,应怎样操作?答:选择“视图"—>“代码窗口”命令或单击“工程资源管理器”窗口中的“查看代码"按钮。

6、当建立好一个简单的应用程序后,假定该工程仅有一个窗体模块。

试问该工程涉及多少个要保存的文件?若要保存该工程的所有文件,应先保存什么文件?再保存什么文件?若不这样做,系统会出现什么信息?答:涉及两个文件要保存.先保存窗体文件(.frm),再保存工程文件(.vbp)。

若先保存工程文件,系统也会先弹出“文件另存为”对话框,要求先保存窗体文件。

7、保存文件时,若不改变目录名,则系统默认的目录是什么?答:系统默认的目录是VB988、安装Visual Basic 6。

0后,帮助系统是否也已安装?答:没有。

VB6.0的帮助系统在两张光盘上,即MSDN Library,其中还包含了VC、VFP等其他语言的帮助系统。

9、如何使用Visual Basic 6.0的帮助系统?答:最方便的方法是选定要帮助的内容,然后按F1功能键,这时系统打开MSDN Library查阅器,直接显示与选定内容有关的帮助信息。

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