VB程序设计教程课后参考答案
- 格式:pdf
- 大小:1.14 MB
- 文档页数:16
Dim n As Integern=Text1.TextIF(n Mod 4 =0 And n mod 100< >0 or n mod 400 = 0)Then Text2.text =”闰年”ElseText2.text=”非闰年”End IF求和求积Dim i As integerOpen App.path&”\jsdata.txt”For input As #1For i =1 to 15Input #1,arr(i)Next iIf op1.value=ture thenT1.text=Aaa()End ifIf op2.value=ture thenT1.text=Bbb()End ifClose #1写入文件****Dim i As Integer, j As Integer, n As IntegerOpen app.path &”\zfwj.txt”for output As #1n=val(text1.text)for I =1 to nfor j=1 to iprint #1,”*”;next jprint #1next I close#1计算结果dim n As Integer, I As Integer, s1 As integer,s2 As long n=val(text1.textfor I =1 to ns1=s1+is2=s2+s1next itext2.text=s2求值dim n1 as integer, n2 as integer, n3 as integer,t as integer n1= val(text1.text)n2=val(text2.text)n3=val(text3.text)if n1<n2 then t=n1:n1=n2:n2=tif n2<n3 then t=n2:2=n3:3=tif n1<n2 then t =n1:1=n2:2=ttext4.text=n1text5.text=n3建立文件显示文件Dim num as string,name as srting, I as integerOpen App.path&”\xhxm.txt”for output As #1For I = 1 to 3num=inputbox(“请输入学号:“)name = inputbox(“请输入姓名:“)write #1,num,namenext iclose #1End sub Private sub command2_click()Dim s as string, I as integerOpen app.path &\xhxm.txt” for input as # 1Do While Not EoF(1)Line input # 1,sText1.text= text1.text& s & vbCrLfLoopClose #1第三卷求和输入N值Dim n As integer, I as integer, sum as integerN= val(text1.text)For I = 1 to nIf I mod 3 =0 then sum = sum+ iNext iText2.text=sum输入正整数NDim m As integer, n as integerPrivate sub commad1_click(0Dim c as doubleN=text1.textM=text2.textIf n<=m thenC=fact(m)/(fact(n)* fact(m-n))Text3.text=cElseMsgbox”输入的n必须小于等于m!请重新输入“Text1.text=””Text2.text=””Text1.setfocusEnd ifEnd sub读入数据统计英文字母Dim s as stringOpen app.path&”\yy.txt”for input as #1Do while not EOF(1)Line input #1,sText1.text=text1.text &s &vbCrLfLoopClose #1End subPrivate sub command2_click()Dim n as integer, I as integer, s As integer, c as stringN= Len(text1.text)For I = 1 to nC= mid(text1.text,I,1)If c >=”a”and c <=”z” or c 》=“a” and c <=”z” then s =s+1 Next iLabel1.caption= “共“& s &”个英文字母”End sub第四卷转换十进制Dim n as integer,b as stringN=text1.textB=zh(n)Text2.text=b读取文件加密Dim s1 as stringPrivate sub command1_click()Open app.path &”\jmwb.txt”for input as #1Input #1,s1Text1.text=s1End subPrivate sub command2_click()Dim n As integer, I as integer dim s2 as string, j As stringN=Len(s1)For I =1 to nJ=mid(s1,I,1)J=chr(asc(j)+5)S2=s2&jNext iText2.text=s2生成数组降序排列Option base 1Dim n AS integer,x(15) as integerPrivate Sub command1_Click(0Dim s1 as stringFor N= 1 to 15X(N)=int(91 * Rnd +10)S1=s1 &STR(x(N))Next NText1.text =s1End subPrivate sub command2_click()Dim s2 as stringDim I as integer, j AS integer t as integerFor I =1 to 15For j 1 to 15For j=I +1 to 15If x (i)<x(j) thenT=x(i)X(i)=x(j)X(j)=tEnd ifNext jS2=s2& Str(x(i))Next IText2.text =s2End sub第五卷判断字符还是字母Dim s as stringCall Getchar(s)Text1.text=sIf Asc(s)>= Asc(“A”) and asc (s)<=asc(“z”) or asc (s)>=Asc(“a”) And asc (s)<=asc(“z”) then Label1.caption=”是字母字符“ElseIf asc(s)>=asc(”0”) and asc(s)<= asc(“s)<=asc(“9”) thenLabel1.caption=”是数字字符“ElseLabel1.caption=”是其他字符”End ifEnd sub生成三个随机数Dim n1 as integer, n2 as integern1=val(text1.text)n2=val(text2.text)label1.caption=int((n2-n1+1)*Rnd +n1)label2.caption=int((n2-n1+1)*Rnd+n1)label3.caption=int((n2-n1+1)*Rnd+n1)end sub转换大写小写Dim a as stringPrivate sub command1_click()Text1.text=UCase(a)End subPrivate sub command1_click()Text1.text=LCase(a)End subPrivate sub command3_click()Text1.text=aEnd subPrivate sub text1_keypress(keyascii as integer)If not((keyascii>=65 and keyascii<=90)or (keyascii>= 97 And keyascii<=122)) then BeepKeyascii =0End Ifa=Text1.textend sub。
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程序设计的相关知识,成为优秀的程序设计师。
VisualBasic程序设计教程第版课后部分编程题参考答案(一)Visual Basic 程序设计教程是程序员必备的一本教材。
而其第四版中也包含了大量课后编程题,能够帮助读者深入理解 Visual Basic 程序设计的核心内容。
本文就来为大家介绍一下这部分编程题的参考答案。
一、数据类型和运算符1. 将两个整数相加Dim num1, num2, result As Integernum1 = 10num2 = 20result = num1 + num2MsgBox ("The result of adding " & num1 & " and " & num2 & " is " & result & ".")2. 将两个小数相减Dim num1, num2, result As Doublenum1 = 2.5num2 = 1.2result = num1 - num2MsgBox ("The result of subtracting " & num2 & " from " & num1 & " is " & result & ".")3. 将两个字符拼接在一起Dim str1, str2, result As Stringstr1 = "Hello"str2 = "World"result = Str1 + Str2MsgBox ("The result of concatenating " & str1 & " and " & str2 & " is " & result & ".")二、程序结构和函数1. 将两个整数相加并返回结果Public Function Add(ByVal num1 As Integer, ByVal num2 As Integer) As IntegerDim result As Integerresult = num1 + num2Return resultEnd Function2. 获取当前日期和时间Dim currentDateTime As StringcurrentDateTime = Now()MsgBox ("The current date and time is " & currentDateTime & ".")3. 显示一个消息框并返回用户的选择Dim userInput As IntegeruserInput = MsgBox("This is a prompt. Would you like tocontinue?", vbYesNoCancel, "Message Box Test")MsgBox ("Your choice was " & userInput & ".")三、数组和结构1. 将一个整数数组按照升序排列Dim numArray() As IntegernumArray = {5, 10, 2, 8, 1}Array.Sort(numArray)MsgBox ("The sorted array is " & Join(numArray, ", ") & ".")2. 创建一个结构体表示一个人,包含姓名、年龄和性别字段Public Structure PersonPublic Name As StringPublic Age As IntegerPublic Gender As StringEnd Structure3. 创建一个数组表示一个班级的学生,使用 Person 结构体表示每个学生的信息Dim students(2) As Personstudents(0).Name = "Tom"students(0).Age = 16students(0).Gender = "Male"students(1).Name = "Jane"students(1).Age = 15students(1).Gender = "Female"students(2).Name = "Bob"students(2).Age = 17students(2).Gender = "Male"四、文件和数据库1. 读取一个文本文件中的内容并显示Dim filePath As String ="C:\Users\UserName\Documents\MyFile.txt"Dim fileText As StringfileText = File.ReadAllText(filePath)MsgBox ("The contents of the file are " & fileText & ".")2. 将一个字符串写入到一个新建的文本文件中Dim filePath As String ="C:\Users\UserName\Documents\NewFile.txt"Dim fileContent As StringfileContent = "This is the content of the new file."File.WriteAllText(filePath, fileContent)MsgBox ("The file was created and the following content was written to it: " & fileContent & ".")3. 从一个 SQL 数据库中查询某个表格的内容Dim connectionString As String = "DataSource=myServerName;Initial Catalog=myDataBase;UserId=myUsername;Password=myPassword;"Dim query As String = "SELECT * FROM myTable"Dim dataTable As New DataTable()Using connection As New SqlConnection(connectionString)connection.Open()Using command As New SqlCommand(query, connection)Using adapter As New SqlDataAdapter(command)adapter.Fill(dataTable)End UsingEnd UsingEnd UsingMsgBox ("The following records were retrieved from the database: " & vbNewLine & DataTableToString(dataTable))这些编程题的参考答案可以帮助读者理解 Visual Basic 程序设计的一些基本概念和技术,希望读者能够结合自己的实际情况进行学习和练习,不断提高自己的编程水平。
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程序设计教程》(第4版)习题解答单元一巩固与提高答案一、选择题1. Visual Basic 6.0分为3种版本,不属于这3种版本的是A)学习版B)专业版C)企业版D)业余版【答】D。
2. 下列方法中不能退出Visual Basic的是A)按Alt+Q组合键B)按下Alt+F组合键,然后按Esc键C)按F10键,然后按F键,再按X键D)打开“文件”菜单→“退出”命令【答】B。
3. Visual Basic集成的主窗口中不包括A)属性窗口B)标题栏C)菜单栏D)工具栏【答】A。
4. 下列操作可以打开立即窗口的是A)Ctrl+D B)Ctrl+F C)Ctrl+G D)Ctrl+E【答】C。
二、填空题1. 与传统的程序设计语言相比,Visual Basic最突出的特点是____。
【答】事件驱动编程机制。
2. 如果不使用鼠标,用键盘打开菜单和执行菜单命令,第一步应按____键。
【答】功能键F10或Alt键。
3. 建立一个新的标准模块,应该选择____菜单下的“添加模块”命令。
【答】“工程”菜单。
三、思考题1. 简述Visual Basic的特点。
【答】与一般的程序设计语言相比,VB具有以下特点:(1) 可视化的设计平台;(2) 面向对象的设计方法;(3) 事件驱动的编程机制;(4) 结构化的设计语言;(5) 充分利用Windows资源;(6) 开放的数据库功能与网络支持。
2. 简述Visual Basic集成开发环境的组成。
【答】VB 6.0集成开发环境除了具有标准Windows环境的标题栏、菜单栏、工具栏外,还有工具箱、属性窗口、工程管理器窗口、窗体设计器、立即窗口、窗体布局窗口等有用的开发工具。
(1) 标题栏和菜单栏:标题栏中显示的有窗体控制菜单图标、当前激活的工程名称、当前工作模式以及最小化、最大化∕还原、关闭按钮。
菜单栏中显示了“文件”、“编辑”、“视图”、“工程”、“格式”等菜单项,其中包含了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课后习题答案第一章习题参考答案一、填空题1、对象事件驱动2、编译运行模式解释运行模式二、简答题1、简述VB的特点。
答:①可视化的程序设计方法②面向对象的程序设计思想③事件驱动的编程机制④结构化的程序设计语言⑤高度的可扩充性⑥强大的数据库访问能力⑦支持动态数据交换⑧支持对象链接与嵌入2、简述VB的安装过程。
答:①向光驱中放入VB安装光盘;②计算机将运行自动安装程序,若没有,执行VB 目录下的Setup.exe;③根据提示逐一回答问题,并点击“下一步”;④点击“完成”;2、如何启动VB。
答:三种方法:①单击“开始”按钮,选择“程序”菜单下的“Microsoft Visual Basic 6.0 中文版”菜单项并单击;②双击桌面上的VB6.0快捷图标;③在“开始”菜单的运行对话框中输入命令来启动VB;第二章习题参考答案一、选择题:1-10、 DCACD BCBBC11-20、BADCA BBAAB21-29、AACBB CDDC二、填空题1.窗体、控件2.属性值3.属性窗口设置、代码窗口设置4.事件过程5.对象名、下划线、事件名6. Form_Click第三章习题参考答案一、选择题1、B2、C3、A4、B5、A6、C7、C二、填空题1、 11字符型、字节型、整型、长整型、单精度型、双精度型、货币型、逻辑型、日期型、对象型、变体型。
String、Byte、Integer、Long、Single、Double、Currency、Boolean、Date、Object、Variant2、双引号(英文)、#3、 ASCII、1、24、 public、通用、Dim、Static、Private、Static5、 &、+、+6、 Now()、Time、日期型三、解答题1、(3)2、(1 )3、(1)常量(关键字)(2)字符型常量(3)逻辑型常量(4)变量(5)字符串常量(6)变量(7)字符串常量(8)变量(9)日期型常量(题目应是#11/16/1999#)(10)数值型常量(单精度)4、315、(1)(1+y/x)/(1-y/x) (2)x^3+3*x*y/(2-y)(3)sqr(abs(a*b-c^3)) (4)sqr(s*(s-a)*(s-b)*(s-c))6、7、(1)13 (2)17(3)#1999-11-12# (4)zxy123ABC(3)5.25 (4)27)16 (8)“-459.65” (9)510、(4)11、(2)12、(4)第四章习题参考答案一、选择题:1—7: DAABBCD二、填空题1. 500.00%2.将字号扩大为原来的二倍3. B三、编程题(略)1.文本框、标签和命令按钮的名称分别为text1、label1、command1Private Sub Command1_Click()Label1.caption=text1.textCommand1.caption=text1.textEnd Sub2.单价、数量、折扣和应付款对应的文本框的名称分别为:text1、text2、text3和text4,计算和清除命令按钮的名称分别为:command1和command2。
A.1Private Sub Command1_Click()Label3 = Text1End SubA.2Private Sub Form_Load()Timer1.Interval = 0End SubPrivate Sub Command1_Click() '自动Timer1.Interval = 200End SubPrivate Sub Command2_Click() '手动Timer1.Interval = 0Call MyMoveEnd SubPrivate Sub Timer1_Timer()Call MyMoveEnd SubSub MyMove()Label1.Move Label1.Left - 50If Label1.Left < 0 Then Label1.Left = Form1.Width End SubA.3Private Sub Form_Click()Text1 = Val(Text1) + 1End SubPrivate Sub Form_Load()Text1 = 0End SubA.4Private Sub Form_Click()Caption = "单击窗体,改变图片"Picture = LoadPicture(App.Path + "\n_015.bmp")Print "欢迎使用VB"End SubPrivate Sub Form_DblClick()ClsCaption = "双击窗体,卸去图片"Picture = LoadPicture("") 'End SubPrivate Sub Form_Load()Caption = "装入窗体"Picture = LoadPicture(App.Path + "\n_016.bmp")Print "装入图"End SubPrivate Sub Form_Resize() ' 该事件的作用窗体始终与图一样大'Caption = "窗体大小不变"'Form1.Width = 260 * 16 ' 260 是Tongji-2.bmp 图的宽度,象素单位'Form1.Height = 260 * 16 + 200 ' 260 是图的高度,象素单位,200 是窗体的标题栏高度End SubA.5Sub Command1_Click()Text1.FontName = "隶书"Text1.FontSize = 25End SubSub Command2_Click()Text2.Text = Text1.SelTextText2.FontName = Text1.FontNameText2.FontSize = Text1.FontSizeEnd SubB.1Private Sub Command1_Click()Text2 = Format(5 / 9 * (Val(Text1) - 32), "0.00")End SubPrivate Sub Command2_Click()Text1 = Format(9 / 5 * Val(Text2) + 32, "0.00")End Sub或Private Sub Command1_Click()Dim f!, c! ' 声明两个变量f = Val(Text1)c = 5 / 9 * (f - 32)Text2 = Format(c, "0.00") ' 保留两位小数End SubPrivate Sub Command2_Click()Dim ff!, cc! ' 声明两个变量cc = Val(Text2)ff = 9 / 5 * cc + 32Text1 = Format(ff, "0.00") ' 保留两位小数End SubB.2Label2 = Format(Val(Text1) * Val(Text1) * 3.14, "0.00") End SubPrivate Sub Command2_Click()Label3 = Format(Val(Text1) * 3.14 * 2, "0.00")End SubPrivate Sub Text1_LostFocus()If Not IsNumeric(Text1.Text) ThenMsgBox "输入有非数字字符,请重新输入", , "警告"Text1.Text = ""Text1.SetFocusEnd IfEnd Sub或Private Sub Command1_Click()Label2 = Format(Val(Text1) * Val(Text1) * 3.14, "0.00") End SubPrivate Sub Command2_Click()Label3 = Format(Val(Text1) * 3.14 * 2, "0.00")End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii = 13 ThenIf Not IsNumeric(Text1.Text) ThenText1.Text = ""End IfEnd IfEnd SubB.3Private Sub Command1_Click()n = Int(Log(2) / Log(1.008) + 1)Label1 = n & "年后人数超过26 亿"End SubB.4Private Sub Command1_Click()Dim x, dx, cdx = Text1.Textdx = UCase(x)cd = Len(x)Print "大写字母为:"; dxPrint "字符串长度为:"; cdEnd SubB.5Text1 = Int(Rnd * 900 + 100)End SubPrivate Sub Command2_Click()Dim x%, x1%, x2%, x3%x = Val(Text1)x1 = x Mod 10 ' 分离出的个位数x2 = (x Mod 100) \ 10 ' 分离出的十位数x3 = x \ 100 ' 分离出的百位数Label1 = x1 * 100 + x2 * 10 + x3End SubB.6Private Sub Form_Click()Label1 = Left(Text1, 11)Label2 = Mid(Text1, 12, 6)Label3 = Right(Text1, 5)End SubB.7Private Sub Command1_Click()PrintFor i = 1 To 5Print Tab(15 - i * 2); String(2 * i - 1, "★"); Spc(18 - 4 * (i - 1)); String(2 * i - 1, "★")Next iEnd SubPrivate Sub Command2_Click()ClsEnd Sub进一步要求:Private Sub Command1_Click()PrintFor i = 1 To 5Print Tab(15 - i * 2); String(2 * i - 1, "★"); String(10 - (2 * i - 1), "☆"); String(2 * i - 1, "★") Next iEnd SubPrivate Sub Command2_Click()ClsEnd SubB.8Private Sub Form_Click()x = Val(InputBox("输入一正实数", "计算", 0))pf = Format(x * x, "0.000")pfg = Format(Sqr(x), "0.000")lf = Format(x * x * x, "0.000")lfg = Format(x ^ (1 / 3), "0.000")Print "平方为:"; pf; Space(5); "平方根为:"; pfg; Space(5); "立方为:"; lf; Space(5); "立方根为:"; lfgEnd SubC.1Private Sub Form_Click()Dim x!, y!x = Val(InputBox("输入x 的值"))If x < 1000 Theny = xElseIf x < 2000 Theny = 0.9 * xElseIf x < 3000 Theny = 0.8 * xElsey = 0.7 * xEnd IfPrint yEnd SubC.2Private Sub Form_Click()Dim x!, y!x = Val(InputBox("输入上网时间"))If x < 10 Theny = 30ElseIf x < 50 Theny = 30 + 2.5 * (x - 10)Elsey = 30 + 2.5 * 40 + 2 * (x - 50)End IfIf y > 150 Theny = 150End IfPrint yEnd SubC.3Private Sub Command1_Click()Dim x!, y!, z!x = InputBox("input x")y = InputBox("input y")z = InputBox("input z")Print " x y z"Print " 排序前"; x; " "; y; " "; z Ifx < y Then t = x: x = y: y = tIf x < z Then t = x: x = z: z = tIf y < z Then t = y: y = z: z = tPrint " 排序后" & x & " " & y & " " & z End SubPrivate Sub Command2_Click()Dim x!, y!, z!x = InputBox("input x")y = InputBox("input y")z = InputBox("input z")Print " x y z"Print " 排序前"; x; " "; y; " "; z Ifx < y Then t = x: x = y: y = tIf y < z Thent = y: y = z: z = tIf x < y Thent = x: x = y: y = tEnd IfEnd IfPrint " 排序后" & x & " " & y & " " & z End SubC.4Dim a(3) As IntegerPrivate Sub Command1_Click()Picture1.ClsFor i = 0 To 2a(i) = Int(Rnd * 100 + 200)Picture1.Print a(i)Next iEnd SubPrivate Sub Command2_Click()Picture2.ClsDim z As IntegerFor i = 0 To 1If a(i) > a(i + 1) Thenz = a(i + 1)a(i + 1) = a(i)a(i) = zEnd IfNext iPicture2.Print a(0)Picture2.Print a(1)Picture2.Print a(2)End SubC.5Private Sub Text2_LostFocus()Dim m%, n%, y%m = Val(Text1)n = Val(Text2)If n Mod 2 <> 0 ThenMsgBox ("脚数必定为偶数")Text2 = ""Text2.SetFocusElsey = n / 2 - mIf y < 0 ThenMsgBox ("脚数必须≥2 倍的头数,请重新输入")Text2 = ""Text2.SetFocusElsex = n / 2 - mLabel2 = yLabel3 = m - yEnd IfEnd IfEnd SubC.6Private Sub Command1_Click()Dim a!, b!, c!, x1!, x2!, de!a = Text1b = Text2c = Text3de = b * b - 4 * a * ct = 2 * aIf de = 0 ThenText4 = Format(-b / t, "0.00")Text5 = Format(-b / t, "0.00")ElseIf de > 0 ThenText4 = Format((-b + Sqr(de)) / t, "0.00")Text5 = Format((-b - Sqr(de)) / t, "0.00")ElseText4 = Format(-b / t, "0.00") & "+" & Format(Sqr(Abs(de)) / t, "0.00") & "i" Text5 = Format(-b / t, "0.00") & "-" & Format(Sqr(Abs(de)) / t, "0.00") & "i" End IfEnd SubPrivate Sub Command2_Click()Text1 = ""Text2 = ""Text3 = ""Text4 = ""Text5 = ""End SubC.7Private Sub Text3_LostFocus()Select Case Trim(Text3)Case "+"Text4 = Val(Text1) + Val(Text2)Case "-"Text4 = Val(Text1) - Val(Text2)Case "*"Text4 = Val(Text1) * Val(Text2)Case "/"If Val(Text2) = 0 ThenMsgBox "分母为零,重新输入"Text2 = ""Text2.SetFocusElseText4 = Val(Text1) / Val(Text2)End IfEnd SelectEnd SubC.8Private Sub Text1_LostFocus()Select Case Trim(Text1)Case 1Text2 = "Monday"Case 2Text2 = "Tuesday"Case 3Text2 = "Wednesday"Case 4Text2 = "Thursday"Case 5Text2 = "Friday"Case 6Text2 = "Saturday"Case 7Text2 = "Sunday"Case Is > 7, Is < 1MsgBox "数字为1~7,重新输入"Text1 = ""Text1.SetFocusEnd SelectEnd Sub或者Private Sub Text1_LostFocus()If Text1 > 7 Or Text1 < 1 ThenMsgBox "数字为1~7,重新输入"Text1 = ""Text1.SetFocusElseText2 = Choose(Text1, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")End IfEnd SubD.1Private Sub Form_Click()For i = 1 To 9Print Tab(10 - i); String(2 * i - 1, Trim(Str(i)))Next iEnd SubD.2Private Sub Form_Click()For i = 1 To 10 Step 1Print Tab(i); String((20 - 2 * i), Chr(64 + i))Next iEnd SubD.3Private Sub Command1_Click()Dim s!, t!, i&s = 1t = 1For i = 1 To 100000t = t + is = s + 1 / tIf 1 / t < 0.00001 Then Exit ForNext iPrint "For 结构"; s, i; "项"End SubD.4Private Sub Command1_Click()Dim n&, pi#, i&n = InputBox("输入n 值")pi = 2For i = 1 To npi = pi * (2 * i) / (2 * i - 1) * (2 * i) / (2 * i + 1) Next iPrint "当n=" & n & "时,pi="; piEnd SubD.5Private Sub Form_Click()Dim s!, t!, i!, a%, n%a = Int(Rnd * 9 + 1)n = Int(Rnd * 6 + 5)t = 0: s = 0Print "a="; a, "n="; nFor i = 1 To nt = t * 10 + as = s + tPrint t;Next iPrintPrint "s="; sEnd SubD.6Private Sub Command1_Click()Dim s As Integers = 0For i = 1 To 9For j = 0 To 9For k = 0 To 9s = i * 100 + j * 10 + kIf s = i ^ 3 + j ^ 3 + k ^ 3 ThenPrint sEnd IfNext kNext jNext iEnd SubPrivate Sub Command3_Click()formd6.Hidemain.ShowEnd SubD.7Private Sub Command1_Click()Dim a!, x0!, x1!a = 27x0 = 2i = 0Doi = i + 1x1 = 2 * x0 / 3 + a / (3 * x0 * x0)If Abs(x1 - x0) < 0.00001 Then Exit Dox0 = x1LoopPrint x1, iEnd SubD.8Private Sub Command1_Click()s = 0x0 = 0.01For i = 1 To 30s = s + x0x0 = x0 * 2Next iPrint sEnd SubD.9Private Sub Command4_Click()Picture1.ClsPicture1.Print "x 课安排在"; "y 课安排在"; "z 课安排在"Picture1.Print ""For z = 5 To 6For x = 1 To z - 2For Y = x + 1 To z - 1X1 = Choose(Weekday(x), "周一", "周二", "周三", "周四", "周五", "周六", "周日")Y1 = Choose(Weekday(Y), "周一", "周二", "周三", "周四", "周五", "周六", "周日") z1 = Choose(Weekday(z), "周一", "周二", "周三", "周四", "周五", "周六", "周日") Picture1.Print " "; X1; " "; Y1; " "; z1Next YNext xNext zEnd SubE.1Private Sub Form_Click()Dim a(1 To 10) As IntegerFor i = 1 To 10a(i) = Int(Rnd * 71 + 30)Print a(i); " ";Next iMax = a(1)Min = a(1)Avg = a(1)For i = 2 To 10If a(i) > Max Then Max = a(i)If a(i) < Min Then Min = a(i)Avg = Avg + a(i)Next iAvg = Avg / 10PrintPrint "Max="; Max; " Min="; Min; " Avg="; AvgEnd SubE.2Private Sub Form_Click()Dim aa = Array(56, 78, 98, 88, 76, 78)For i = 0 To 5Print String(a(i) \ 5, "◆"); a(i)PrintNext iEnd SubE.3Dim a%(19)Private Sub Command1_Click()Picture1.ClsFor i = 0 To 19a(i) = Int(Rnd * 101)Picture1.Print a(i); " ";If (i + 1) Mod 4 = 0 Then Picture1.PrintNext iEnd SubPrivate Sub Command2_Click()Picture2.ClsDim s(5 To 9)For i = 0 To 19k = a(i) \ 10Select Case kCase 0 To 5s(5) = s(5) + 1Case 9 To 10 '90~100 分的人数s(9) = s(9) + 1Case 6 To 8 ' 存放其他三个分数段的下标有规律,根据K 获得s(k) = s(k) + 1End SelectNext iFor i = 5 To 9If s(i) <> 0 Then Picture2.Print "s("; i; ")的人数有"; Format(s(i), "0"); "个" Next iEnd SubE.4Private Sub Command1_Click()Picture1.ClsDim d%(1 To 10)For i3 = 1 To 10Randomized(i3) = Int(Rnd * 91 + 10)Next i3For i = 1 To 10For j = 1 To 10 - iIf d(j) < d(j + 1) Thent = d(j): d(j) = d(j + 1): d(j + 1) = tEnd IfNext jNext iFor i = 1 To 10: Picture1.Print d(i);If i Mod 5 = 0 Then Picture1.PrintNext iEnd SubE.5Dim a%(3, 3), b%(3, 3)Private Sub Form_Load()For i = 0 To 3For j = 0 To 3a(i, j) = Int(Rnd * 36 + 35)b(i, j) = Int(Rnd * 41 + 100)Next jNext iEnd SubPrivate Sub Command1_Click()Picture1.ClsFor i = 0 To 3For j = 0 To iPicture1.Print a(i, j); " ";Next jPicture1.PrintNext iEnd SubPrivate Sub Command2_Click()Picture2.ClsFor i = 0 To 3For j = i To 3Picture2.Print Tab(j * 6); b(i, j);Next jPicture2.PrintNext iEnd SubPrivate Sub Command3_Click()Picture3.Clssa = 0For i = 0 To 3sa = sa + a(i, i)Next isb = 0For i = 0 To 3sb = sb + b(i, 3 - i)Next iPicture3.Print "A 数组主对角线元素和为:"; sa Picture3.Print "B 数组副对角线元素和为:"; sb End SubE.6Private Sub Form_Click()n = InputBox("输入n 值")ReDim a6%(n + 1, n + 1)a6(0, 0) = 1: a6(1, 1) = 1: a6(1, 0) = 1For i = 2 To n + 1For j = 2 To ia6(i, j) = a6(i - 1, j - 1) + a6(i - 1, j) Picture1.Print a6(i, j); "";Next jPicture1.PrintNextEnd SubE.7Private Sub Form_Load()List1.ClearList1.AddItem "大学计算机基础"List1.AddItem "C/C++程序设计"List1.AddItem "VB 程序设计"List1.AddItem "Web 程序设计"List1.AddItem "多媒体技术与应用"List1.AddItem "数据库技术与应用"List1.AddItem "网络技术与应用"List1.AddItem "硬件技术基础"List1.AddItem "软件技术技术基础"End SubPrivate Sub List1_Click()If List2.ListCount >= 5 ThenMsgBox ("超过5 门课程,不能再选")Exit SubElseList2.AddItem List1.TextList1.RemoveItem List1.ListIndexEnd IfEnd SubE.8Sub Combo1_KeyPress(KeyAscii As Integer) Select Case KeyAsciiCase 48 To 57, 13Case ElseKeyAscii = 0End SelectIf KeyAscii = 13 ThenCombo1.AddItem Combo1.TextCombo1.Text = ""End IfEnd SubPrivate Sub Command1_Click()Dim min%, max%min = Val(Combo1.List(0))max = Val(Combo1.List(0))imin = 0imax = 0For i = 1 To Combo1.ListCount - 1If Val(Combo1.List(i)) > max Thenimax = imax = Combo1.List(i)ElseIf Val(Combo1.List(i)) < min Thenimin = imin = Combo1.List(i)End IfNext it = Combo1.List(0)Combo1.List(0) = Combo1.List(imin)Combo1.List(imin) = tt = Combo1.List(Combo1.ListCount - 1)Combo1.List(Combo1.ListCount - 1) = Combo1.List(imax) Combo1.List(imax) = tEnd SubE.9Private Sub Form_Click()For i = 0 To Screen.FontCount - 1If Asc(Left(Screen.Fonts(i), 1)) < 0 ThenPicture1.Print Screen.Fonts(i)Picture2.FontName = Screen.Fonts(i)Picture2.Print "商丘师范学院"End IfNext iEnd SubE.10Private Type clerknumber As String * 3name As String * 5salary As IntegerEnd TypeDim a(0 To 4) As clerk, n%Private Sub Command1_Click()If n >= 5 ThenMsgBox ("输入人数超过数组声明的个数")ElseWith a(n).number = Text1.name = Text2.salary = Text3Picture1.Print a(n).number, a(n).name, a(n).salary PrintEnd Withn = n + 1Text1 = ""Text2 = ""Text3 = ""End IfEnd SubPrivate Sub Command2_Click()Dim t As clerk, i%, j%For i = 0 To n - 1For j = i To n - 1If a(i).salary < a(j + 1).salary Thent = a(i): a(i) = a(j + 1): a(j + 1) = tEnd IfNext jNext iPicture1.ClsPicture1.Print "工号姓名工资" For i = 0 To n - 1Picture1.Print a(i).number, a(i).name, a(i).salaryPrintNext iEnd SubF.1Private Sub Form_Click()Dim a(1 To 10), amin, i%For i = 1 To 10a(i) = -Int(Rnd * 101 + 300)Print a(i);Next iCall s(a(), amin)PrintPrint "min="; aminEnd SubSub s(b(), min)Dim i%min = b(LBound(b))For i = LBound(b) + 1 To UBound(b)If b(i) < min Then min = b(i)Next iEnd SubF.2Private Sub Command1_Click()Dim mm%, nn%mm = Val(Text1)nn = Val(Text2)Picture1.Print mm; Tab(6); nn; Tab(12); gcd(mm, nn) End SubFunction gcd%(ByVal m%, ByVal n%)If m < n Then t = m: m = n: n = tr = m Mod nDo While (r <> 0)m = n: n = r: r = m Mod nLoopgcd = nEnd FunctionF.3Dim x!Private Sub Command1_Click()Print "调用标准函数Sin 的结果"; Sin(x)End SubPrivate Sub Command2_Click()Print "调用自定义函数MySin 的结果"; MySin(x) End SubFunction MySin(x!) As DoubleDim i%, t!, s!t = xs = ti = 1Do While Abs(t) > 0.00001t = -1 * t * x * x / ((i + 1) * (i + 2))s = s + ti = i + 2LoopMySin = sEnd FunctionPrivate Sub Command3_Click()x = InputBox("输入要计算正弦函数的角度值x") x = x * 3.14 / 180End SubF.4Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 ThenIf Not IsNumeric(Text1) ThenMsgBox "输入非数字串,重新输入"Text1.Text = ""Text1.SetFocusElseIf IsH(Text1) ThenPicture1.Print Text1; " ★"ElsePicture1.Print Text1End IfText1 = ""End IfEnd IfEnd SubFunction IsH(ss As String) As BooleanDim i%, Ls%IsH = Truess = Trim(ss)Ls = Len(ss)For i = 1 To Ls \ 2If Mid(ss, i, 1) <> Mid(ss, Ls + 1 - i, 1) ThenIsH = FalseExit FunctionEnd IfNext iEnd FunctionF.5Function prime(ByVal m As Integer) As Booleanprime = TrueDim i%For i = 2 To m - 1If (m Mod i) = 0 Then prime = False: Exit Function '注意冒号和exit 的范围Next iEnd FunctionPrivate Sub Command1_Click()n = 0For i = 6 To 100 Step 2For j = 3 To i \ 2If prime(j) ThenIf prime(i - j) ThenList1.AddItem i & " =" & j & " +" & i - jn = n + 1End IfEnd IfNext jNext iPicture1.Print " 6 和100 之间共有"; n; "对素数和"End SubF.6Dim a%()Private Sub Form_Click()Print "1000 以内的完数为:"For i = 1 To 1000If IsWs(i) ThenPrint i; "=1";For j = 1 To UBound(a)Print "+"; a(j);Next jPrintEnd IfNext iEnd SubFunction IsWs(m) As BooleanDim s%s = 0For i = 1 To m \ 2If m Mod i = 0 ThenReDim Preserve a(j)a(j) = ij = j + 1s = s + iEnd IfNext iIf m = s Then IsWs = TrueEnd FunctionF.7Private Sub DeleStr(s1 As String, ByVal s2 As String)Dim i%ls2 = Len(s2)i = InStr(s1, s2)Do While i > 0s1 = Left(s1, i - 1) + Mid(s1, i + ls2) ' 在s1 中去除s2 子串i = InStr(s1, s2)LoopEnd SubPrivate Sub Command1_Click() ' 调用DeleStr 子过程Dim ss1 As Stringss1 = Text1Call DeleStr(ss1, Text2)Text3 = ss1End SubPrivate Sub Command2_Click()End SubF.8Private Sub Command1_Click()Dim maxw$maxlen Text1 & " ", maxwText2 = maxwEnd SubSub maxlen(s$, maxw$)Dimword$ maxw = ""Do While s <> ""i = InStr(s, " ")word = Left(s, i - 1)If Len(word) > Len(maxw) Then maxw = words = Mid(s, i + 1)LoopEnd SubG.1Private Sub Command1_Click()List1.ClearList1.AddItem Combo1If Option1 Then List1.AddItem "Pentium II"If Option2 Then List1.AddItem "Pentium I"If Option3 Then List1.AddItem "Celeron"List1.AddItem Text1If Check1 Then List1.AddItem "声卡"If Check2 Then List1.AddItem "Modem"If Check3 Then List1.AddItem "网络适配器"End SubPrivate Sub Text1_LostFocus()st = UCase(Trim(Text1))le = Len(st)If Not IsNumeric(Left(st, le - 2)) Or Right(st, 2) <> "MB" Then MsgBox "有不合法字符!"Text1 = ""Text1.SetFocusEnd IfEnd SubG.2Private Sub Check1_Click()Picture1.Font.Bold = Not Picture1.Font.BoldEnd SubPrivate Sub Check2_Click()Picture1.Font.Italic = Not Picture1.Font.BoldEnd SubPrivate Sub Command1_Click()Picture1.ClsIf Option1 ThenPicture1.Print Sin(Val(Text1))ElseIf Option2 ThenPicture1.Print Exp(Val(Text1))ElseIf Option3 ThenPicture1.Print Sqr(Val(Text1))End IfEnd SubPrivate Sub return_Click(Index As Integer)Form6.ShowUnload Form2End SubG.3Private Sub HScroll1_Change()Text1 = VScroll1.ValueText2 = HScroll1.ValueText3 = HScroll2.ValueText4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), "0.00") Text5 = Format(Val(Text4) + Val(Text1), "0.00")End SubPrivate Sub HScroll2_Change()Text1 = VScroll1.ValueText2 = HScroll1.ValueText3 = HScroll2.ValueText4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), "0.00") Text5 = Format(Val(Text4) + Val(Text1), "0.00")End SubPrivate Sub VScroll1_Change()Text1 = VScroll1.ValueText2 = HScroll1.ValueText3 = HScroll2.ValueText4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), "0.00") Text5 = Format(Val(Text4) + Val(Text1), "0.00")End SubG.4Dim t As SinglePrivate Sub Command1_Click()t = InputBox("输入倒计时分钟数")t = t * 60ProgressBar1.Min = 0ProgressBar1.Max = tProgressBar1.Value = tEnd SubPrivate Sub Command2_Click()Timer1.Interval = 1000ProgressBar1.Visible = TrueEnd SubPrivate Sub Timer1_Timer()Dim m%, s%t = t - 1ProgressBar1.Value = tm = t \ 60s = t Mod 60Label1 = m & "分" & s & "秒"If t = 0 ThenMsgBox " 时间到!"Timer1.Interval = 0ProgressBar1.Visible = FalseEnd IfEnd SubG.5Private Sub Command1_Click()CommonDialog1.ShowColorLabel1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Command2_Click()CommonDialog1.ShowOpeni = Shell("C:\WINDOWS\NOTEPAD.exe " + CommonDialog1.FileName, vbNormalFocus) End SubG.6rivate Sub bold_Click()Text1.FontBold = Not Text1.FontBoldbold.Checked = Not bold.CheckedEnd SubPrivate Sub del_Click()Text1 = ""End SubPrivate Sub end_Click()EndEnd SubPrivate Sub font12_Click()Text1.FontSize = 12End SubPrivate Sub font16_Click()Text1.FontSize = 16End SubPrivate Sub Form_Load()bold.Checked = Falseitalic.Checked = FalseEnd SubPrivate Sub italic_Click()Text1.FontItalic = Not Text1.FontItalicitalic.Checked = Not italic.CheckedEnd SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then PopupMenu menu2End SubG.7Private Sub Command1_Click()CommonDialog1.ShowColorLabel1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Command2_Click()CommonDialog1.ShowOpeni = Shell("C:\WINDOWS\NOTEPAD.exe " + CommonDialog1.FileName, vbNormalFocus) End SubPrivate Sub return_Click(Index As Integer)Form6.ShowUnload Form5End SubG.8G.9Private Sub 结束_Click()EndEnd SubPrivate Sub 删除最大值_Click()max = List1.List(0)For i = 1 To List1.ListCount - 1If max < List1.List(i) Then max = List1.List(i): j = i Next iList1.RemoveItem jEnd SubPrivate Sub 删除最小值_Click()min = List1.List(0)For i = 1 To List1.ListCount - 1If min > List1.List(i) Then min = List1.List(i): j = i Next iList1.RemoveItem jEnd SubPrivate Sub 随机产生_Click()RandomizeFor i = 0 To 9List1.List(i) = Int(Rnd * 30 + 70)Next iEnd SubPrivate Sub 添加数据_Click()List1.AddItem Int(Rnd * 30 + 70)End SubPrivate Sub 统计_Click()Dim max%, min%, ave!, m%, n%max = List1.List(0)min = List1.List(0)ave = List1.List(0)m = 0n = 0For i = 1 To List1.ListCount - 1If max < List1.List(i) Then max = List1.List(i): m = i If min > List1.List(i) Then min = List1.List(i): n = i ave = ave + List1.List(i)Next iForm2.Text1 = List1.List(n)Form2.Text2 = List1.List(m)Form2.Text3 = Format(ave / List1.ListCount, "0.00") Form2.ShowEnd SubG.10Private Sub experimentG2_Click()Form2.ShowEnd SubPrivate Sub experimentG3_Click()Form3.ShowEnd SubPrivate Sub experimentG4_Click()Form4.ShowEnd SubPrivate Sub experimentG5_Click()Form5.ShowEnd SubPrivate Sub font_12_Click()Text1.FontSize = 12End SubPrivate Sub font_16_Click()Text1.FontSize = 16End SubPrivate Sub rnd10_Click()RandomizeFor i = 0 To 9List1.List(i) = Int(Rnd * 30 + 70)Next iEnd SubPrivate Sub stat_Click()Dim max%, min%, ave!, m%, n%max = List1.List(0)min = List1.List(0)ave = List1.List(0)m = 0n = 0For i = 1 To List1.ListCount - 1If max < List1.List(i) Then max = List1.List(i): m = i If min > List1.List(i) Then min = List1.List(i): n = i ave = ave + List1.List(i)Next istat2.Text1 = List1.List(n)stat2.Text2 = List1.List(m)stat2.Text3 = Format(ave / List1.ListCount, "0.00")stat2.ShowEnd SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then PopupMenu caidan2, vbPopupMenuCenterAlignEnd SubPrivate Sub xie_Click()Text1.Font.Italic = Not Text1.Font.BoldEnd SubH.1Private Sub Command1_Click()Open "c:\score" For Output As #1Print #1, "051023", "王海涛", 66Print #1, "052498", "周文英", 88Print #1, "050992", "陈建东", 77Open "c:\score1" For Output As #2Write #2, "051023", "王海涛", 66Write #2, "052498", "周文英", 88Write #2, "050992", "陈建东", 77Closei1 = Shell("NOTEPAD.exe" + " c:\score", vbNormalNoFocus)i2 = Shell("NOTEPAD.exe" + " c:\score1", vbNormalNoFocus)End SubPrivate Sub Command2_Click()Dim no As String, name As String, s As IntegerOpen "c:\score" For Input As #1Do While Not EOF(1)Line Input #1, linedataList1.AddItem linedataLoopOpen "c:\score1" For Input As #2Do While Not EOF(2)Input #2, no, name, sList2.AddItem no & name & sLoopCloseEnd SubH.2Private Sub Command1_Click()Dim fib%(0 To 9), i%Open "c:\fb.dat" For Output As #1For i = 0 To 9If i = 0 Or i = 1 Thenfib(i) = iElsefib(i) = fib(i - 1) + fib(i - 2)End IfPrint #1, """Fib(" & i & ")""," & fib(i)Next iClose #1i = Shell("NOTEPAD.exe" + " c:\fb.dat", vbNormalNoFocus) End SubPrivate Sub Command2_Click()Dim st$, n%, sum%Open "c:\fb.dat" For Input As #1Do While Not EOF(1)Input #1, st, nsum = sum + nList1.AddItem st & "=" & nLoopClose #1List1.AddItem " 合计:" & sumList1.AddItem "平均:" & sum / 10End SubH.3H.4Private Type studtypeno As String * 4name As String * 6mark As SingleEnd TypeDim student As studtype, stud(1 To 5) As studtype, t As studtypePrivate Sub Command1_Click()Open "d:\score.dat" For Random As #1 Len = Len(student) With student.no = "0001".name = "星期一"。
"VB程序设计"综合复习资料第一章 Visual Basic程序设计概述一、填空题1、VisualBasic是一种面向__________的可视化程序设计语言,采取了__________的编程机制。
2、在VB中工程文件的扩展名是____________,窗体文件的扩展名是____________,标准模块文件的扩展名是____________。
3、执行“工程〞菜单下的__________命令,可选择并添加Active*控件。
4、Visual Basic 6.0用于开发__________环境下的应用程序。
二、选择题1、下面不是VB工作模式的是〔〕A.设计模式B.运行模式C.汇编模式D.中断模式2、可视化编程的最大优点是〔〕A.具有标准工具箱B.一个工程文件由假设干个窗体文件组成C.不需要编写大量代码来描述图形对象D.所见即所得3、以下不能翻开属性窗口的操作是〔〕A.执行“视图〞菜单中的“属性窗口〞命令B.按F4键C.按Ctrl+TD.单击工具栏上的“属性窗口〞按钮4、以下可以翻开立即窗口的操作是〔〕A.Ctrl+D B.Ctrl+E C.Ctrl+F D.Ctrl+G5、Visual Basic的编程机制是〔〕A.可视化 B.面向对象 C.面向图形 D.事件驱动三、简答题1、代码窗口主要包括哪几局部?2、在工程资源管理器窗口中,主要列出了哪三类文件?3、窗体布局窗口的主要用途是什么?4、VB的根本特点是什么?5、怎样理解可视化设计?6、怎要理解事件驱动编程?第二章简单的VB程序设计一、填空题1、设置是否可以用Tab键来选取命令按钮,应该用______________属性。
2、一个控件在窗体的位置由_______和________属性决定,其大小由__________和_________属性决定。
3、利用对象的属性setfocus可获得焦点,对于一个对象,只有其visible属性和____________属性为true,才能承受焦点。