VB_NET习题集答案(无编程答案)-刘炳文书54
vb程序设计教程习题答案
vb程序设计教程习题答案VB程序设计教程习题答案在学习VB程序设计的过程中,经常会遇到各种习题,这些习题旨在帮助我们巩固所学的知识,提高编程能力。
然而,有时候我们可能会遇到一些难以理解的问题,或者是不知道如何去解决的问题。
因此,本文将为大家提供一些VB程序设计教程习题的答案,希望能够帮助大家更好地理解和掌握VB程序设计。
1. 编写一个程序,实现两个数的加法运算。
答案:```vbDim num1 As IntegerDim num2 As IntegerDim sum As Integernum1 = InputBox("请输入第一个数")num2 = InputBox("请输入第二个数")sum = num1 + num2MsgBox("两个数的和为:" & sum)```2. 编写一个程序,实现输出1到100之间的所有偶数。
答案:```vbFor i = 1 To 100If i Mod 2 = 0 ThenMsgBox(i)End IfNext```3. 编写一个程序,实现输入一个数字,判断该数字是奇数还是偶数。
答案:```vbDim num As Integernum = InputBox("请输入一个数字")If num Mod 2 = 0 ThenMsgBox(num & "是偶数")ElseMsgBox(num & "是奇数")End If```通过以上习题的答案,我们可以看到VB程序设计的一些基本语法和逻辑运算,这些知识对于我们日后的编程学习和实践都是非常重要的。
希望大家能够通过不断地练习和思考,掌握VB程序设计的相关知识,成为优秀的程序设计师。
VBnet参考习题答案.doc
A )二进制文件 9.设X 二-2,贝I 」( A ) Vai (“X")D)・Abs(X)s.Remove (1,5)s.Remove (3, 2)C ) s.Substring(6, 2) D ) s.Substring (5)要求一个正整数n 除以8所得的余数,不可以采用(D )oA) n Mod 8 n-Int(n/8)*8 B) n-Fix(n/8)*8 n-Int(n\8) 程序设计参考习题(16级)一、单项选择题1. 如果a, b, c 的值分别是・2, 2, 3,则下列表达式的值是(A )。
Math.Abs (b*c-a ) + b*Int (Rnd ())A ) 8B ) 9C ) 10D ) 11 2. 执行如下语句:Label 1 .Text= InputBoxf 4请输入标题“新标题“旧标题”)将显示一个输入对话框,若用户不输入内容就直接冋车,贝J Label 1显示的标题内容是 (A )。
A )旧标题B )新标题C )空白D )请输入标题3. 在代码窗口中,当从对象列表框屮选定了某一对象后,在(A )屮会列出适用该对象 的事件过程。
A )事件过程列表框B )属性框C )工具箱D )工具栏 5. 在设计阶段,用鼠标双击窗体上的某个控件,打开的窗口是(C )oA )解决方案资源管理器窗口B )属性窗口C )代码窗口D )即时窗口6. 设窗体VBform 上有1个命令按钮Btnl,下面叙述正确的是(C ) A ) 窗体的Click 事件过程的过程名是Form_Click B ) 窗体的Click 事件过程的过程名是Forml_Click C ) 命令按钮的Click 事件过程的过程名是Btnl_Click D ) 命令按钮的Click 事件过程的过程名是Buttonl_CIick7. 要在命令按钮Button!上显示“开始”,可用下列语句中的(B )。
A ) Buttonl.Value ="开始" B ) Button 1 .Text = v 开始" C ) = ”开始”D ) Button 1.Caption = ,?开始”8. 以下可以用普通文本编辑软件打开阅读的数据文件是( B )oB )顺序文件C )随机文件)函数的执行结果与英他3个不一样。
VB语言习题集答案(无编程部份答案)
VB语言习题集答案第一章VB环境和程序设计初步习题一、选择题1-5: ACBCA 6-10: BACBA 11-15: DCDAD 16-20: BDBCA21-24: BDAD二、填空题(1)ADO ActiveX Database Object 第9章介绍(2)视图(3)工具箱(4)工具(5)选项(6)编辑器(7)对象的性质,来描述和反映对象特征的参数(8)对象的动作和行为(9)Form窗体(10)Font(11)MultiLine(12)在程序运行时无效。
有些属性只能在设计时才能设置,例如:BorderStyle, MaxButton等;有些属性只能在运行时设置,例如:SelStart, SelLenght等。
(13)Style(14)工程(15)工程属性(16)通用(17)Form1.Show(18)SelStart(19)Locked(20)TabIndex(21)0三、编程题第二章简单的VB程序设计习题一、概念题1、合法常量有:(1)Single (3)Single (4)Double (7)String (9)Date (10) Double (12)八进制的整型(13) 八进制的整型(14) 十六进制的整型(15)Boolean (18)Single2、合法变量:(1)(2) (6) (9) (10) (11)3、(1)abs(x+y)+z^5(2)(1+x*y)^6(3)(10*x+sqr(3*y))/(x*y)(4)sin(45*3.1415926/180)+(exp(10)+log(10))/sqr(x+y+1)4、(1)chr$(67) and chr$(76)(2)int(rnd*101)+100(3)int(x/5) =x/5 or int(x/7)=x/7(4)略(5)int(x*100+0.5)/100(6)略(7)略(8)x>=10 and x<20(9)x<z or y<z(10)x>z and y>z5、写出下列表达式的值:(1)188 (2)200100 (3)68.56 (4)876543 (5)2000-2-29(6) 66、略7、略8、略9、答:数字字符串转换成数值,用Val函数;用IsNumeric()函数可判断是否是数字字符串;用Mid()函数取字符串中的某几个字符;用Ucase()函数将小写字母转换成大写字母;用Lease()函数将大写字母转换成小写字母。
vb习题答案
vb习题答案VB习题答案Visual Basic(VB)是一种广泛应用于软件开发的编程语言,它简单易学、功能强大,因此备受开发者的喜爱。
然而,对于初学者来说,掌握VB的各种知识和技巧并不容易。
为了帮助大家更好地学习和理解VB,本文将提供一些常见习题的答案,希望能够对大家的学习有所帮助。
1. 请写一个VB程序,输出“Hello, World!”。
答案:```vbModule Module1Sub Main()Console.WriteLine("Hello, World!")Console.ReadLine()End SubEnd Module```2. 请写一个VB程序,计算并输出1到100之间所有偶数的和。
答案:```vbModule Module1Sub Main()Dim sum As Integer = 0For i As Integer = 1 To 100If i Mod 2 = 0 Thensum += iEnd IfNextConsole.WriteLine("1到100之间所有偶数的和为:" & sum) Console.ReadLine()End SubEnd Module```3. 请写一个VB程序,判断一个输入的整数是否为素数。
答案:```vbModule Module1Sub Main()Console.WriteLine("请输入一个整数:")Dim num As Integer = Console.ReadLine()Dim isPrime As Boolean = TrueIf num <= 1 ThenisPrime = FalseElseFor i As Integer = 2 To Math.Sqrt(num)If num Mod i = 0 ThenisPrime = FalseExit ForEnd IfNextEnd IfIf isPrime ThenConsole.WriteLine(num & "是素数。
vb练习题及答案
vb练习题及答案VB练习题及答案一、选择题1. 在VB中,以下哪个是正确的数据类型?A. IntegerB. IntC. Both A and BD. None of the above答案:C2. VB中,哪个关键字用于声明变量?A. DimB. DeclareC. DefineD. Set答案:A3. 在VB中,以下哪个是正确的循环结构?A. ForB. WhileC. RepeatD. All of the above答案:D4. VB中,以下哪个是正确的条件语句?A. IfB. SwitchC. CaseD. A and B only答案:A5. 在VB中,以下哪个是正确的数组声明方式?A. Dim myArray(5) As IntegerB. Dim myArray As Integer(5)C. Both A and BD. None of the above答案:A二、填空题1. 在VB中,使用________关键字可以定义一个类。
答案:Class2. VB中,使用________方法可以为控件添加事件处理程序。
答案:AddHandler3. 在VB中,________方法用于结束程序的执行。
答案:End4. VB中,________属性用于获取或设置一个控件的文本。
答案:Text5. 在VB中,________方法用于打开一个文件。
答案:Open三、简答题1. 请简述VB中的事件和事件处理程序的概念。
答案:在VB中,事件是用户或程序触发的特定动作,如按钮点击或键盘敲击。
事件处理程序是一个过程,当特定的事件发生时,会被自动调用以响应该事件。
2. 描述VB中如何使用For循环。
答案:在VB中,For循环用于重复执行一段代码直到满足特定条件。
基本语法是:```For counter = start To end [Step increment]' 循环体Next [counter]```3. 解释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 = 0End SubPrivate 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 = FalseEnd IfEnd SubPrivate Sub Check3_Click()If Check1.V alue = 1 ThenText1.FontUnderline = TrueElseText1.FontUnderline = FalseEnd IfEnd SubPrivate Sub Command1_Click()Text1.Text = " "End Sub2.Private Sub Command1_Click()Text2.Text = List1.ListCountEnd 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.ListCountEnd SubPrivate Sub Form_Load()Command3.Enabled = FalseEnd SubPrivate Sub List1_Click()Command3.Enabled = TrueEnd 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 + tLoop Print s End Sub。
(完整版)VBNET习题集答案(无编程答案)-刘炳文书
本文由余亚洪贡献doc文档可能在WAP端浏览体验不佳。
建议您优先选择TXT,或下载源文件到本机查看。
第 1、2 章 Visual Basic .NET 程序开发环境、一、单选题:单选题:1、A2、A3、B二、填空题:填空题:,Internet 协议。
1、XML(可扩展标记语言)、这里的 Internet 协议主要是指:HTTP 和 SOAP-简单对象访问协议。
2、可以提供多语言支持。
、 3、IIS(Internet Information Service)。
、 4、ADO .NET。
(本课程不要求)、 5、视图,工具箱。
、6、项目,“属性…”命令项,“生成”选项。
7、sln, vbproj, vb, bin。
三、编程题:略第 6 章常用 Windows 窗体和控件一、单选题1-5:CBCAD 6-10:BCABD 11-15:ADCDB 16-20:CDDCB 21-25:ACCDD 26-30:AABC 31-35:DDDDA 36-38:DCB二、填空题1、TextBox1.ForeColor=Color.Red;2、对象的性质,来描述和反映对象特征的参数;3、对象的动作和行为;4、对窗体的 FontName 属性设置;5、MultiLine;6、BackgroupImage;7、工具,对象属性,启动对象, Dim firstForm As New form1 firstForm.Show() 8、SelectAll 属性或 SelectText 属性,程序运行 9、Locked 10、Load, TabIndex, 0, Button1.Focus() 11、FormBorderStyle=FixSingle 12、Form1.Loction=new Point(left, top) 写在 Load 事件中。
13、CheckAlign=MiddleRight 14、ImageAlign 15、Image16、Enabled *17、0 *18、ListBox1.Items(ListBox1.Items.Count - 1) 19、Items 20、Items.Clear 21、当 DropDownStyle 属性为 DropDownList 值。
VBNET习题集汇编
习题集汇编整理者: 华中科技大学管理学院龚晓光一、单项选择题是否完全符合CLS? ( A )。
A. 是B. 否2. 窗体中提供的是Hide方法的作用是( D )。
A. 销毁窗体对象B. 关闭窗体C. 将窗体极小化D.隐藏窗体3. 窗体对象的Close方法的作用( C )。
A. 极小化窗体B. 隐藏窗体C. 关闭窗体D. 销毁窗体对象(注意,这个题目有问题,参考后面的多选题)4. 中编写对象的成员方法代码时,表示"本对象"的关键字为( D )。
A. loca10bjectB. selfC. thisD. Me5. 程序中的逻辑错误能否被编译器发现?( B )。
注:编译器只能捕获语法错误,而不能捕获运行时错误和逻辑错误。
A.能B.不能6. 对于语句Speed=Miles/Hours(其中Speet,Miles,Hours都是Double值),当Hours=0时,该语句将引发( C )。
.A.逻辑错误B.编译错误C.运行错误D.语法错误7. 在.NET构架中,程序被编译成( B )。
A.脚本B.MSIL码C.汇编码D.机器码8. InputBox( )函数括号中的第一个参数代表( A )。
A、提示信息B、标题C、默认值D、对话框位置9. 以下哪种项目是不能创建的( B )。
A、Windows应用程序B、Dos应用程序C、Web应用程序D、Windows服务10. 要在文本框中显示文本,应给其( A )属性赋值。
A、TextB、CaptionC、NameD、File11. 将按钮的Visible属性设为False,按钮会( B )。
A、可用且可见B、可用不可见C、可见不可用D、不可用不可见(注意,Visible属性设为False,在程序中测试,发现控件的enable属性是没有被修改的,所以控件是可用的。
而事实上,控件不可见,没有办法接受焦点,不能触发相关事件,对用户事实不可用,程序中还是可以用的(涉及到DDE等内容)。
VB课后习题答案汇总
课后习题参考答案第1章Visual Basic 6.0一、判断题1--5:√×√×√ 6――10:××√×√ 11――13:√××二、选择题1――5:ADBBB 6――10:.CACDB三、填空题1、图片框和框架2、对象3、控件屏幕4、Load5、Load Activate四、程序设计题1、Private Sub Command1_Click()Print Text1.TextEnd SubPrivate Sub Command2_Click()EndEnd Sub2、Private Sub Command1_Click()Form1.FontSize = Form1.FontSize + 3Print "青春无悔"End SubPrivate Sub Command2_Click()FontSize = FontSize - 3Print "青春无悔"End SubPrivate Sub Command3_Click()Form1.FontBold = TruePrint "青春无悔"End SubPrivate Sub Command4_Click()FontBold = FalsePrint "青春无悔"End Sub3、Private Sub Command1_Click()Text1.Visible = FalseEnd SubPrivate Sub Command2_Click()Text1.Visible = TrueText1.FontName = "楷体_gb2312"Text1.FontSize = 15Text1.Text = "我学会了创建一个应用程序了!"End Sub第二章判断题:1~5错错错错错第3章顺序结构程序设计一、思考题略二、程序阅读题1.A=2 B=1 C=22.123.BABCBACBC4. 1 2 False5.1-12-123-1234-三、选择题1.B2.D3.B4.B5.D6.C四、程序设计题1.Private sub form_click()Dim r!,s!R=val(inputbox(“r=”))S=3.14159*r*rPrint “s=”;sEnd sub2.Private sub form_click()Dim x as singleX=val(inputbox(“x=”))Print fix(x*x*1000)/1000,fix(sqr(x)*1000)/1000End sub第4章选择结构程序设计一、判断题1.错2.错3.错4.错5.对二、选择题1.A 2. D 3.A 4.B 5.A 6.A三、程序阅读题1.X=3 y=72.w=4w=13w=135w=313.X_`a12 Uvw&4.12 9四、程序填空题1.(1) chr(keyascii) (2) chr(keyascii)=”)”(3)count1=count1-1 (4)count1=0 (5)count1>02.(1) max (2)min (3)c>max (4)c<min3.(1)x mod 3=2 and x mod 5=3 and x mod 7=4 then(2)text1.setfocus (3) text1.selstrat=0 (4)text1.sellength=len(text1.text)五、1.Private Sub Command1_Click()Dim y As Integery = Val(InputBox("y="))If (y Mod 4 = 0 And y Mod 100 <> 0) Or (y Mod 400 = 0) Then Print "是闰年"ElsePrint "不是闰年"End IfEnd SubPrivate Sub Command1_Click()Dim y As Integer,y1 as stringy = Val(InputBox("y="))If (y Mod 4 = 0 And y Mod 100 <> 0) Or (y Mod 400 = 0) Then Y1= "是闰年"ElseY1= "不是闰年"End If? y,y1End SubPrivate Sub Command1_Click()Dim y As Integer,y1 as stringy = Val(InputBox("y="))Y1= "不是闰年"If (y Mod 4 = 0 And y Mod 100 <> 0) Or (y Mod 400 = 0) Then Y1= "是闰年"End If? y,y1End Sub2.Private Sub Command1_Click()Dim a%, b%, c%, x!,s!a = Val(InputBox("a="))b = Val(InputBox("b="))c = Val(InputBox("c="))If a + b > c And a + c > b And b + c > a Thenx = (a + b + c) / 2s = Sqr(x * (x - a) * (x - b) * (x - c))Print "s="; sElsePrint "不是三角形,重输a,b,c"End IfEnd SubPrivate Sub Command1_Click()Dim a%, b%, c%, x!,s!,t%a = Val(InputBox("a="))b = Val(InputBox("b="))c = Val(InputBox("c=")) ‘a,b,c=3,4,5t=0If a + b > c And a + c > b And b + c > a Thenx = (a + b + c) / 2s = Sqr(x * (x - a) * (x - b) * (x - c))t=1End IfIf t=0 then? “不是“endifEnd Sub3.Private Sub Command1_Click()Dim x!, y!x = Val(InputBox("x="))y = x * x - x – xIf x < 0 And x <> -3 Theny = x * x + x - 6ElseIf 0 <= x And x < 10 And x <> 2 And x <> 3 Then y = x * x - 5 * x + 6End IfPrint "x="; x, "y="; yEnd SubPrivate Sub Command1_Click()Dim x!, y!x = Val(InputBox("x="))If x < 0 And x <> -3 Theny = x * x + x – 6elseIf 0 <= x And x < 10 And x <> 2 And x <> 3 Theny = x * x - 5 * x + 6elsey=x^2-x-1End IfPrint "x="; x, "y="; yEnd SubPrivate sub form_click()Dim y%,z%,dj%,p!,t!Y=val(inputbox(“月”))Z= val(inputbox(“订票数”))Dj= val(inputbox(“票价”))Select case ycase 7,8,9If z>=20 then p=0.15 else p=0.05case 1 to 5,10,11If z>20 then p=0.3 else p=0.2Case elseP=0.2End selectT=z*dj*p? tend sub5.private sub form_click()dim m1%,m2%,m3%,dj$m1=val(inputbox(“m1=”)): m2=val(inputbox(“m2=”)): m3=val(inputbox(“m3=”))if (m1+m2+m3)/3>=95 or ( a=100 and b=100 and c>=80) or ( a=100 and c=100 and b>=80) or ( c=100and b=100 and a>=80) thendj=”一等”elseif (m1+m2+m3)/3>=90 or ( a=100 and b>=75 and c>=75) or ( b=100 and a>=75 and c>=75) or ( c=100 and b>=75 and a>=75) thendj=”二等”elseif a>=75 and b>=75 and c>=75 thendj=”三等”elsedj=”没有”endif? “dj=”;djend sub第5章 循环结构程序设计1.判断题×√√√××√×2.选择题BBBBCC3.填空题(1)7(2)Do/Loop For/Next While/Wend(3)-364.程序阅读题(1) (2)(3)4 (4)5.程序填空题(1)①sign=1 ②For i=2 to 19(2)①Len(str1) ②length-1 ③Mid(str1,i,2) ④Sum=0(3)①I mod 7=5 and i Mod 5 = 3 And i Mod 3=2 ②i<1000(4)①last_one = last_two ②last_two = this_one ③i=i+1 ④i-2(5)①I>int(sqr(m)) ②Int(Sqr(n-m))6.编程题(1)Private Sub Form_Click()Dim i As Integer, j As IntegerDim s As Double, Sum As Doubles = 188 68861 2 3 4 Sum=10# # # # # ## # # # ## # # ## # ## ##For i = 1 To 11 Step 2For j = 1 To is = s * jNext jSum = Sum + sNext iPrint SumEnd Sub(2)Private Sub Form_Click()Dim m%, n%, mn%, r%, t%m = Val(InputBox("m="))n = Val(InputBox("n="))If n <= 0 Or m <= 0 ThenMsgBox "数据有误"EndEnd Ifmn = m * nIf m < n Thent = m: m = n: n = tEnd IfDo While (n <> 0)r = m Mod n: m = n: n = rLoopForm1.Print "最大公约数="; mForm1.Print "最小公倍数="; mn / m End Sub(3)Private Sub Form_Click()Dim i%, j%For i = 1 To 5Print Spc(20 - i);For j = 1 To 2 * i - 1Print Trim(Str(i));Next jPrintNext iFor i = 4 To 1 Step -1Print Spc(20 - i);For j = 1 To 2 * i - 1Print Trim(Str(10 - i));PrintNext iEnd Sub(4)Private Sub Form_Click()Dim x As IntegerDim y As IntegerDim z As IntegerFor x = 0 To 100For y = 0 To 100 - xz = 100 - x - yIf 5 * x + 3 * y + z / 3 = 100 Then Print x, y, zNext yNext xEnd Sub(5)Private Sub Form_Click()Dim x As Single, y As Single, a As Single, i As Integerx = Val(InputBox("输入x:"))a = 1: y = a: i = 0While a >= 0.00001i = i + 1: a = a * x / i: y = y + aWendPrint "y="; yEnd Sub第六章答案一、判断题1.错2.错3.错4.错(可以为小数,不过仍然是当作整数来处理)5.错6.错二、选择题1.C2.C3.A4.D三、程序填空1.(1)N-1 (2)T = A(J): A(J) = A(J + 1): A(J + 1) = T(3)Print A(I)2.(1)a(i, j) = 1 (2)Print四、程序阅读1.52.1 2 3 41 2 3 41 2 3 41 2 3 41 1 1 12 2 2 23 3 3 34 4 4 43.(前面空4个空格)1 12 11 102 13 16 93 14 15 84 5 6 7第7章过程判断题:1、对2、错3、错4、错5、对6、对7、错选择题:1.B 2、D 3、D 4、C 5、A程序阅读题:1、y=5 a=52、n=1 z=4y=15 a=10 n=2 z=7y=30 a=15 n=3 z=103、32 644、2 2 216 648 644 645、A1=10 B1=20A2=20 B2=10程序填空题:1、(1)hwstring(str) (2)"" (3)As Boolean(4)n=len(strtxt) (5) True (6)False2.(1)Xsch(Nman,Nkcen) (2)n(3)sum=sum+x(i,j) (4)tt/n (5)x(i,m+1)<1.2*ver and x(i,m+1)>=1.1*ver 3.(1)number(i)(2)Byval n as Integer (3)number= number+7*10^ (i-1)4.(1)temp=1 (2)temp (3)nFactor( i ) (4)sum 程序设计题:1、具体程序为:Function Maxnum(ByRef a() As Integer, ByVal n As Integer) As IntegerDim i As IntegerMaxnum = a(1)For i = 2 To nIf a(i) > Maxnum Then Maxnum = a(i)Next iEnd FunctionFunction Avenu(ByRef a() As Integer, ByVal n As Integer) As SingleDim i As Integer, sum As IntegerFor i = 1 To nsum = sum + a(i)Next iAvenu = sum / nEnd FunctionSub Sortrnum(ByRef a() As Integer, ByVal n As Integer)Dim i As Integer, j As Integer, k As IntegerDim temp As IntegerFor i = 1 To nk = iFor j = i + 1 To nIf a(k) > a(j) Then k = jNext jIf i <> k Thentemp = a(i)a(i) = a(k)a(k) = tempEnd IfNext iEnd SubPrivate Sub Form_Click()Dim b(10) As Integer, i As IntegerFor i = 1 To 10b(i) = InputBox("请输入整数", "输入")Next iCall Sortrnum(b(), 10)Print "从小到大排序为:"For i = 1 To 10Print b(i);NextPrintPrint "最大数为:"; Maxnum(b(), 10)Print "平均数为:"; Avenu(b(), 10)End Sub2、具体程序为:Function fe(n%, x!) As SingleDim temp As Single, i As Integerfe = 1temp = 1For i = 1 To ntemp = temp * x / ife = fe + tempNext iEnd FunctionPrivate Sub Form_Click()Dim n As Integer, x As Singlen = Val(InputBox("请输入n", "输入"))x = Val(InputBox("请输入x", "输入"))Print "e的值为:"; fe(n, x)End Sub3、具体程序为:Sub sort(a() As Single, n As Integer)Dim i As Integer, j As Integer, k As Integer Dim temp As SingleFor i = 1 To nk = iFor j = i + 1 To nIf a(k) < a(j) Then k = jNext jIf i <> k Thentemp = a(i)a(i) = a(k)a(k) = tempEnd IfNext iEnd SubPrivate Sub Form_Click()Dim a(10) As Single, i As IntegerFor i = 1 To 10a(i) = Val(InputBox("请输入数据", "输入")) Next iCall sort(a(), 10)Print "从大到小为:"For i = 1 To 10Print a(i);If i Mod 5 = 0 Then PrintNext iEnd Sub第8章 常用控件参考答案:一、判断题1、×2、×3、√4、√5、×6、×7、×8、×9、× 10、×11、× 12、√ 13、× 14、√ 15、√二、单选题1、A2、B3、A4、C5、B6、D7、A8、B9、C 10、C11、A 12、A 13、C 14、B 15、A三、填空题1、Autosize WordWrap2、Enabled Visible3、文本框和列表框4、拖动滚动框5、Change6、Command1.Setfocus7、Timer8、MaxLength 9、AddItem 10、定时器屏蔽123 45.五、程序填空题1、(1) Label1.left (2) –Label1.Width2、(1) List1.ListIndex<0 (或者List1.ListIndex = -1) (2) List1.RemoveItem List1.ListIndex(3) Text1.Text=”” (4) List1.AddItem Text1.Text3、(1) 1 to 2*I-1 (2) Command2.Enabled=True(3) Command2.Enabled=False4、(1) ndec<>0 (2) ndec mod 16 (3) ai=ndec(4) end (5) ai & shex (6)shex5、(1) Timer1.Enabled=True (2) x \ 3600 (3) (x-h*3600)\60(4) x=x+16、(1) m<len(str1)/2 (2) mid (str1,m+1,1) (3)mid (str1,len(str1)-m,1)六、程序设计题1、 Private Sub Command1_Click()If Text1.Text = "" ThenMsgBox "请先输入添加项"ElseList1.AddItem Text1.TextEnd IfEnd SubPrivate Sub Command2_Click()If List1.ListIndex < 0 Then ‘或者if list1.listindex=-1 then MsgBox "请选择一删除项"ElseList1.RemoveItem List1.ListIndexEnd IfEnd SubPrivate Sub Command3_Click()If List1.ListIndex < 0 ThenMsgBox "请选择一修改项"ElseText1.Text = List1.TextEnd IfCommand4.Enabled = TrueEnd SubPrivate Sub Command4_Click()Dim a As IntegerIf List1.Text = Text1.Text ThenMsgBox "请先修改此项"Elsea = List1.ListIndexList1.RemoveItem List1.ListIndexList1.AddItem Text1.Text, aEnd IfEnd SubPrivate Sub Form_Load()Command4.Enabled = FalseEnd Sub2、 Dim a As IntegerPrivate Sub Command1_Click()a = Int(Rnd * 100) + 1End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)Static i As IntegerIf KeyAscii = 13 ThenIf Val(Text1.Text) > a ThenLabel1.Caption = "太大了,请重输"i = i + 1ElseIf Val(Text1.Text) = a ThenLabel1.Caption = "恭喜你,你答对了!"i = 0Command1_ClickElseLabel1.Caption = "太小了,请重输!"i = i + 1End IfIf i > 10 ThenMsgBox "你失败了!"EndEnd IfEnd IfEnd Sub3、Private Sub Command1_Click()Dim n As Integer: n = Len(Text1.Text)Dim s(1 To 1000) As String, i As Integer, j As Integer, t As String,a As StringFor i = 1 To ns(i) = Mid(Trim(Text1.Text), i, 1)Next iFor i = 1 To n - 1For j = i + 1 To nIf s(i) > s(j) Thent = s(i): s(i) = s(j): s(j) = tEnd IfNext j, iFor i = 1 To n: a = a + s(i): Next iPrint aCommand1.Enabled = False: Command2.Enabled = TrueEnd SubPrivate Sub Command2_Click(): End: End SubPrivate Sub Form_Load()Text1.MaxLength = 200Command2.Enabled = False: Command1.Enabled = TrueEnd Sub4、Dim a(1 To 1000) As String, b(1 To 1000) As String, c(1 To 1000) As Double, d(1 To 1000) As DoublePrivate Sub Combo1_click()Text1.Text = a(Combo1.ListIndex + 1)Text2.Text = b(Combo1.ListIndex + 1)Text3.Text = c(Combo1.ListIndex + 1)Text4.Text = d(Combo1.ListIndex + 1)End SubPrivate Sub Command1_Click()Combo1.AddItem Text1.Texta(Combo1.ListCount) = Text1.Textb(Combo1.ListCount) = Text2.Textc(Combo1.ListCount) = Val(Text3.Text)d(Combo1.ListCount) = Val(Text4.Text)End SubPrivate Sub Command2_Click()For i = Combo1.ListIndex + 1 To Combo1.ListCount - 1a(i) = a(i + 1)b(i) = b(i + 1)c(i) = c(i + 1)d(i) = d(i + 1)Next ia(i) = ""b(i) = ""c(i) = 0d(i) = 0Combo1.RemoveItem Combo1.ListIndexText1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""End SubPrivate Sub Form_Load()Dim i As IntegerCombo1.AddItem "张三"Combo1.AddItem "李四"Combo1.AddItem "王五"a(1) = "张三": a(2) = "李四": a(3) = "王五"b(1) = "浙江林学院": b(2) = "浙江工业大学": b(3) = "浙江大学"c(1) = : c(2) = : c(3) =d(1) = : d(2) = : d(3) =End Sub5、Private Sub Check1_Click()If Check1.Value = 1 ThenLabel1.FontBold = TrueElseLabel1.FontBold = FalseEnd IfEnd SubPrivate Sub Check2_Click()If Check1.Value = 1 ThenLabel1.FontItalic = TrueElseLabel1.FontItalic = FalseEnd IfEnd SubPrivate Sub Option1_Click()Label1.FontName = "宋体"End SubPrivate Sub Option2_Click()Label1.FontName = "楷体_gb2312"End Sub6、Private Sub Command1_Click()Dim a As String, i As Integer, n As IntegerDim s As Integer, q As Integer, l As Integern = Len(Text1.Text)For i = 1 To na = Mid(Text1.Text, i, 1)If a >= "a" And a <= "z" Thens = s + 1 '大写个数ElseIf a >= "A" And a <= "Z" Thenq = q + 1 '小写个数ElseIf a >= "0" And a <= "9" Thenl = l + 1End IfNext iText2.Text = sText3.Text = qText4.Text = lEnd SubPrivate Sub Form_Load()Text1.SetFocusEnd Sub7、Private Sub Form_Click()Dim i As Integer, j As Integer, t As IntegerFor i = 0 To List1.ListCount - 1List3.AddItem List1.List(i)Next iList1.ClearDo While List2.ListCountList3.AddItem List2.List(0)List2.RemoveItem 0LoopFor i = 0 To List3.ListCount - 2For j = i + 1 To List3.ListCount - 1If List3.List(i) > List3.List(j) Thent = List3.List(i): List3.List(i) = List3.List(j): List3.List(j) = tEnd IfNext j, iEnd SubPrivate Sub Form_Load()Dim i As Integer, n As Integern = InputBox("")For i = 1 To nList1.AddItem Int(Rnd * 90) + 10List2.AddItem Int(Rnd * 90) + 10Next iEnd Sub第9章对话框和菜单1.判断题:×√√(题中应把flag改为flags)√√××√√×××√××2.选择题:DDCCD BDCCB3.填空题1.-2.一级子菜单3.将顶级菜单设置为不可见4.popupmenu pmenu,0,x,y5.showfont6.工程、部件7.click8.代码窗口,click9.下拉式,弹出式打开/另存为、颜色,字体、打印、帮助4. 程序阅读题打开对话框2、*.txt3、allfiles*.exe*.txt*.doc4、Checking,No File Selectd,重试(R),取消5. 程序填空题“c:\winnt”commondialog1.showopen,loadpicture(commondialog1.filename)6. 程序设计题1、界面如图:代码如下:Private Sub Command1_Click()CommonDialog1.FileName = ""CommonDialog1.Flags = 4096CommonDialog1.Action = 1If CommonDialog1.FileName = "" ThenMsgBox "No File Selectd", 5 + vbExclamation, "Checking"ElseList1.AddItem CommonDialog1.FileNameEnd IfEnd Sub2、代码如下:Private Sub a_Click()CommonDialog1.ShowColorText1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub b_Click()CommonDialog1.Flags = 1CommonDialog1.ShowFontText1.FontSize = CommonDialog1.FontSizeEnd SubPrivate Sub c_Click()CommonDialog1.Flags = 1CommonDialog1.ShowFontText1.FontName = CommonDialog1.FontNameEnd SubPrivate Sub d_Click()EndEnd Sub第10章图形操作和图形控件一、判断题×√×××√×√××二、选择题BAADACAA三、填空题(1)pic1.Circle (pic1.ScaleLeft + pic1.ScaleWidth / 2, pic1.ScaleTop + pic1.ScaleHeight / 2), 700(2)在图片框picture1中,以(800,1000)为圆心画一个半径为500的圆(3)Form1.Scale (-200, 250)-(300, -100)(4)Autosize stretch四、程序阅读题1、窗体宽和高的1/4为起点,画一个边长为1000的正方形,并画出其正向对角线2、在图片框中交替画出实心和空心的矩形,空心矩形是黄色边框。
VB 课后习题参考答案
第1章 习题参考答案一、思考题 略二、选择题1. C2. B第2章 习题参考答案一、判断题二、填空题1. 窗体font2. 不能在代码中设置 3. selstart 4. Locked5. TabIndex 、 0 6. vbModal 或 17. Activate 、 Deactivate 8.PictureBox 和 Frame -三、选择题第3章 习题参考答案一、思考题1、double2、 xyC@abc , 15eyd , Is , #END X8[P]3、变量有 (1) (4) (6) (8),常量有 (2)字符串型 (3)逻辑型 (5)字符串型 (7)字符串型 (9)日期型 (10)实型 4、 fe d cb a++5、 (1) 26 (2) 3.75 (3) 36、写出下列Visual Basic 表达式的值:(1) False (2) True (3) True (4) False (5) True(6) True (7) False (8) False7、将下列命题用Visual Basic布尔表达式表示:(1) z>x and z>y (2) abs(a)<=abs(b+2) or a > b+2(3) p mod q=0 (4) x<-5 or x>-2 and x<2 or x>5(5) x<z and y>z or x>z and y<z (6) a<b and a mod 2=08、写出下列函数的值:(1) -4 (2) 换行符(3) –3 (4) -1 (5) hello(6) ello (7) 16 (8) “-459.65” (9) 5二、填空题1.整型、长整型、双精度型、双精度型2.(X mod 10)*10+X\103.sin(1/4*3.14)+sqr(x+2*exp(y))/abs(x-y)4.(a+b)/(c*d-sqr(1-a^2))5.x mod 5=0 or x mod 9=06.False7.-3 、 2 、-2 、 28.CDEF9.x>0 and y>0 or x<0 and y<0 或x*y>010.s>=”A” and s<=”Z” or s>=”a” and s<=”z”三、选择题四、编程题1、Private Sub Form_Click()Dim x%, Ten%, hundred%x = Val(Text1.Text)Ten = (x \ 10) Mod 10hundred = x \ 100Print "百位数是: " & hundredPrint "十位数是: " & TenEnd Sub2Private Sub Form_Click()Dim char As String * 1Form1.CurrentX = Rnd * Form1.ScaleWidthForm1.CurrentY = Rnd * Form1.ScaleHeightchar = Chr(Int(Rnd * 16) + 65)Print charEnd Sub第4章习题参考答案一、判断题二、选择题三、程序阅读写出下列各段程序执行后的输出结果。
VBNET课后答案
课后答案第一章一、选择题1.A 2.A 3.A 4.D二、填空题1.公共语言运行库2.解决方案资源管理器3.Text4.Read或ReadLine Write或WriteLine5.Main()6.方法事件1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickEndEnd Sub2 Sub Main()Dim a, b, c As IntegerConsole.Write("请输入第一个数:")a = Console.ReadLine() '输入第一个数Console.Write("请输入第二个数:")b = Console.ReadLine()c = a + bConsole.WriteLine("和为:" & c)End Sub第二章一、选择题1.A 2.A 3.B 4.C二、填空题1.True2.73.04._ (下划线加空格)5.Math.Exp(B+8)*Math.Sin(75/180*Math.PI)6.Math.Pow(a+b,x+y)7.jd / 180 * Math.PI c * Math.Cos(d)1 Dim D As Single'存放直径Dim S As Single'存放面积S = Val(TextBox1.Text) '获取面积D = Math.Sqrt(S / Math.PI) * 2 '求得直径TextBox2.Text = CStr(D) '显示出直径End Sub2 Dim a, b, c, sinv, cosv, tanv As Double'用来存放三角形的三个边长c = Val(TextBox1.Text) '斜边长度a = Val(TextBox2.Text) '一直角边长度b = Math.Sqrt(c * c - a * a) '另一直角边sinv = a / c : TextBox3.Text = CStr(sinv) '求得正弦值并显示cosv = b / c : TextBox4.Text = CStr(cosv) '求得余弦值并显示tanv = a / b : TextBox5.Text = CStr(tanv) '求得正切值并显示End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickEndEnd Sub第三章一、选择题1.A 2.C 3.B 4.D二、填空题1.While …End While For…Next2.33.edcba4.Exit For5.999 a ^ 3 + b ^ 3 + c ^ 3 = i6."合格"1 Dim s As Single = 100, t As Single = 100Dim i As Integeri = 1Do While i < 10s = s + tt = t / 2i = i + 1LoopTextBox1.Text = Str(s)TextBox2.Text = Str(t)End Sub2 ivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim S As Double, T As Double, I As IntegerT = 1 : S = 0For I = 1 To 10T = T * IS = S + TNext ITextBox1.Text = SEnd Sub第四章一、选择题1.B 2.D 3.A 4.B二、填空题1.Arr(5,5)2.03.ReDim Preserve Arr(10)4.UBound(Arr,2)5.i, j i, i i, 4 - i6.For Each1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim i As IntegerRandomize()TextBox1.Text = ""For i = 0 To N - 1Arr(i) = Int(90 * Rnd()) + 10TextBox1.Text = TextBox1.Text + CStr(Arr(i)) + " "Next iEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickDim aver As DoubleDim i, count As Integeraver = 0.0 : count = 0For i = 0 To N - 1aver = aver + Arr(i)Next iaver = aver / NFor i = 0 To N - 1If Arr(i) >= aver Thencount = count + 1End IfNext iTextBox2.Text = CStr(aver)TextBox3.Text = CStr(count)End Sub2Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim i, j As IntegerRandomize()Label1.Text = "数组:" + Chr(10) + Chr(13)For i = 0 To M - 1 '本循环生成数组各元素For j = 0 To N - 1Arr(i, j) = Int(90 * Rnd()) + 10 '产生两位随机整数赋值给数组元素Label1.Text = Label1.Text + CStr(Arr(i, j)) + " "'连接到Label1中Next jLabel1.Text = Label1.Text + Chr(10) + Chr(13) '换到下一行Next iEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickDim C1, C2, I, J As IntegerC1 = 0 : C2 = 0For I = 0 To M - 1For J = 0 To N - 1If Arr(I, J) Mod 2 <> 0 ThenC1 = C1 + 1ElseC2 = C2 + 1End IfNext JNext ILabel1.Text = Label1.Text + "奇数个数为:" + CStr(C1) + Chr(10) + Chr(13)Label1.Text = Label1.Text + "偶数个数为:" + CStr(C2) + Chr(10) + Chr(13)End Sub第五章一、选择题1.A 2.C 3.D 4.C二、填空题1.ByRef2.Optional3.ParamArray4.函数过程有返回值而通用过程无返回值5.Func1过程中的6.15 20 M=15,N=551Private Function PingFeng(ByVal Df() As Single) As SingleDim M, i As IntegerDim Sum As Single = 0.0, Maxdf, Mindf As SingleMaxdf = Df(0) : Mindf = Df(0)M = UBound(Df)For i = 0 To MSum += Df(i)If Maxdf < Df(i) Then Maxdf = Df(i)If Mindf > Df(i) Then Mindf = Df(i)Next iPingFeng = (Sum - Maxdf - Mindf) / (M + 1 - 2)End FunctionPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim pf() As Single, Final As Single, pfstr() As StringDim i, Num As Integerpfstr = Split(TextBox1.Text, ",")Num = UBound(pfstr)ReDim pf(Num)For i = 0 To Numpf(i) = pfstr(i)Next iFinal = PingFeng(pf)TextBox2.Text = CStr(Final)End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickTextBox1.Text = ""TextBox2.Text = ""End SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickEndEnd Sub2Private Function TaoZi(ByVal N As Integer) As IntegerDim k As IntegerIf N = 1 Thenk = 1Elsek = 2 * TaoZi(N - 1) + 1End IfReturn kEnd FunctionPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim N As IntegerN = Val(TextBox1.Text)TextBox2.Text = CStr(TaoZi(N))End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton2.ClickEndEnd Sub第六章一、选择题1.D 2.D 3.D 4.B二、填空题1.逻辑2.中断3.监视4.语法5.Number6.Finally7.Message8.前面1Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickEndEnd SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim ScoreStr(N - 1) As String, aver As Single = 0Dim Score(N - 1), i As Integer'存放成绩TryScoreStr = Split(TextBox1.Text, ",")For i = 0 To NScore(i) = Val(ScoreStr(i))aver = aver + Score(i)Next iTextBox2.Text = CStr(aver)Catch exam As System.IndexOutOfRangeExceptionTextBox2.Text = "数组下标越界"CatchTextBox2.Text = "其它异常"End TryEnd Sub2Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim Num1, Num2, Result As Single, Op As StringTryNum1 = Val(TextBox1.Text) : Num2 = Val(TextBox3.Text)Op = TextBox2.TextSelect Case OpCase"+" : Result = Num1 + Num2Case"-" : Result = Num1 - Num2Case"*" : Result = Num1 * Num2Case"/" : Result = Num1 / Num2End SelectTextBox4.Text = CStr(Result)Catch Exam As System.NotFiniteNumberExceptionMsgBox("无穷大异常")Catch Exam As System.OverflowExceptionMsgBox("溢出异常")End TryEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickEndEnd Sub第七章一、选择题1.B 2.B 3.A 4.A二、填空题1.TextChanged2.Increment3.CheckState4.MultiColumn5.SelectedItems6.SizeMode7.Interval8.Value1Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) End SubPrivate Sub TextBox1_TabStopChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickDim btn As Buttonbtn = senderTextBox1.Text += btn.TextEnd SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickDim btn As Buttonbtn = senderTextBox1.Text += btn.TextEnd SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickDim btn As Buttonbtn = senderTextBox1.Text += btn.TextEnd SubPrivate Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.ClickDim btn As Buttonbtn = senderTextBox1.Text += btn.TextEnd SubPrivate Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.ClickDim btn As Buttonbtn = senderTextBox1.Text += btn.TextEnd SubPrivate Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.ClickDim btn As Buttonbtn = senderTextBox1.Text += btn.TextEnd SubPrivate Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.ClickDim btn As Buttonbtn = senderTextBox1.Text += btn.TextEnd SubPrivate Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.ClickDim btn As Buttonbtn = senderTextBox1.Text += btn.TextEnd SubPrivate Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.ClickDim btn As Buttonbtn = senderTextBox1.Text += btn.TextEnd SubPrivate Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.ClickDim btn As Buttonbtn = senderTextBox1.Text += btn.TextEnd SubPrivate Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.ClickDim btn As Buttonbtn = senderTextBox1.Text = TextBox1.Text + " " + btn.Text + " "End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickTextBox1.Text = ""End SubPrivate Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.ClickDim btn As Buttonbtn = senderTextBox1.Text = TextBox1.Text + " " + btn.Text + " "End SubPrivate Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.ClickDim btn As Buttonbtn = senderTextBox1.Text = TextBox1.Text + " " + btn.Text + " "End SubPrivate Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.ClickDim btn As Buttonbtn = senderTextBox1.Text = TextBox1.Text + " " + btn.Text + " "End SubPrivate Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.ClickDim r As Single'保存计算结果Dim t As String = TextBox1.Text '用于保存文本框中的算术表达式Dim space As Integer = t.IndexOf(" ") '搜索空格位置Dim s1 As String = t.Substring(0, space)Dim op As String = t.Substring(space + 1, 1) '用于保存运算符Dim s2 As String = t.Substring(space + 3)Dim arg1, arg2 As Singlearg1 = Val(s1) : arg2 = Val(s2)Select Case opCase"+" : r = arg1 + arg2Case"-" : r = arg1 - arg2Case"*" : r = arg1 * arg2Case"/" : r = arg1 / arg2Case ElseMsgBox("输入的运算符有误!")Exit SubEnd SelectTextBox1.Text = CStr(r)End Sub2Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChangedEnd SubPrivate Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPressDim m As IntegerIf e.KeyChar = Chr(13) ThenFor m = 0 To ListBox1.Items.Count - 1If ListBox1.Items(m) = TextBox1.Text ThenTextBox1.SelectAll()Exit ForEnd IfNext mIf m = ListBox1.Items.Count ThenListBox1.Items.Add(TextBox1.Text)TextBox1.Text = ""TextBox1.Focus()End IfEnd IfEnd SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim m As Integer = 0For m = ListBox1.SelectedItems.Count - 1 To 0 Step -1ListBox1.Items.Remove(ListBox1.SelectedItems(m))Next mEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickListBox1.Items.Clear()End Sub第八章一、选择题1.D 2.A 3.D 4.A二、填空题1.FileName2.MultiSelect3.ShowDialog4.ShowEffects5.工具[&T]6.DialogResult.OK7.IsMdiContainer8.ImageIndex1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim testDialog As New InputBox() '产生输入对话框的实例If (testDialog.ShowDialog(Me) = DialogResult.OK) Then'显示输入对话框且单击了确定按钮Label1.Text = testDialog.TextBox1.Text '获得用户输入的内容ElseLabel1.Text = "Cancelled"'显示取消信息End IftestDialog.Dispose() '输入对话框释放End Sub2Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.ClickyoutMdi(MdiLayout.ArrangeIcons) '排列图标End SubPrivate Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.ClickDim fname As String'存放文件名Dim K As IntegerOpenFileDialog1.Filter = "文本文件(*.txt)|*.txt|图片文件(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF"'设置过滤器OpenFileDialog1.ShowDialog() '显示打开文件对话框fname = OpenFileDialog1.FileName '获得文件名K = fname.IndexOf(".")If UCase(fname.Substring(K + 1)) <> "TXT"ThenDim Child As New ChildForm2() '创建新的子窗体Child.MdiParent = Me'设置子窗体的MdiParentChild.Open(fname) '调用在子窗体中定义的open方法把文件显示在richTextBox框中Child.Show() '显示子窗体ElseDim Child As New ChildForm1() '创建新的子窗体Child.MdiParent = Me'设置子窗体的MdiParentChild.Open(fname) '调用在子窗体中定义的open方法把文件显示在richTextBox框中Child.Show() '显示子窗体End IfEnd SubPrivate Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.ClickApplication.Exit()End SubPrivate Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.ClickyoutMdi(MdiLayout.Cascade) '层叠End SubPrivate Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.ClickyoutMdi(MdiLayout.TileHorizontal) '水平平铺End SubPrivate Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem9.ClickyoutMdi(MdiLayout.TileVertical) '垂直平铺End SubPrivate Sub MenuItem11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem11.ClickDim i As IntegerFor i = Me.MdiChildren.Length - 1 To 0 Step -1Me.MdiChildren(i).Close() '关闭所有子窗体Next iEnd SubPrivate Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.ClickEnd Sub第九章一、选择题1.B 2.D 3.B 4.B二、填空题1.Protected2.New Finalize3.Value4.过程的重载重写5.Inherits E16.RaiseEvent1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim v As New Vehicle()Label1.Text = v.Run() + " " + v.Stoped()Dim bike As New bicycle(50, 100, 50, 285)Label2.Text = bike.Run() + " 速度:" + bike.Speed.ToString() + " " + bike.Stoped()Dim Car As New car(100, 250, 300, 150000.0)Label3.Text = Car.Run() + " 速度:" + Car.Speed.ToString() + " " + Car.Stoped() End Sub2Private CJ(5) As Double'存放成绩Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim i As IntegerRandomize()TextBox4.Text = ""For i = 0 To 4CJ(i) = 100 * Rnd()TextBox4.Text = TextBox4.Text + CStr(CJ(i))Next iEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickDim xm As String = TextBox1.TextDim nl As Integer = Val(TextBox2.Text)Dim xb As String = TextBox3.TextDim S1 As New Student(xm, nl, xb, CJ)S1.CalAver()TextBox5.Text = S1.Aver.ToString()End Sub第十章一、选择题1.D 2.A 3.A 4.C二、填空题1.FileOpen2.Input3.EOF(20)4.OpenMode.Random5.StreamWrite BinaryReader6.Peek()7.Position1Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadDim i As Integer'以打开和创建,只能写的方式创建文件流MyFileDim MyFile As New FileStream("C:\EXAMPLE1.DA T", FileMode.OpenOrCreate, FileAccess.Write)'根据MyFile文件流创建BinaryWriter流的实例MyBWriterDim MyBWriter = New BinaryWriter(MyFile, System.Text.Encoding.Unicode)For i = 1 To 10 '向文件流中写入个整数MyBWriter.Write(i * i)Next iMyBWriter.Close() '关闭文件流End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim i, num As Integer'创建文件流Dim MyFile As New FileStream("C:\EXAMPLE1.DA T", FileMode.Open, FileAccess.Read)'根据文件流创建StreamReader流的实例MyBFDim MyBF As New BinaryReader(MyFile, System.Text.Encoding.Unicode)i = Convert.ToInt32(TextBox1.Text)'定位到要读取的数据位置MyBF.BaseStream.Seek((i - 1) * 4, SeekOrigin.Begin)num = MyBF.ReadInt32() '读取一个整型数据TextBox2.Text = num.ToString() '显示读出的整型数据End Sub2Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickDim a As Integer, ch As Char'打开可读写的文件流Dim MyFile As New FileStream("Exam.txt", FileMode.Open, FileAccess.ReadWrite)a = MyFile.ReadByte() '从文件中读取一个字节Do While (a <> -1 And Chr(a) <> "#") '如果不是文件的结尾且在'#'字符前ch = Chr(a - 10)MyFile.Seek(-1, SeekOrigin.Current) '定位到前一字节MyFile.WriteByte(Asc(ch)) '写入要修改的字符a = MyFile.ReadByte() '再读一个字节LoopMyFile.Close() '关闭文件流End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim a As Integer, ch As Char'以打开,只读的方式创建文件流MyFileDim MyFile As New FileStream("Exam.txt", FileMode.Open, FileAccess.Read)a = MyFile.ReadByte() '从文件中读取一个字节TextBox1.Text = ""'清除TextBox1中显示的内容Do While (a <> -1) '如果不是文件的结尾ch = Chr(a) '把读取的字节转换为字符串型TextBox1.Text += ch '把读取的字符连接到TextBox1中a = MyFile.ReadByte() '从文件中读取一个字节LoopMyFile.Close() '关闭文件End Sub第十一章一、选择题1.C 2.A 3.B 4.A二、填空题1.System.Drawing2.Dim Mypen As New Pen(Color.Blue, 10)3.TextureBrush4.DrawPolygon5.NotifyValue6.StatusUpdate7.自定义工具箱8.AxMMControl1.hWndDisplay = Pic1.Handle.ToInt321Dim shouldPaint As Boolean'是否画图Dim startpt As Point '画线的起点Dim endpt As Point '画线的终点Dim g As Graphics '"画布"对象Dim Mypen As Pen '画笔对象Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loadg = Me.CreateGraphics() '生成Graphics对象gMypen = New Pen(Color.Blue, 3) '生成画笔对象MypenEnd SubPrivate Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDownshouldPaint = True'启动画图startpt.X = e.X '设置画线起点坐标startpt.Y = e.YEnd SubPrivate Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUpshouldPaint = False'结束画图End SubPrivate Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMoveIf (shouldPaint = True) Then'如果是画图状态endpt.X = e.X '设置本次画线终点endpt.Y = e.Yg.DrawLine(Mypen, startpt, endpt) '画线startpt = endpt '把本次的终点作为下一次画线的起点End IfEnd Sub2Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadAxMMControl2.Notify = Truemand = "Close"'关闭播放背景音乐的多媒体设备AxMMControl2.FileName = Application.StartupPath + "\1.mid"'设置背景音乐文件名mand = "Open"'打开多媒体设备AxMMControl2.TimeFormat = 3ProgressBar2.Minimum = 0 '设置进度条的最小值ProgressBar2.Maximum = AxMMControl2.Length + 1 '设置进度条的最大值mand = "Play"'播放openFileDialog1.Filter = "声波文件(*.WA V)|*.WA V"openFileDialog1.InitialDirectory = Application.StartupPathEnd SubPrivate Sub AxMMControl2_BackClick(ByVal sender As System.Object, ByVal e As AxMCI.DmciEvents_BackClickEvent) Handles AxMMControl2.BackClickEnd SubPrivate Sub AxMMControl2_Done(ByVal sender As Object, ByVal e As AxMCI.DmciEvents_DoneEvent) Handles AxMMControl2.DoneIf (AxMMControl2.Position = AxMMControl2.Length) Then'如果播放到文件尾,则重新播放mand = "Prev"'回到文件头mand = "Play"'重新播放End IfEnd SubPrivate Sub AxMMControl2_StatusUpdate(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxMMControl2.StatusUpdateProgressBar2.Value = AxMMControl2.Position '用多媒体文件的当前位置更新进度条值End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickOpenFileDialog1.ShowDialog()If (OpenFileDialog1.FileName <> "") Thenmand = "Close"'关闭播放朗诵声音的多媒体设备AxMMControl1.Notify = True'AxMMControl1.FileName = OpenFileDialog1.FileName 'mand = "Open"'打开多媒体设备AxMMControl1.TimeFormat = 4ProgressBar1.Minimum = 0 '设置进度条的最小值ProgressBar1.Maximum = AxMMControl1.Length + 1 '设置进度条的最大值mand = "Play"'播放End IfEnd SubPrivate Sub AxMMControl1_BackClick(ByVal sender As System.Object, ByVal e As AxMCI.DmciEvents_BackClickEvent) Handles AxMMControl1.BackClickEnd SubPrivate Sub AxMMControl1_StatusUpdate(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxMMControl1.StatusUpdateProgressBar1.Value = AxMMControl1.Position '用多媒体文件的当前位置更新进度条值End Sub第十二章一、选择题1.C 2.C 3.A 4.D二、填空题1.元组2.SQL Server .NET Framework3.System.Data.OleDb4.DataColumn5.Fill6.ConnectionString7.BindingContext8.Position1Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickDim SqlStr As StringSqlStr = "Select * from 教师表where 出年日期Between #" + TextBox2.Text + "# And #" + _ TextBox3.Text + "#"'查询字符串mandText = SqlStr '设置命令文本DataSet11.Clear() '清除记录集OleDbDataAdapter1.Fill(DataSet11) '刷新记录集End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim SqlStr As StringSqlStr = "Select * from 教师表where 姓名Like '" + TextBox1.Text + "%'"'查询字符串mandText = SqlStr '设置命令文本DataSet11.Clear() '清除记录集OleDbDataAdapter1.Fill(DataSet11) '刷新记录集End Sub第十三章一、选择题1.A 2.A 3.C 4.C二、填空题1.2.URL3.IIS FrontPage服务器扩展4.LocalHost5.D:\inetpub\wwwroot6.添加Web窗体7.添加Web引用1Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)' 在应用程序启动时激发End SubSub Session_Start(ByVal sender As Object, ByVal e As EventArgs)' 在会话启动时激发End SubSub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) ' 在每个请求开始时激发End SubSub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs) ' 尝试对使用进行身份验证时激发End SubSub Application_Error(ByVal sender As Object, ByVal e As EventArgs)' 在发生错误时激发End SubSub Session_End(ByVal sender As Object, ByVal e As EventArgs)' 在会话结束时激发End SubSub Application_End(ByVal sender As Object, ByVal e As EventArgs)' 在应用程序结束时激发End Sub1(1)' Web 服务示例' HelloWorld() 示例服务返回字符串Hello World。
vb程序设计题库及答案详解
vb程序设计题库及答案详解在编写VB程序设计题库及答案详解时,我们通常会按照以下结构进行排版:1. 题目编号:为每个题目分配一个唯一的编号,方便索引和查找。
2. 题目描述:清晰地描述题目要求,包括输入、输出、功能等。
3. 解题思路:简要说明解题的步骤和方法。
4. 代码实现:提供完整的VB代码实现,包括必要的注释。
5. 运行结果:展示程序运行后的结果,可以是截图或文本描述。
6. 注意事项:列出在编写程序时应注意的问题或常见的错误。
7. 拓展思考:提供一些拓展问题或变体,引导读者进一步思考。
以下是一篇符合标题的正文内容示例:题目编号:001题目描述:编写一个VB程序,实现用户输入两个整数,程序输出这两个整数的和。
解题思路:1. 使用InputBox函数获取用户输入的两个整数。
2. 将输入的字符串转换为整数类型。
3. 计算两个整数的和。
4. 使用MsgBox函数显示结果。
代码实现:```vbDim num1 As IntegerDim num2 As IntegerDim sum As Integernum1 = Val(InputBox("请输入第一个整数:"))num2 = Val(InputBox("请输入第二个整数:"))sum = num1 + num2MsgBox "两个整数的和是:" & sum```运行结果:程序将弹出两个输入框,用户输入两个整数后,将显示一个消息框,展示这两个整数的和。
注意事项:- 确保输入的是整数,否则Val函数可能会失败。
- 输入框中不要包含非法字符。
拓展思考:- 如果用户输入的不是数字,程序应如何处理?- 能否修改程序,使其能够计算两个数的平均值而不是和?请注意,这只是一个示例,实际的题库及答案详解会根据具体题目的不同而有所变化。
(完整word版)VBNET语言习题集(刘炳文书)
第1、2章Visual Basic .NET 程序开发环境一、单选题:1.Visual Basic .NET是一种面向对象的可视化程序设计语言,采取了面向对象、________的编程机制。
(A)事件驱动(B)按过程顺序执行(c)从主程序开始执行(D)按模块顺序执行2.Visual Basic .NET是面向对象的程序设计语言,下面________不是面向对象系统所包含的三要素(A)变量(B)事件(C)属性(D)方法3.在VB .NET集成环境(IDE)创建VB .NET应用程序时,除了工具箱窗口、窗体中的窗口、属性窗口外,必不可少的窗口是________。
(A)类视图(B)解决方案资源管理(C)服务器资源管理器(D)对象浏览器二、填空题:1、.NET平台所基于的两种核心技术是________________和__________________。
2、.NET的独一无二的特征是__________________。
3、由于.NET是在.NET框架结构上进行软件开发,所以在计算机上安装VS .NET 2005的先决条件是,必须安装操作系统的___________服务。
4.VB .NET提供了一种新的数据库访问技术,即________, 通过该技术,能方便地访问多种数据库中的数据。
5.当进入VB .NET集成环境,发现没有显示“工具箱”窗口时,应选择________菜单的________。
选项,使“工具箱”窗口显示。
6.要使新建项目时,在“常规”中自动加入Option Explicit Off语句,与之对应的也可以在________菜单的_______________选项中进行相应的选择。
7、在VB .NET中,解决方案文件的扩展名____________, 项目文件扩展名__________, 窗体文件扩展名_____________。
对于一个己创建的项目,生成的应用程序(扩展名为exe)可执行文件放在项目文件夹的_______________子文件夹下。
VB程序习题集附答案
VB简介1、在以下有关对象属性的叙述中,不正确的是___________。
A、一个对象的属性可分为外观、行为若干类B、不同属性可能具有不同的数据类型C、一个对象的所有属性都可在属性窗口的列表中进行设置D、属性窗口中的属性列表既可按字母排序也可按类别排序2、Visual Basic中最基本的对象是___________,它是应用程序的基石,也是其他控件的容器。
A、文本框B、命令按钮C、窗体D、标签3、有程序代码“Text1.Text="Visual Basic"”,其中的Text1、Text和“Visual Basic”分别代表___________。
A、对象、值、属性B、对象、方法、属性C、对象、属性、值D、属性、对象、值4、用窗体的___________属性来设置窗体的标题。
A、CaptionB、StyleC、TextD、Name5、窗体上有一个文本框控件Text1,假设已存在三个整型变量a、b、c,且变量a的值为5,变量b的值为7,变量c的值为12。
以下的___________语句可以使文本框内显示的内容为:5+7=12。
A、Text1.Text = a + b + cB、Text1.Text = "a+b=c"C、Text1 = a & "+" & b & "=" & cD、Text1 = "a" & "+" & "b" & "=" & "c"6、如果在窗体上有命令按钮OK,在代码编辑窗口有与之对应的Cmd_Click()事件,则命令按钮的名称属性和Caption属性分别为_________。
A、OK、CmdB、Cmd、OKC、CmdOK、OKD、OK、CmdOK7、窗体Form1的名称属性是frm,它的Load事件过程名为___________。
VBnet习题集
第一章第一章 环境和程序设计初步环境和程序设计初步一.选择题选择题1.在Visual 的集成开发的环境中,下面不属于该环境编程语言的是(C )。
A.VBB.C++C. PascalD. J#2.在集成开发环境中有两类窗口,浮动窗口和固定窗口,下面不属于浮动窗口的是(D )。
A.工具箱窗口工具箱窗口B.属性窗口属性窗口C.立即窗口立即窗口D.窗体窗口窗体窗口3.在 中,在窗体上显示控件的文本,用(中,在窗体上显示控件的文本,用( A )属性设置。
)属性设置。
A. TextB. NameC. CaptionD. Image 4.不论何种控件,共同具有的是什么属性( D )。
A. Text B. NameC .ForeColorD .Text 5.对于窗体,可改变窗体的边框性质的属性是(B )。
A. MaxButtonB. FormBorderStyleC. NameD. Left 6.若要使标签控件显示时不要覆盖窗体的背景图案,要对(A )属性进行设置。
)属性进行设置。
A .BackColor B. BorderStyle C .ForeColorD.BackStyle 7.若要使命令按钮不可操作,要对(A )属性进行设置。
)属性进行设置。
A. EnabledB.VisibleC. BackColorD. Text 8.要使文本框中的文字不能被修改,应对(D )属性进行设置。
)属性进行设置。
A. LockedB. VisibleC. EnabledD. ReadOnly 9.要使当前Form1 窗体的标题栏显示“欢迎使用 ”,以下(B )语句是正确的。
)语句是正确的。
A. Form1.Text=“欢迎使用V ”B. Me. Text=“欢迎使用 ”C. =“欢迎使用 ”D. Me. Name=“欢迎使用 ”10.当运行程序时,系统自动执行启动窗体的(A )事件过程。
)事件过程。
A. LoadB. ClickC. UnLoadD. GotFocus 11.当文本框的ScrollBars 属性设置了非None 值,却没有效果,原因是(B )。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
本文由余亚洪贡献doc文档可能在WAP端浏览体验不佳。
建议您优先选择TXT,或下载源文件到本机查看。
第 1、2 章 Visual Basic .NET 程序开发环境、一、单选题:单选题:1、A2、A3、B二、填空题:填空题:,Internet 协议。
1、XML(可扩展标记语言)、这里的 Internet 协议主要是指:HTTP 和 SOAP-简单对象访问协议。
2、可以提供多语言支持。
、 3、IIS(Internet Information Service)。
、 4、ADO .NET。
(本课程不要求)、 5、视图,工具箱。
、6、项目,“属性…”命令项,“生成”选项。
7、sln, vbproj, vb, bin。
三、编程题:略第 6 章常用 Windows 窗体和控件一、单选题1-5:CBCAD 6-10:BCABD 11-15:ADCDB 16-20:CDDCB 21-25:ACCDD 26-30:AABC 31-35:DDDDA 36-38:DCB二、填空题1、TextBox1.ForeColor=Color.Red;2、对象的性质,来描述和反映对象特征的参数;3、对象的动作和行为;4、对窗体的 FontName 属性设置;5、MultiLine;6、BackgroupImage;7、工具,对象属性,启动对象, Dim firstForm As New form1 firstForm.Show() 8、SelectAll 属性或 SelectText 属性,程序运行 9、Locked 10、Load, TabIndex, 0, Button1.Focus() 11、FormBorderStyle=FixSingle 12、Form1.Loction=new Point(left, top) 写在 Load 事件中。
13、CheckAlign=MiddleRight 14、ImageAlign 15、Image16、Enabled *17、0 *18、ListBox1.Items(ListBox1.Items.Count - 1) 19、Items 20、Items.Clear 21、当 DropDownStyle 属性为 DropDownList 值。
22、Scroll 23、LargeChange 24、滚动条内滑块位置 25、15000 26、Now 27、TabPages 28、MouseButtons.Right 29、$ 30、Form1_Load, MyBaseLoad, cboComputer.Text, TxtComputer.Text, RideoButton1.Checked 31、i+1, ListBox1.Items.RemoveAt(j) 32、ComboBox1.Text = ComboBox1.Items(i), Not flag 或flag=false,ComboBox1.Items.Add(ComboBox1.Text) 33、if FontDialog1.ShowDialog=DialogResualt.OK then TextBox1.Font=FontDialog1.Font End if if ColorDialog1.ShowDialog=DialogResualt.OK then TextBox1.ForeColor=ColorDialog1.Font End if 34、Label1.Font=New System.Drawing.Font(“黑体”,24,FontStyle.Italic) 三、编程题 1.设计一段程序在程序运行后,单击命令按钮后,文本框中显示出字符”欢迎来到 VB .NET 多彩世界!”, 并把文本框的背景和文字的颜色变成黄色和蓝色,字体为“楷书”,字型及字号变成“粗体”和 35 号字。
1、界面设计和属性对象名 Form1 Button1 TextBox1 程序:程序:属性 Text Text Text属性值“第 5 章上机题 1”“运行”“”2、在窗体上添加一个标签框,要求在程序运行时,单击窗体时改变标签的背景色(绿、色)、前景色(粉红)和标题,双击时还原。
提示:可以设置一个变量(将变量设为模块级)事先把原来窗体的背景颜色属性值,事先把原来窗体的背景颜色属性提示:可以设置一个变量(将变量设为模块级)事先把原来窗体的背景颜色属性值,赋给出这个变量,当执行另一个操作时,再将这个变量值赋回给窗体背景属性。
赋给出这个变量,当执行另一个操作时,再将这个变量值赋回给窗体背景属性。
程序:程序:,要求在窗体调整大小时,保持文框和窗体的比例不 3、在窗体上绘制一个文本框,变,请编写事件代码。
注意:在 VB .NET 2005 版里,有了 Anchor 和 Dock 属性后,上述代码就显的不重要了。
4、窗体上有 3 个按顺序建立的文本框 Text1、 Text2 和 Text3, 有哪些方法可在窗体加载时使 Text3 首先获得焦点。
方法一、用 TabIndex 属性实现方法二:用 Focus 方法实现TextBox3 得到焦点实现: 5、在 VB .NET 环境下,创建 1 个名为.Pro1 的项目,当窗体第一次显示时,窗体大小为(200,200), 窗体边框为默认边框,窗体不透明;当鼠标在窗体上单击时,窗体边框变为固定大小的三维立体边框,窗体大小变为原来大小 2 倍且窗体变为半透明;当鼠标指针离开窗体时,窗体恢复为第一次显示时的状态。
程序: 6、再上题所建的项目中,再添加一个窗体,在程序运行时改变窗体的背景图案,并且两个窗体之间能够交替隐藏和显示。
程序: *7、创建两个窗体 Form1 和 Form2,在 Form1 上有命令按钮Button1”Form2.Show“,单击该按钮和单击 Form1 的结果相同,都是隐藏 Form1 显示 Form2; 在 Form2 上也有一个命令按钮 Button1”Form1.Show“,单击该按钮实现隐藏 Form2 显示Form1。
调用过程的方法,使用同一个过程实现在 Form1 上单击按钮、单击窗体以及在Form2 上单击按钮的功能。
程序:程序:多个窗体之间互相调用在 VB 6.0 中,多个窗体之间可以很方便地互相调用,如:在 Form1 中,只需要用一条“Form2.Show”语句就能显示窗体 Form2。
然而在 中窗体处理机制发生了很大的变化:在访问窗体之前,你必须进行窗体实例化;如果在项目中有多处代码访问同一窗体,则必须把它的同一实例指针传递给这些代码,否则新创建的窗体实例就不再是原先的窗体了。
下面的代码实现窗体 Form1 和 Form2 之间互相调用,Form1 为主窗体。
Form1 上的按钮 BtnShowFrm2 的标题为“显示 Form2”,Form2 上的按钮 BtnShowFrm1 的标题为“显示Form1”。
中的代码:(1)Form1 中的代码:Public Class Form1 Inherits System.Windows.Forms.Form ‘创建 Form2 的一个新的实例 Dim Frm2 As New Form2() Public Function Instance2(ByVal frm As Form2) Frm2 = frm End Function Private Sub BtnShowFrm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnShowFrm2.Click ’以下语句保证在 Form2 以及其他窗体中访问 Form1 时,都将得到 Form1 的同一个窗体实例。
Frm2.Instance(Me) Frm2.Show() Me.Hide() End Sub End Class 中的代码:(2)Form2 中的代码:Public Class Form2 Inherits System.Windows.Forms.Form Dim frm1 As Form1‘借助一个新增的 Instance 属性来生成窗体 frm1 的实例Public Function Instance(ByVal frm As Form1) frm1 = frm End Function Private Sub BtnShowFrm1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnShowFrm1.Click Me.Hide() frm1.Show() End Sub Private Sub Form2_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed’如果 Form2 被关闭,则设置 Form1 的按钮 BtnShowFrm2 不可用。
frm1.BtnShowFrm2.Enabled = False frm1.Show() End Sub End Class 第 3 章简单 Visual Basic .NET 程序设计编程题:编程题: 1、见 P74 页 3.7 题程序: 2、见 P74 页 3.8 题、程序:第4章编程基础(顺序结构部份)章编程基础(顺序结构部份)一、单选题1、合法常量有: (1)Single (3)Single (4)Double (7)String (9)Date (10) Double (12)八进制的整型 (13) 八进制的整型 (14) 十六进制的整型 (15)Boolean (18)Single 2、合法变量: (1) (2) (6) (9) (10) (11) 3、(1)abs(x+y)+z^5 (2)(1+x*y)^6(3)(10*x+sqr(3*y))/(x*y) (4)sin(45*3.1415926/180)+(exp(10)+log(10))/sqr(x+y+1) 4、(1)chr$(67) and chr$(76) (2)int(rnd*101)+100 (3)int(x/5) =x/5 or int(x/7)=x/7 (4)略 (5)int(x*100+0.5)/100 (6)略 (7)略 (8)x>=10 and x<20 (9)x<z or y<z (10)x>z and y>z 5、写出下列表达式的值: (1)188 (2)200100 (3)68.56 (4)876543 (5) 6 6、答:单精度类型。