2012年3月vb实验考试练习题
VB实验指导书_理论综合练习题_答案(完结版).doc
第二部分综合练习理论练习一一单选1-5 CDCCB 640ABDCD 11-15 CCBBD 16-20 DBCBA二多选1 ABCE 2CE 3 BCE 4 ADE 5 ABCD6ABCDE 7ACD8ABCDE 9 ABC 10ABCDE三判断1-5 X V X V V6-10 V X V V V四填空1 x=int(Rnd*101)End If avg=s/82 i=l to 10Right(str(i),l)或Right(str(i mod 10))3 m*n/GCD(m,n)GCD(b, a mod b)4 Exit For i & “是素数”Next i五阅读程序1-4 DDCB六程序设计1Option Base 1Private Sub Form_click()Dim a( 10)Ciscreatedata a()sort a()Fori= ITo 10Print a(i);Next iEnd SubSub createdata(a())Fori = ITo 10a(i) = Int(Rnd * 101)Next iEnd SubSub sort(a())For i = 1 To 9Forj = 1 To 10-iIf a(j) > a(j + l)Thent = a(j): a(j) = a(j + 1): a(j + 1) = tEnd IfNext jNext iEnd Sub2Private Type ksno As String * 8Bscj As IntegerSjcj As IntegerEnd TypeDim student As ksPrivate Sub Form_Load()Open "c:\ksxx.dat" For Random As#l Len = Len(student)End SubPrivate Sub cmdadd_Click()student.no = Text 1.Textstudent.Bscj = Val(Text2.Text)student.Sjcj = Vai (Tex t3.Text)lastrecord = LOF( 1) / Len(student) + 1Put # 1, lastrecord, studentTextl.Text =Text2.Text = ””Text3.Text ="End SubPrivate Sub cmdquit_Click()Close #1EndEnd Sub1-5 CABCD理论练习二6-10 ABCCD 11-15 BBBAB1 CD2 AD3CE4BC6BCDE7CDE8ABCDE9 ABD三判断二多选1-5 X X X X V 6-10 V V V X X 16-20 DBAAC5 AD10ACDE1n-l 或者Sqr (n)02X y3 1 to 102*i-14Button=2start=True 五阅读程序1-5DBDAB六程序设计1Private Sub Form_click()四填空japan = 47528china = 22257n = 0 True — (x, y)Do While china <= japanchina = china * 1.098japan = japan * 1.028 n= n + 1LoopPrint n & ”年之后,中国GDP将超过日本”End Sub•VB6中的Split函数,其功能足将一字符巾用分界符分割为一字符串数组。
2012年江苏高中信息技术学业水平测试vb操作题带答案
Vb专项练习第一套题目1、打开“考生文件夹\96\工程1.vbp”,完善程序并保存。
实现功能:假设有一个5位数密码。
只记得密码为67□□8,其中百位和十位的数字记不清了,但知道该密码能够被78整除,也能被67整除。
请完善算法帮忙找出这个密码。
''请不要更改源程序的结构,删除原题里的①、②、③。
填写正确的代码,使程序完善Private Sub Command1_Click()Dim x As LongFor x = ① To 67998 Step 10If (x Mod 67 = 0) And (x Mod 78 = 0) ThenPrint ②End If③End Sub2、“考生文件夹\51\工程1.vbp”是采用“穷举法”求出所有水仙花数的程序,请完善程序并保存。
说明:若一个三位数abc,满足:abc=a3+b3+c3,则称abc为水仙花数。
如三位数153满足:13+53+33=1+125+27=153,则153是水仙花数。
'请不要更改源程序的结构,删除原题里的①、②、③。
填写正确的代码,使程序完善Private Sub Command1_Click()Dim i, a, b As IntegerFor i = 100 To ①a = i \ 100b = (i - a * 100) \ 10c = ②If a * a * a + b * b * b + c * c * c = i ThenPrint CStr(i)③Next iEnd Sub3、打开“考生文件夹\12\工程1.vbp”,完善程序并保存。
实现功能:在Text1中输入一个代表秒数的整数后,单击“计算”按钮后,在Label1、Label2、Label3中显示对应的小时、分钟和秒数。
如在Text1中输入“3672”,Label1、Label2、Label3中分别显示“1”、“1”、“12”,即1小时1分12秒。
2012 立信VB 操作题 不负责任版
2012 立信VB 操作题不负责任版。
来源:黄舒蓉的日志1.答案:2.答案3.答案:44.。
答案5.有些我只能说大概题目了反正计时器,通用对话框,菜单编辑,图像框是肯定有考的,而且五题操作题基本上有四题是这个。
6.图像框的放大(题目不太记得清)那题的代码是image1.heigh=image1.heigh+100 image1.width=image1.width +100缩小就是-100.7 书本154页例7.18 计时器的多数比较简单 visible 属性和间隔时间会了就差不多主观题很多在之前的立信题库四里面八题以上差不多我这里再给一次VB考试四1、某人编写了如下程序,用来求10个整数(整数从键盘输入)中的最大值:Private Sub Command1_Click()Dim a(10) As Integer,max As IntegerFor k=1 To 10a(k)=InputBox("输入一个整数")Next kmax=0For k=1 To 10If a(k)>max Thenmax=a(k)End IfNext kPrint maxEnd Sub运行程序时发现,当输入10个正数时,可以得到正确结果,但输入10个负数时结果是错误的,程序需要修改。
下面的修改中可以得到正确运行结果的是______。
A:把max=a(k)改为a(k)=maxB:把If a(k)>max Then改为If a(k)<max ThenC:把第2个循环语句For k=1 To 10改为For k=2 To 10D:把max=0改为max=a(10)参考答案:D2、设有语句:Open "d:\Test.txt" For Output As #1,以下叙述中错误的是______。
A:执行该语句后,就可以通过Print#语句向文件Test.txt中写入信息B:用该语句建立的文件的文件号为1C:该语句打开d盘根目录下一个已存在的文件Test.txt,之后就可以从文件中读取信息D:若d盘根目录下无Test.txt文件,则该语句创建此文件参考答案:C3、工程中有2个窗体,名称分别为Form1、Form2,Form1为启动窗体,该窗体上有命令按钮Command1。
VB实验指导书_理论综合练习题_答案(完结版)
第二部分综合练习理论练习一一单选1-5 CDCCB 6-10 ABDCD 11-15 CCBBD 16-20 DBCBA 二多选1 ABCE2 CE3 BCE4 ADE5 ABCD6 ABCDE7 ACD8 ABCDE9 ABC 10 ABCDE三判断1-5×√×√√6-10 √×√√√四填空、1 x=int(Rnd*101) End If avg=s/82 i=1 to 10 Right(str(i),1) 或Right(str(i mod 10))3 m*n/GCD(m,n) GCD(b, a mod b)4 Exit For i & “是素数”Next i五阅读程序1-4 DDCB六程序设计1Option Base 1Private Sub Form_click()Dim a(10)Clscreatedata a()sort a()For i = 1 To 10Print a(i);Next iEnd SubSub createdata(a())For i = 1 To 10a(i) = Int(Rnd * 101)Next iEnd SubSub sort(a())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 iEnd Sub2Private Type ksno As String * 8Bscj As IntegerSjcj As IntegerEnd TypeDim student As ksPrivate Sub Form_Load()Open "c:\ksxx.dat" For Random As #1 Len = Len(student) End SubPrivate Sub cmdadd_Click()student.no = Text1.Textstudent.Bscj = V al(Text2.Text)student.Sjcj = V al(Text3.Text)lastrecord = LOF(1) / Len(student) + 1Put #1, lastrecord, studentText1.Text = ""Text2.Text = ""Text3.Text = ""End SubPrivate Sub cmdquit_Click()Close #1EndEnd Sub理论练习二一单选1-5 CABCD 6-10 ABCCD 11-15 BBBAB 16-20 DBAAC 二多选1 CD2 AD3 CE4 BC5 AD6 BCDE7 CDE8 ABCDE9 ABD 10 ACDE三判断1-5××××√6-10 √√√××四填空1 n-1 或者Sqr(n) 0 True2 x y3 1 to 10 2*i-14 Button=2 start=True -(x,y)五阅读程序1-5 DBDAB六程序设计1Private Sub Form_click()japan = 47528china = 22257n = 0Do While china <= japanchina = china * 1.098japan = japan * 1.028n = n + 1LoopPrint n & "年之后,中国GDP将超过日本"End Sub2' VB6中的Split函数,其功能是将一字符串用分界符分割为一字符串数组。
2012年3月VB试卷和答案
2012年3月全国计算机等级考试二级笔试试卷Visual Basic 语言程序设计(考试时间90分钟,满分100分)一、选择题(每小题2分,共70分)下列各题A )、B )、C )、D )四个选项中,只有一个选项是正确的。
请将正确选项填涂在答题卡相应位置上,答在试卷上不得分。
(1)下列叙述中正确的是A )循环队列是队列的一种链式存储结构B )循环队列是队列的一种顺序存储结构C )循环队列是非线性结构D )循环队列是一种逻辑结构(2)下列叙述中正确的是A )栈是一种先进先出的线性表B )队列是一种后进先出的线性表C )栈与队列都是非线性结构D )以上三种说法都不对(3)一棵二叉树共有25个结点,其中5个是叶子结点,则度为1的结点数为A )16B )10C )6D )4(4)在下列模式中,能够给出数据库物理存储结构与物理存取方法的是A )外模式B )内模式C )概念模式D )逻辑模式(5)在满足实体完整性约束的条件下A )一个关系中应该有一个或多个候选关键字B )一个关系中只能有一个候选关键字C )一个关系中必须有多个候选关键字D )一个关系中可以没有候选关键字(6)有三个关系R 、S 和T 如下:R S T则由关系R 和S 得到关系T 的操作是 A )自然连接 B )并 C )交D )差 (7)软件生命周期中的活动不包括 A )市场调研 B )需求分析C )软件测试D )软件维护 (8)下面不属于需求分析阶段任务的是A )确定软件系统的功能需求B )确定软件系统的性能需求C )需求规格说明书评审 A B Ca 1 2b 2 1c 3 1 A B C a 1 2d 2 1 A B C b 2 1 c 3 1D )制定软件集成测试计划 (9)在黑盒测试方法中,设计测试用例的主要根据是A )程序内部逻辑B )程序外部功能C )程序数据结构D )程序流程图(10)在软件设计中不适用的工具是A )系统结构图B )PAD 图C )数据流图(DFD 图) D )程序流程图(11)以下合法的VB 变量名是A )caseB )name10C )t-nameD )x*y(12)设x 是小于10的非负数。
2012vb笔试外A带参考答案-共享
一、填空题(共10个空,每空2分,共20分)1. 弹出名称为“Menu ”的菜单的语句为 PopUpMenu Main 。
2. 在VB 中,声明静态变量的关键字是 Static 。
3. 在Visual Basic 中,所有控件都应具有的属性是___Name __。
4. 显示打开文件对话框的方法是:___ShowOpen ____。
5. 以下程序的功能是:找出数组a 中的第一次出现的最小值。
要求在任何情况下都能正确运行,请完善之。
Dim a%(), Mini%, i%, n%n = Val(InputBox("请输入整数个数")) '假设输入的 n 值一定大于零 ReDim a(1 To n) For i = 1 To na(i) = Rnd * 100 Next i Mini = 1For i = 2 To nIf a(i) > a(Mini) Then Mini = i Next i Print "最小值首次出现在下标为" & Mini & "的数组元素中,值为" & a(Mini)6. 以下程序的功能是循环产生“a ” 到“z ”之间的小写英文字母,并以每行显示10个字符的形式在窗体上显示出来,当出现字母”y ”时退出循环。
请完善程序。
(小写英文字母a 的ASCII 码值为97)Private Sub Form_Click() Dim a as string * 1,i as integer Doa =_chr(int(rnd()*26+97))_ i=i+1 Print a;If _i mod 10 = 0_ then Print Loop Until _a=”y ”_ End Sub1.VB是一种面向对象的可视化程序设计语言,它采用了 A 的编程机制。
A)事件驱动B) 从主程序开始执行C)按过程顺序执行D) 按模块顺序执行2.函数Format(9876.567, "00000.00")的返回值是 B 。
2012年VB语言程序设计试卷A
Print “*”;
Next k
next i
End Sub
该程序的执行结果为___________________________________________。
教务处印制共14页(第5页)
2.下列程序的功能是找出100-999三位数中的“水仙花”数,并计算其个数。所谓水仙花数,是指三位数字立方和等于该数本身,例如153是水仙花数,因为153=13+53+33。请分析下面的程序,并补充程序的划线处。
c=k mod 10
if ________________________ then
print k
n=n+1
end if
next k
print “一共有” & n & “个水仙花数”
End Sub
教务处印制共14页(第6页)
3.请分析下面的程序,写出程序的执行结果。
Private Sub Form_Load()
Show
For i=1 to 4
For j=1 to 5-i
Print “ ”; ‘双引号之间有一个空格
Next j
For k=1 to 2*i-1
Print “*”;
Next k
next i
For i=1 to 3
For j=1 to i+1
Print “ ”; ‘双引号之间有一个空格
Next j
考试班级
管院11级
考试日期
2012年月日
考试时间
2小时
班级
姓名
学号
成绩
注意:1.命题时请适当留答题位置。请用深蓝色墨水书写,字、图清晰,书写不出边框。
2012年计算机二级VB上机试题及解题思路(第三套)
第03套1. 基本操作(2小题,每小题15分,共计30分)注意:下面出现的“考生文件夹”均为%USER%**********************************************************************请根据以下各小题的要求设计Visual Basic应用程序(包括界面和代码)。
(1)在名称为Form1的窗体上画一个名称为Frame1,标题为“目的地”的框架,在框架中添加三个复选框,名称分别为Check1、Check2、Check3,其标题分别是“上海”、“广州”、“巴黎”,其中“上海”为选中状态,“广州”为未选状态,“巴黎”为灰色状态,如图所示。
请画控件并设置相应属性。
注意:存盘时必须存放在考生文件夹下,工程文件名为sjt1.vbp,窗体文件名为sjt1.frm。
解题思路:启动Visual Basic系统,创建一个Form1窗体。
在该窗体上画一个框架控件,通过其属性窗口将名称设为Frame1,标题(Caption属性)设为“目的地”。
在F1框架中画三个复选框控件,通过其属性窗口将名称分别设为Check1、Check2、Check3,标题(Caption 属性)分别设为“上海”、“广州”、“巴黎”,“上海”的Value属性设为1,“巴黎”的Value属性设为2。
参考文件:c:\wexam\26990001\hlpsys\参考答案\sjt1.vbp、sjt1.frm、sjt1.vbw请把这些文件复制到c:\wexam\26990001中,然后打开sjt1.vbp文件并运行。
**********************************************************************(2)在名称为Form1的窗体上画一个名称为Picture1的图片框,其宽和高分别为1700、1900。
请编写适当事件过程,使得在运行时,单击图片框,则装入考生目录下的图形文件pic1.bmp,如图所示。
vbvb期末考试实验答案作业
请参考10_2.exe程序的运行结果,新建一个工程,完成"调色板"程序的设计,该程序由红绿兰三原色进行调色,如果预览满意,单击"应用"按钮,将调好的颜色作为文本框中文字的颜色。
将完成后的工程文件以Design.Vbp、窗体文件以Design.frm保存到D:\10_2目录下。
具体要求如下:1. 应用程序界面设计参考图示。
2. 要求水平滚动条和颜色成分输入文本框分别采用控件数组实现。
3. 要求操作任意一个滚动条,都会在相应的文本框中显示该颜色成分的当前取值,并且动态改变预览框中长方形的颜色。
[注意:滚动条最大值为255]4. 要求在任意一个颜色成分输入文本框中输入一个0-255的数据,相应的滚动条的滑块都会移到正确的位置上,并且预览框中长方形的颜色也随之而调整。
5. 单击"应用"按钮后将调好的颜色作为文本框中文字的颜色。
思考题:拖动滚动条时有没有触发滚动条的Change事件?提示:1. 应用程序界面设计参考图示。
程序界面右下角的预览框架里的长方形是形状控件Shape1(工具箱中的),将其FillStyle属性设置为0。
2. 要求水平滚动条和颜色成分输入文本框分别采用控件数组实现。
三个滚动条的Min设为0,Max设为255;三个文本框的Text属性设为空字串。
3. 要求操作任意一个滚动条,都会在相应的文本框中显示该颜色成分的当前取值,并且动态改变预览框中长方形的颜色。
颜色是利用Rgb(r,g,b)函数来表示,其中r,g,b是红、绿、兰颜色的饱和度,分别通过滚动条来控制。
Private Sub HScroll1_Change(Index As Integer)Text1(Index).Text = HScroll1(Index).ValueShape1.FillColor = RGB(HScroll1(0).Value, HScroll1(1).Value, HScroll1(2).Value)End Sub4. 要求在任意一个颜色成分输入文本框中输入一个0—255的数据,相应的滚动条的滑块都会移到正确的位置上,并且预览框中长方形的颜色也随之而调整。
VB练习3
一、试题1(本大题共5小题,每小题3分,共15分)【程序说明】界面设计如上图所示,程序运行时要求有以下功能:•按Command1(出题)后随机生成两个两位正整数存入模块级变量a、b且a>b,并分别在Label1、Label2中显示,此后Command1不可用;•在Text1中输入结果、按回车后,以消息框显示运算正确与否、累计所完成题数以及做错的题数,Command1恢复为可用;•按Command2(退出)后以消息框显示所完成题数以及做错的题数,退出。
【程序】Dim n As Integer, n_error As Integer(1)Private Sub Command1_Click()a = 10 + Rnd * 89:b = 10 + Rnd * 89If a < b Then (2)Label1.Caption = a: Label2.Caption = bn = n + 1: Text1.Text = "": Command1.Enabled = FalseEnd SubPrivate Sub Text1_ (3) (KeyAscii As Integer)If KeyAscii <> 13 Then (4) ' 回车键的ASCII码值为13If a - b = Val(Text1.Text) ThenMsgBox ("回答正确")ElseMsgBox("回答不正确")n_error = n_error + 1End IfCommand1.Enabled = TrueEnd SubPrivate Sub Command2_Click()MsgBox( (5) )EndEnd Sub【供选择的答案】(1) A.'小学生两位数减法训练程序 B.a=0: b=0: c=0C.n=0: n_error=0D.Dim a As Integer, b As Integer, c As Integer(2) A.b=a: a=b B.c=a: a=b: b=cC.a=b: b=aD.c=a: b=a: a=c(3) A.KeyPress B.Change C.KeyDown D.KeyUp(4) A.Exit Sub B.KeyAscii =13 C.KeyAscii=0 D.Exit Do(5) A."共" & n & "题,错" & n_error & "题"B."共n 题,错 n_error 题"C."共" + n + "题,错" + n_error + "题"D.共 & n & "题,错" & n_error & "题"二、试题2(本大题共3小题,每小题3分,共9分)阅读下列程序并回答问题,在每小题提供的若干可选答案中,挑选一个正确答案。
VB6.0 2012年考题(编程题) 加答案 注意(不可能出现2013年的考题因为还没开考所有标榜2013者都是假的)
5630101:答:设置Text1 的属性MultiLine为true和ScrollBarsFalsecommand1的属性Enabled 为Text1.FontBold = TrueEnd SubPrivate Sub Op2_Click()Text1.FontBold = FalseEnd SubPrivate Sub Cd1_Click()P1.ClsP1.Line (0, 0)-(1800, 1200)End SubPrivate Sub Cd2_Click()P1.ClsP1.Circle (900, 600), 500End SubPrivate Sub Command1_Click()Dim n As IntegerDim a As Integer, b As Integer, c As Integer n = Text1.Texta = n Mod 10b = n \ 10 Mod 10c = n \ 100If a ^ 3 + b ^ 3 + c ^ 3 = n ThenLabel1.Caption = "是水仙花数" ElseLabel1.Caption = "不是水仙花数" End IfEnd SubDim A(1 To 10)Private Sub Command1_Click() RandomizeDim i As IntegerFor i = 1 To 10A(i) = Int(10 + Rnd * (99 - 10 + 1))Text1.Text = Text1.Text & A(i) & " " Next iEnd SubPrivate Sub Command2_Click()Min = A(1)Max = A(1)For i = 2 To 10If A(i) < Min ThenMin = A(i)ElseIf A(i) > Max ThenMax = A(i)End IfNext iText2.Text = MaxText3.Text = MinEnd Sub5630102:答:设置image1 的属性BorderStyle为1和Stretch为true属性找到图片在image1 的pictureText2.Text = Text1.SelTextText1.Text = ""Text1.SetFocusEnd Sub'''不得删改本行注释Dim a As Singlea = Text1.TextIf a >= 80 And a <= 100 Then Text2.Text = "优良"If a >= 60 And a < 80 Then Text2.Text = "合格"If a > 0 And a < 60 Then Text2.Text = "不合格"End Sub:5630103Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()Label1.Caption = TimeEnd SubPrivate Sub Command1_Click()L1.AddItem Text1.TextL2.AddItem Val(Text1.Text) ^ 2T1.Text = ""T1.SetFocusEnd SubPrivate Sub Command1_Click()Dim s As String, i As Integer, n As Integers = Text1.TextFor i = 1 To Len(s)If Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" Then n = n + 1End IfNext iText2.Text = nEnd SubPrivate Sub Command1_Click()Dim i As IntegerFor i = 100 To 200If isprime(i) = False ThenText1.Text = Text1.Text & i & " "End IfNext iEnd Sub:5630104按窗体右键->菜单编辑器, 标题和名称不能少,例如:标题: 文件,名称为File.注意名称的大小写和题目一致设置标签L1的BorderStyle属性为1,Private Sub Cd1_Click()L1.Visible = FalseEnd SubPrivate Sub Cd2_Click()L1.Visible = TrueEnd Sub5630106:设置combo1的style属性为1,然后下拉组合框Private Sub Cd1_Click()Combo1.AddItem Combo1.TextEnd SubPrivate Sub Cd2_Click()Combo1.RemoveItem Combo1.ListIndexEnd SubPrivate Sub Command1_Click()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 IfEnd SubPrivate Sub Command1_Click()'''不得删改本行注释Text2.Text = zh(Text1.Text)End Sub5630107:Private Sub Command1_Click()'''不得删改本行注释Dim S As StringOpen "K:\administrator\5630111\PDZM.TXT" For Input As #1 Do While Not EOF(1)Input #1, SText1.Text = Text1.Text & SLoopEnd SubPrivate Sub Command2_Click()'''不得删改本行注释Dim S As String, i As Integer, N As IntegerS = Text1.TextFor i = 1 To Len(S)If Mid(S, i, 1) = UCase(Text2.Text) Or Mid(S, i, 1) = LCase(Text2.Text) Then N = N + 1End IfNext iText3.Text = NEnd Sub:5630108Private Sub C1_Click()L1.AddItem T1.TextL2.AddItem Asc(T1.Text)T1.Text = ""T1.SetFocusEnd Sub:5630109Private Sub Form_Load()List1.AddItem "PictureBox"List1.AddItem "Label"List1.AddItem "TextBox"List1.AddItem "Frame"List1.AddItem "CommandButton"List1.AddItem "CheckBox"End SubPrivate Sub Command1_Click()Text1.Text = List1.TextText2.Text = List1.ListIndexEnd Sub5630110:Dim n As Integern = Text1.TextFor i = 1 To 50If Sqr(i) = Int(Sqr(i)) ThenText2.Text = Text2.Text & i & " "End IfNext iEnd SubOption ExplicitDim A(1 To 20) As Integer '''不得删改本行声明Private Sub Command1_Click()'''不得删改本行注释Open "K:\administrator\5630005\input02.txt" For Input As #1 For i = 1 To 20Input #1, A(i)Text1.Text = Text1.Text & A(i) & " "Next iEnd SubPrivate Sub Command2_Click()Dim i As Integer, sum As IntegerFor i = 1 To 20sum = sum + A(i)Next iText2.Text = sumEnd Sub答:设置image1 的属性BorderStyle为1和Stretch为true Private Sub Check1_Click()If Check1.Value = 1 ThenImage1.Picture = LoadPicture("K:\Fjexam95\Jztx.bmp")ElseImage1.Picture = LoadPicture("")End IfEnd Sub。
VB实验教材习题答案 (1)
第1章VB集成环境与VB概述一、选择题第2章常用控件与界面设计一、选择题第3章数据、表达式与简单程序设计一、选择题第4章选择分支与循环一、选择题二、填空题1.5 7 13 12 14 112. 3 1 5 3 4 13. right(a$,i)4. 45. 6-i6. 6 11 10 21 13 347. 5 14 138. Is else end select9. a*(2*i-1)*(-1)*x/(2*i+2) i+110. 0 n-111. 1 t*(-1)*x^2/((2*k-1)*(2*k)) Abs(t)>eps12. count1=count+1 count1>013. sum=0 sum+j st & k & “+”14. 9 x三、编程题1.Option ExplicitPrivate Sub Command1_Click()Dim s As String, i As Integer, ch As String * 1Dim a As Integer, b As Integer, c As Integers = Text1.TextFor i = 1 To Len(s)ch = Mid(s, i, 1)If (ch >= "0" And ch <= "9") Thena = a + 1ElseIf (ch >= "A" And ch <= "Z") Or (ch >= "a" And ch <= "z") Thenb = b + 1Elsec = c + 1End IfNextPrint "数字个数"; aPrint "字符个数"; bPrint "其他字符"; cEnd Sub2.Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, n As IntegerDim a As Integer, b As Integer, c As IntegerFor i = 1 To 50n = Int(Rnd * 90 + 10)Print n;If i Mod 10 = 0 Then PrintIf n <= 40 Thena = a + 1ElseIf n <= 70 Thenb = b + 1Elsec = c + 1End IfNext iPrint "小于等于40的个数:"; aPrint "大于40小于等于70的个数:"; bPrint "大于70的个数:"; cEnd Sub3.Option ExplicitPrivate Sub Command1_Click()Dim x As SingleDim t As Long, n As Integerx = 1t = 1n = 1Do While 1 / t >= 0.0001x = x + 1 / tn = n + 1t = t * nLoopPrint xEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim k As Integer, sum As Integer, i As Integerk = InputBox("请输入一个正整数k", "输入框")For i = 1 To Len(CStr(k))sum = sum + Mid(k, i, 1)Next iMsgBox k & "的各位数字之和" & sumEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, iSum As LongFor i = 1 To 20iSum = iSum + i ^ 4NextPrint iSumEnd Sub6.Option ExplicitPrivate Sub Command1_Click()Dim a As Integer, b As IntegerDim sum1 As Integer, sum2 As LongDim i As Integer, j As IntegerFor a = 2 To 3000sum1 = 0sum2 = 0For i = 1 To a \ 2If a Mod i = 0 Then sum1 = sum1 + i Next ib = sum1For j = 1 To b \ 2If b Mod j = 0 Then sum2 = sum2 + j Next jIf sum2 = a And a < b Then Print a, bNextEnd Sub7.Private Sub Command1_Click() '打印菱形Dim i As Integer, j As IntegerClsFor i = 1 To 6 '打印菱形上边6行Print Tab(20);Print Spc(6 - i);For j = 1 To 2 * (i - 1) + 1If j = 1 Or j = 2 * (i - 1) + 1 ThenPrint "*";ElsePrint " ";End IfNext jPrintNext iFor i = 5 To 1 Step -1 '打印下半部分Print Tab(20);Print Spc(6 - i);For j = 1 To 2 * (i - 1) + 1If j = 1 Or j = 2 * (i - 1) + 1 ThenPrint "*";ElsePrint " ";End IfNext jPrintNext iEnd Sub8.Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, j As Integer, iSum As IntegerPrint "连续和为1250的正整数是:"For i = 1 To 500iSum = 0For j = i To 500iSum = iSum + jIf iSum >= 1250 Then Exit ForNextIf iSum = 1250 ThenPrint i; " ~"; jEnd IfNextEnd Sub9.Option ExplicitPrivate Sub Command1_Click()Dim a As Integer, b As Integer, c As IntegerFor a = 1 To 50For b = a To 50For c = b To 50If a ^ 2 + b ^ 2 = c ^ 2 ThenPrint a, b, cEnd IfNext cNext bNext aEnd Sub第5章数组一、选择题二、填空题1.Variant2.ReDim A(N)A(1)If M < A(I) Then M = A(I)3.Int(26 * Rnd) + 65Chr(t)i + 1 To 10A(i) > A(j)4.InStr(s, ",")Right(s, Len(s) - n)s5.T – 1I + 16.k = 6 - i – jmax = m7.j = 48j = j-38.i + 1i = i + 19. 23710. 3103511.numi + 1a(j)=temp三、编程题1.Option ExplicitOption Base 1Private Sub Command1_Click()Dim a(10) As IntegerDim i As Integer, max As IntegerFor i = 1 To 10a(i) = Int(90 * Rnd) + 10Print a(i);Next iPrinti = 1max = 0Do While i <= 10If a(i) Mod 3 = 0 ThenIf a(i) > max Thenmax = a(i)End IfEnd Ifi = i + 1LoopIf max = 0 ThenPrint "无要找的数"ElsePrint max & "是最大的能被3整除的数"End IfEnd Sub2.Option ExplicitOption Base 1Private Sub Command1_Click()Dim A() As IntegerDim I As Integer, m As IntegerDim K As IntegerReDim A(10)Print "原数组:";For I = 1 To 10A(I) = IPrint A(I);Next IPrintm = InputBox("????m")K = 9 + mReDim Preserve A(K)For I = 11 To KA(I) = A(I - 10)Next IFor I = 1 To 10A(I) = A(I + m - 1)Next IPrint "平移后的数组:";For I = 1 To 10Print A(I);Next IPrintEnd Sub3.Option ExplicitOption Base 1Private Sub Command1_Click()Dim I As Integer, J As Integer, K As IntegerDim a() As Integer, n As Integer, p As Integer Dim s As String, Flag As Booleanp = 1For K = 10 To 100I = 1Do While I <= 10 And Not FlagJ = 1Do While J <= 10 And Not Flagn = I ^ 2 + J ^ 2If n = K ThenFlag = TrueReDim Preserve a(p)a(p) = Kp = p + 1s = I & Str(J) & Str(K)List1.AddItem sEnd IfJ = J + 1LoopI = I + 1LoopFlag = FalseNext KEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim A(10) As IntegerDim B(10) As Integer, S As StringDim I As Integer, J As Integer, X As IntegerA(1) = Int(90 * Rnd) + 10S = A(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = A(J) Then Exit ForNext JIf J = I ThenA(I) = XS = S & " " & A(I)Exit DoEnd IfLoopNext IText1.Text = SB(1) = Int(90 * Rnd) + 10S = B(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = B(J) Then Exit ForNext JIf J = I ThenB(I) = XS = S & " " & B(I)Exit DoEnd IfLoopNext IText2.Text = SS = ""For I = 1 To 10For J = 1 To 10If A(I) = B(J) ThenS = S & " " & A(I)End IfNext JNext IIf S = "" ThenText3.Text = "没有重复"ElseText3.Text = SEnd IfEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim I As Integer, J As IntegerDim a() As Integer, K As Integer, Sum As Integer K = Val(Text1.Text)I = 1DoJ = K Mod 10ReDim Preserve a(I)a(I) = JSum = Sum + JK = K \ 10I = I + 1Loop Until K = 0Text2.Text = SumEnd Sub6.Option ExplicitPrivate Sub Command1_Click()Dim a(100, 2) As Integer, K As IntegerDim I As Integer, J As IntegerDim M As Integer, N As IntegerK = 1For I = 1 To 99For J = 1 To 99If I > J ThenM = I - JN = I + JIf Sqr(M) = Int(Sqr(M)) And Sqr(N) = Int(Sqr(N)) ThenList1.AddItem I & " " & Ja(K, 1) = Ia(K, 2) = JK = K + 1End IfEnd IfNext JNext IEnd Sub7.Option ExplicitOption Base 1Dim a(5, 5) As IntegerPrivate Sub Command1_Click() '生成数组并显示Dim i As Integer, j As IntegerPicture1.ClsPicture2.ClsPicture3.ClsRandomizeFor i = 1 To 5For j = 1 To 5a(i, j) = Int(90 * Rnd) + 10Picture1.Print a(i, j);NextPicture1.PrintNextEnd SubPrivate Sub Command2_Click()Dim i As Integer, j As Integer, max As IntegerDim b(5) As Integer, c(5) As IntegerFor i = 1 To 5max = a(i, 1)For j = 1 To 5If max < a(i, j) Thenmax = a(i, j)End Ifb(i) = maxIf max = a(i, j) Then c(i) = jNext jNext iFor i = 1 To 5Picture2.Print b(i)Picture3.Print c(i)NextEnd Sub8.Option ExplicitOption Base 1Dim a(5, 5) As IntegerPrivate Sub Command1_Click() '生成数组并显示Dim i As Integer, j As IntegerPicture1.ClsPicture2.ClsLabel3.Caption = "最大值?"Label4.Caption = "最小值?"RandomizeFor i = 1 To 5For j = 1 To 5a(i, j) = Int(90 * Rnd) + 10Picture1.Print a(i, j);NextPicture1.PrintNextEnd SubPrivate Sub Command2_Click() '交换并显示Dim i As Integer, j As Integer, t As IntegerDim maxi As Integer, mini As Integer, max As Integer, min As Integer max = 10: min = 99For i = 1 To 5For j = 1 To 5If max < a(i, j) Thenmax = a(i, j)maxi = iEnd IfIf min > a(i, j) Thenmin = a(i, j)mini = iEnd IfNextNextIf maxi <> mini ThenFor j = 1 To 5t = a(maxi, j)a(maxi, j) = a(mini, j)a(mini, j) = tNext jFor i = 1 To 5For j = 1 To 5Picture2.Print a(i, j);NextPicture2.PrintNextLabel3.Caption = "最大值" & max & "在第" & maxi & "行"Label4.Caption = "最小值" & min & "在第" & mini & "行"ElsePicture2.Print "最小值和最大值在一行"Label3.Caption = "最大值" & max & "在第" & maxi & "行"Label4.Caption = "最小值" & min & "在第" & mini & "行"End IfEnd SubPrivate Sub Form_click()Picture1.ClsPicture2.ClsLabel3.Caption = ""Label4.Caption = ""End Sub9.Option Base 1Private Sub Command1_Click()Dim i As Integer, j As Integer, n As Integer, a() As Integern = InputBox("请输入一个奇数N:")If n Mod 2 = 0 ThenMsgBox ("请重新输入奇数!")End IfReDim a(n, n)For i = 1 To nFor j = 1 To nIf i = (n + 1) / 2 And j = (n + 1) / 2 Thena(i, j) = -1ElseIf i = j Or i + j = n + 1 Thena(i, j) = 1Elsea(i, j) = 0End IfNext jFor i = 1 To nFor j = 1 To nPrint a(i, j);Next jPrintNext iEnd Sub10.Option Base 1Dim a(10) As IntegerPrivate Sub Command1_Click()Dim i As IntegerPrint "生成的数组:"RandomizeFor i = 1 To 10a(i) = Int(Rnd * 90) + 10Print a(i);NextPrintEnd SubPrivate Sub Command2_Click()Dim i As Integerx = InputBox("请输入要删除的数组元素下标:") Print "删除第" & x & "个数组元素后:"For i = x + 1 To 10a(i - 1) = a(i)NextFor i = 1 To 9Print a(i);NextEnd Sub11.Option ExplicitDim a(20) As Integer, i As IntegerPrivate Sub Command1_Click()RandomizeFor i = 1 To 20a(i) = Int(Rnd * 9) + 1Text1 = Text1 & a(i) & " "If i = 10 Then Text1 = Text1 & vbCrLf NextPrivate Sub Command2_Click()Dim j As Integer, k As Integer, b(20) As Boolean 'b(2)用来记录a(2)是否和前面的数相同,相同记为true,不再统计For i = 1 To 20k = 1If b(i) = False Then '如果b(i)=False,表示a(i)没有被统计过For j = i + 1 To 20If a(i) = a(j) Thenk = k + 1b(j) = TrueEnd IfNext jList1.AddItem a(i) & "出现次数:" & kEnd IfNextEnd SubPrivate Sub Command3_Click()Text1 = ""List1.ClearEnd Sub第6章过程一、选择题二、填空题1. 6 .2. 4 20 1013.第一行是 6 26 、第三行是-2 984.第一行10 6 、第二行 5 -55.第一行 6 5 、第三行8 76.第一行11 、第二行77.Fun(i)Fun=p8.第一行 4 、第二行2079.第一行29 、第二行28.710.J=kb( ) As Integerb( k-1) =b(k)i11.第一行gec 、第二行ge 、第四行 312.p1 = True And p2 = True 或p1 And p2= isp(i)Isp = Truem Mod i = 013.Convert(st)Len(s)"A" To "F"k = k + p * h14.isualVisualVisu15.s + an + 1x As Single, n As Integer 、p * (x + i) / ((2 * i - 1) * i * x)16.27617.Left(s, 1)Mid(s, i - 1, 1) = Mid(s, i, 1)n = 1c & CStr(n)18.chtempTrue19.val(mid(s,i,j))n as longprime=True20.A(2,2)的值是 6 ,A(3,1) 的值是8 ;A(4,2) 的值是 321.Option1(i)X22.1023.第一行7 6 ,第二行16 16 ,第三行,4524.第一行15 1 ,第二行35 3 ,第三行,50三、改错题1、Option Base 1Private Sub Command1_Click()Dim A() As Integer, I As Integer, J As Integer, Logic As Boolean Dim K As IntegerReDim A(1)A(1) = 50————————'K=1For I = 51 To 149K = 1 '位置错Logic = FalseCall Sub1(A, I, Logic)If Logic ThenK = K + 1ReDim A(K) 'ReDim Preserve A(K)A(K) = IEnd IfNext IFor I = 1 To UBound(A)Text1 = Text1 & Str$(A(I))If I Mod 5 = 0 Then Text1 = Text1 & vbCrLfNext IEnd SubPrivate Sub Sub1(A() As Integer, N As Integer, F As Boolean) Dim I As Integer, J As Integer, Ub As IntegerUb = UBound(A)For I = 1 To UbFor J = 2 To A(I)If A(I) Mod J = 0 And N Mod J = 0 ThenExit For 'Exit SubEnd IfNext JF = TrueNext IEnd Sub2、Option ExplicitOption Base 1Private Sub Command1_Click()Dim I As Integer, Flg As Boolean, S1 As Integer, S2 As IntegerDim J As Integer, K As Integer, P() As IntegerReDim P(1)P(1) = 2For I = 3 To 150 Step 2For J = 2 To Sqr(I)If I Mod J = 0 Then Exit ForNext JIf J > Sqr(I) ThenReDim Preserve P(UBound(P) + 1)P(UBound(P) + 1) = I 'P(UBound(P)) = IEnd IfNext IFor I = 80 To 125If fun(I, P, S1, S2) Then 'If fun(I, P, S1, S2)Text1 = Text1 & Str$(I) & "=" & Str(S1) & "*" & Str$(S2) & vbCrLf End IfNext IEnd SubPrivate Function fun(N As Integer, P() As Integer, S1 As Integer, S2 As Integer) As Boolean Dim I As Integer, J As IntegerFor I = 1 To UBound(P)For J = 1 To UBound(P) - 1If N = P(I) * P(J) ThenS1 = P(I)S2 = P(J)'fun = TrueExit Functionfun = True '位置错End IfNext JNext IEnd Function3、Option ExplicitPrivate Sub Get_Chess(Chess() As Integer, idx As Integer, Over As Integer) 'ByVal idx As IntegerDim Ub As Integer, Counter As Integer, K As IntegerUb = UBound(Chess)Chess(idx) = 0Counter = 1K = 0 '位置错Do Until Counter = Ub - 1Do Until K = 2idx = idx + 1If idx > Ub Then idx = 1K = K + Chess(idx)LoopChess(idx) = 0Counter = Counter + 1LoopFor Over = 1 To UbIf Chess(Over) <> 0 Then Exit ForNext OverEnd SubPrivate Sub Command1_Click()Dim Chess(32) As Integer, I As Integer, J As IntegerDim K As Integer, idx As IntegerFor I = 1 To 32For J = 1 To 32Chess(J) = 1Next JCall Get_Chess(Chess, I, K)If K = 23 ThenText1 = "从第" & Str$(I) & "号棋子开始取"Exit ForEnd IfNext IEnd Sub4、Option ExplicitPrivate Sub Form_Click()Dim S As String, Flg As BooleanDoS = InputBox("输入一个自然数")If S = "" Or Not IsNumeric(S) ThenMsgBox "请重新输入", 48 + vbOKOnlyElseExit DoEnd IfLoopjudge(S, Flg) ' Call judge(S, Flg) 或judge S, Flg If Flg ThenPrint S; "是回文数"ElsePrint S; "不是回文数"End IfEnd SubPrivate Sub judge(Ch As String, F As Boolean)Dim L As Integer, I As IntegerL = Len(Ch)F = True ' F = FalseFor I = 1 To LIf Mid$(Ch, I, 1) <> Mid$(Ch, L + 1 - I, 1) Then Exit Sub Next IF = False ' F = TrueEnd Sub四、编程题1.Private Function Prime(a As Integer) As BooleanDim i As IntegerFor i = 2 To Sqr(a)If a Mod i = 0 Then Exit FunctionNext iPrime = TrueEnd Function'方法一Private Sub Command1_Click()Dim m As Integer, i As Integerm = InputBox("请输入一个大于2 的偶数")If m <= 2 Or m Mod 2 <> 0 Then MsgBox "请输入大于2的偶数": Exit Sub If Prime(2) And Prime(m - 2) ThenPrint m & "=2 +" & m - 2ElseDoi = i + 1If Prime(2 * i + 1) And Prime(m - (2 * i + 1)) ThenPrint m & "=" & 2 * i + 1 & "+" & m - (2 * i + 1)Exit DoEnd IfLoop While 2 * i + 1 < m - (2 * i + 1)End If'方法二Private Sub Command2_Click()Dim m As Integer, i As Integer, p() As Integer, n As IntegerDim flg As Booleanm = InputBox("请输入大于2的偶数")If m <= 2 Or m Mod 2 <> 0 Then MsgBox "请输入大于2的偶数": Exit Sub ReDim p(1)p(1) = 2n = 1For i = 3 To m - 2 Step 2If Prime(i) Thenn = n + 1ReDim Preserve p(n)p(n) = iEnd IfNext iFor i = 1 To nFor j = 1 To nIf p(i) + p(j) = m ThenPrint m & "=" & p(i) & "+" & p(j)flg = TrueExit ForEnd IfNext jIf flg = True Then Exit ForNext iEnd Sub2.Private Function Fact(a As Integer) As LongIf a = 0 Or a = 1 ThenFact = 1ElseFact = a * Fact(a - 1)End IfEnd FunctionPrivate Sub Command1_Click()Dim n As Integer, m As Integer, result As Singlen = Val(Text1.Text)m = Val(Text2.Text)If n >= m Thenresult = Fact(n) / Fact(m) / Fact(n - m)Text3.Text = resultMsgBox "要求n>=m,请重新输入"Text1.Text = ""Text2.Text = ""Text1.SetFocusEnd IfEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd Sub3.Private Function Istgs(n As Integer) As BooleanDim s As String, L As IntegerL = Len(CStr(n))s = CStr(n ^ 2)If Right(s, L) = n Then Istgs = TrueEnd FunctionPrivate Sub Command1_Click()Dim n As IntegerFor n = 10 To 300If Istgs(n) Then List1.AddItem n & "^2" & "=" & n ^ 2 Next nEnd SubPrivate Sub Command2_Click()EndEnd Sub4.Private Sub Command1_Click()Dim a(3, 4) As Integer, i As Integer, j As IntegerDim m As Integer, mj As IntegerRandomizeFor i = 1 To 3For j = 1 To 4a(i, j) = Int(900 * Rnd + 100)Print a(i, j);Next jPrintNext iFor i = 1 To 3m = 0Call max(a, i, m, mj)Print "第" & i & "行最大值为" & m & ",在第" & mj & "列"Next iEnd SubPrivate Sub max(a() As Integer, i As Integer, m As Integer, maxj As Integer) Dim j As Integerm = a(i, 1): maxj = 1For j = 2 To UBound(a, 2)If a(i, j) > m Thenm = a(i, j)maxj = jEnd IfNext jEnd SubPrivate Sub Command2_Click()EndEnd Sub5.Private Function Judge(n As Integer) As BooleanDim sum As Integersum = yz(n)If yz(sum) = 2 * n Then Judge = TrueEnd FunctionPrivate Function yz(n As Integer) As IntegerDim i As IntegerFor i = 1 To nIf n Mod i = 0 Then yz = yz + iNext iEnd FunctionPrivate Sub Command1_Click()Dim n As IntegerFor n = 1 To 500If Judge(n) Then Print nNext nEnd SubPrivate Sub Command2_Click()EndEnd Sub6.Private Sub Command1_Click()Dim n As Integer, j As Integer, flg As BooleanFor n = 2 To 30flg = FalseFor j = 2 To nIf pfs(j) And n Mod j = 0 Thenflg = TrueExit ForEnd IfNext jIf flg = False Then Print n;Next nEnd SubPrivate Function pfs(n As Integer) As BooleanIf Sqr(n) = Int(Sqr(n)) Then pfs = TrueEnd Function7.Private Function fxs(n As Long) As LongDim i As Integer, s As StringFor i = 1 To Len(CStr(n))s = Mid(CStr(n), i, 1) & sNext ifxs = sEnd Function'判断某数是否为回文数Private Function Hws(n As Long) As BooleanDim i As Integer, s As String, L As Integers = CStr(n): L = Len(s)For i = 1 To Len(s) / 2If Mid(s, i, 1) <> Mid(s, L + 1 - i, 1) Then Exit Function Next iHws = TrueEnd FunctionPrivate Sub Command1_Click()Dim x As Long, t As Longx = InputBox("请输入一个正整数:")t = xDo While Hws(t) = FalsePrint t; "+"; fxs(t); "="; t + fxs(t)t = t + fxs(t)LoopEnd Sub8.Private Function fxs(n As Long) As LongDim i As Integer, s As StringFor i = 1 To Len(CStr(n))s = Mid(CStr(n), i, 1) & sNext ifxs = sEnd FunctionPrivate Sub Command1_Click()Dim n As Long, t As LongFor n = 1 To 999t = fxs(n)If t ^ 2 = fxs(n ^ 2) And n Mod 10 <> 0 And n < t ThenList1.AddItem n & " " & tList2.AddItem n & "^2" & "=" & n ^ 2 & " " & t & "^2" & "=" & t ^ 2 End IfNext nEnd Sub9.Private Function fxs(n As Long) As LongDim i As Integer, s As StringFor i = 1 To Len(CStr(n))s = Mid(CStr(n), i, 1) & sNext ifxs = sEnd FunctionPrivate Function Judge(n As Integer) As BooleanDim i As Integer, L As Integer, a(9) As Integer, t As IntegerIf Sqr(n) = Int(Sqr(n)) ThenL = Len(CStr(n))For i = 1 To Lt = Mid(CStr(n), i, 1)a(t) = 1Next iFor i = 0 To 9Sum = Sum + a(i)Next iIf Sum = L - 1 Then Judge = TrueEnd IfEnd FunctionPrivate Sub Command1_Click()Dim a As IntegerFor a = 300 To 2000If Judge(a) Then List1.AddItem aNext aEnd Sub10.Private Function F(n As Integer) As BooleanDim i As IntegerFor i = 1 To Len(CStr(n))If i Mod 2 = 1 And Mid(CStr(n), i, 1) Mod 2 <> 1 Then Exit FunctionIf i Mod 2 = 0 And Mid(CStr(n), i, 1) Mod 2 <> 0 Then Exit Function Next iF = TrueEnd FunctionPrivate Sub Command1_Click()Dim a(8) As Integer, i As Integer, j As IntegerRandomizeDot = Int(900 * Rnd + 100)For j = 1 To iIf t = a(j) Then Exit ForNext jIf j = i + 1 Theni = i + 1a(i) = tList1.AddItem a(i)If F(a(i)) Then List2.AddItem a(i)End IfLoop Until i = 8End SubPrivate Sub Command2_Click()List1.ClearList2.ClearEnd SubPrivate Sub CmdEnd_Click()EndEnd Sub11.Private Function prime(a As Integer) As BooleanDim i As IntegerFor i = 2 To Sqr(a)If a Mod i = 0 Then Exit FunctionNext iprime = TrueEnd FunctionPrivate Function nx(n As Integer) As IntegerDim i As Integer, s As StringFor i = 1 To Len(CStr(n))s = Mid(CStr(n), i, 1) & sNext inx = Val(s)End FunctionPrivate Sub Command1_Click()Dim n As Integer, t As IntegerFor n = 100 To 900t = nx(n)If prime(n) And prime(t) And n < t ThenList1.AddItem "(" & n & "," & t & ")"End IfNext nEnd SubPrivate Sub Command2_Click()List1.ClearEnd Sub12.Option Base 1Dim a(4, 5) As IntegerPrivate Sub Command1_Click()Dim i As Integer, j As IntegerRandomizeFor i = 1 To 4For j = 1 To 5a(i, j) = Int(Rnd * 90 + 10)Picture1.Print a(i, j);Next jPicture1.PrintNext iEnd SubPrivate Sub Fp(a() As Integer, i As Integer, maxj As Integer, Flg As Boolean) Dim max As Integer, j As Integer, t As Integermax = a(i, 1): maxj = 1For j = 2 To UBound(a, 2)If a(i, j) > max Thenmax = a(i, j)maxj = jEnd IfNext jFor t = 1 To UBound(a, 1)If a(t, maxj) > max ThenFlg = FalseExit SubEnd IfNextFlg = TrueEnd SubPrivate Sub Command2_Click()Dim i As Integer, m As Integer, mj As Integer, f As BooleanFor i = 1 To 4f = Falsem = 0: mj = 0Call Fp(a, i, mj, f)If f = True ThenText1.Text = Text1.Text & "(" & i & "," & mj & "):" & a(i, mj) & vbCrLf End IfNext iEnd SubPrivate Sub Command3_Click()Picture1.ClsText1 = ""End Sub13.Private Sub Command1_Click()Dim a(30) As Integer, i As Integer, j As IntegerDim Flag As BooleanRandomizeDot = Int(900 * Rnd + 100)For j = 1 To iIf t = a(j) Then Exit ForNext jIf j = i + 1 Theni = i + 1a(i) = tText1.Text = Text1.Text + Str(a(i))If i Mod 10 = 0 Then Text1.Text = Text1.Text + vbCrLfIf IsDown(a(i)) ThenList1.AddItem a(i)Flag = TrueEnd IfEnd IfLoop Until i = 30If Flag = False Then List1.AddItem "无降序数"End SubPrivate Function IsDown(n As Integer) As BooleanDim i As Integer, S As StringS = CStr(n)For i = 1 To Len(S) - 1If Mid(S, i, 1) < Mid(S, i + 1, 1) Then Exit FunctionNext iIsDown = TrueEnd FunctionPrivate Sub Command2_Click()List1.ClearText1 = ""End Sub14.Option ExplicitPrivate Sub CmdFind_Click()Dim i As Integer, p As String, st As String, st1 As StringFor i = 100 To 999st = ""If csum(i) = zyz(i, st) Thenp = CStr(i)st1 = Left(p, 1) & "+" & Mid(p, 2, 1) & "+" & Right(p, 1)List1.AddItem i & ": " & st1 & "=" & Left(st, Len(st) - 1)End IfNext iIf List1.ListCount = 0 ThenList1.AddItem "无满足要求的数!"End IfEnd SubPrivate Function csum(m As Integer) As Integer '求各位数字之和Dim i As Integer, p As Stringp = CStr(m)For i = 1 To Len(p)csum = csum + Val(Mid(p, i, 1))Next iEnd FunctionPrivate Function zyz(ByVal m As Integer, st As String) As Integer '求所有质因子之和Dim i As Integeri = 2DoIf m Mod i = 0 Thenzyz = zyz + ist = st & i & "+"m = m \ iElsei = i + 1End IfLoop Until m = 1End Function15.Private Sub Command1_Click()Dim k As Integer, i As Integerk = InputBox("请输入要求的数列项数:")List1.AddItem "共输出前" & k & "项数列"For i = 0 To kList1.AddItem p(i)NextEnd SubPrivate Function p(n As Integer) As IntegerIf n = 0 Or n = 1 Or n = 2 Thenp = 1Elsep = p(n - 2) + p(n - 3)End IfEnd Function第7章文件一、选择题二、填空题1.顺序文件和随机文件2. EOF3. Write和Print4.返回或设置当前的工作目录5.5116.文件的写语句7.Append8.LOF9.关闭10.Pattern11.【1】For Input 【2】#2 【3】Not EOF(2) 12.【1】”END”【2】Text1.Text 或者Text113.【1】Input 【2】ch 【3】Len(mystr) 14.【1】Number 【2】s15.【1】For Append As #1 【2】"end" 【3】ct,nt 16.【1】For Input 【2】For Output As #2 【3】Not EOF(1) 【4】Line Input #1,str1 【5】Close #1,#2 【6】Kill “C:\old.txt 17.【1】Open "C:StuData.txt" For OutPut As #1 【2】Write 18.【1】"C:\data.txt" 【2】#1, a(i) 【3】k>1 And a(k-1)>b 【4】k = k -1三、综合题1.Option Base 1Dim arr(100) As IntegerPrivate Sub Command1_Click()Dim i As IntegerOpen "c:\in18.txt" For Input As #6For i = 1 To 100Input #6, arr(i)Next iClose #6End SubPrivate Sub Command2_Click()Dim i As IntegerText1.Text = ""Open "c:\out18.txt" For Output As #8For i = 1 To 100If arr(i) Mod 2 <> 0 ThenText1.Text = Text1.Text & Str(arr(i))Write #8, arr(i)End IfNext iClose #8End Sub2.Dim str As StringDim n As LongPrivate Sub Command1_Click()CommonDialog1.Filter = "文本文件(*.txt)|*.txt|All Files(*.*)|*.*"CommonDialog1.FilterIndex = 1CommonDialog1.Action = 1Open CommonDialog1.FileName For Input As #2n = LOF(2)str = Input(n, #2)Text1.Text = strClose #2End SubPrivate Sub Command2_Click()Dim i As IntegerFor i = 1 To Len(str)If Asc(Mid(str, i, 1)) <= Asc("Z") And Asc(Mid(str, i, 1)) >= Asc("A") Then Mid(str, i, 1) = LCase(Mid(str, i, 1))ElseIf Asc(Mid(str, i, 1)) <= Asc("z") And Asc(Mid(str, i, 1)) >= Asc("a") Then Mid(str, i, 1) = UCase(Mid(str, i, 1))End IfNext iText1.Text = strEnd SubPrivate Sub Command3_Click()Open "D:\out.txt" For Output As #3Print #3, strClose #3End Sub第8章程序调试一.选择题二.改错题1.a(i)=int(Rnd*19)+1 →a(i)=int(rnd*20)+1For l=1 to a(i)+1 →for i=2 to a(i)+1If l=a(i) →if l <> a(i)K=k+1 →k=k-1。
VB实验指导书-测试题答案
营销1042第1章测试题答案一、AABD第2章测试题答案一、BCDACACC二、1.Gotfocus2.Lostfocus3.Setfocus4.Style,15.S(165)6.Vbp7. 18. ScrollBars三、1.答:Private Sub Form_Click()Form1.BackColor = vbBlue End SubPrivate Sub Form_DblClick() Form1.BackColor = vbRed End Sub2.答:(1)若在设计状态完成:(2)若在运行状态完成:编写窗体的Load事件过程如下:Private Sub Form_Load()Form1.BackColor = vbWhiteLabel1.Caption = "欢迎使用VB6.0!"Label1.ForeColor = vbYellowLabel1.BackColor = vbBlueLabel1.FontName = "黑体"Label1.FontItalic = TrueLabel1.FontSize = 20End Sub第3章测试题答案一、BBDBCADA二、1.True ”cde”2.”bcd”-123.True ”abc123xy”4.A*exp(-2*t)*sin(50*t+ 3) 5.4/3*3.1416*r^3 6.Long & 7.Double # 8.关系逻辑第4章测试题答案一、BBBAB ADBDA ADBAC二、1.判断奇偶数InputBox("输入一个整数")If a Mod 2 = 1 ThenElseMsgBox a & "是偶数"2.计算Y值Val(Text1.Text)x > 100 Thenx > 0 ThenElse3.购物优惠xVB实验指导书测试题答案Is > 5000 Is > 3000 Is > 2000 Is > 1000 Case Else 4.1+2+。
VB实验练习20题记录2
VB实验练习20题记录(2)以下是用VB6实验练习的记录。
目录例子一求100到200之间的所有素数——————- 1例子二-统计某个文本文件中英文字母的个数———————— 2例子三vb 文本框中内容写入文本文件——————-——— 2例子四以下三角的形式输出九九乘法表————-———— 3例子五三数阶乘和————————————4例子六用InputBox$函数输入一个正整数,计算其平方根————— 4 例子七找出不大于1000的最大素数。
——— 4例子八求1+1/2+……1/100的值——— 5例子九用vb中数组的语言编写一个5*5的阵列———— 6例子十把文本文件内容写到TextBox———— 6例子十一计算S的值:s=2+4+6+8+…+100—————7例子十二计算S的值:s=1+2+3+4+5+6+…+100—————7例子十三王大力35————————————————8例子十四列表框项目数在标签中显示出来————8例子十五爱心社两个复选框————9例子十六操作系统三个复选框————10例子十七圆柱面积————10例子十八考试科目数学英语————11例子十九n的阶乘————12例子二十一元二次方程————12例子一:VB编程,求100到200之间的所有素数。
解题的源代码:Private Sub Command1_Click()For i = 101 To 199 Step 2For j = 2 To Sqr(i)If i Mod j = 0 Then Exit ForNextIf j > Sqr(i) ThenPrint i;c = c + 1If c Mod 5 = 0 ThenPrintEnd IfNextEnd Sub例子二:VB编程,统计某个文本文件中英文字母的个数。
2、用vb设计一个应用程序,统计某个文本文件中英文字母的个数,并将统计结果写入另一个文本文件解题的源代码:Private Sub Command1_Click()Dim s As String, x As Strings = ""Open "C:\1.txt" For Input As #1 'word.txt为需统计的文件Do While Not EOF(1)Input #1, xs = s + xLoopClose #1For i = 1 To Len(s)If Asc(Mid(s, i, 1)) >= 65 And Asc(Mid(s, i, 1)) <= 122 Thenn = n + 1 '统计英文个数Elsem = m + 1 '统计中文个数End IfNextOpen "C:\2.txt" For Output As #2 '输出统计结果文件Print #2, "英文个数:" & nPrint #2, "中文个数:" & mClose #2End Sub例子三:vb 文本框中内容写入文本文件。
2012年3月vb实验考试练习题
2012年VB程序设计实验考试练习题(共40题)第一部分简单应用题(20个)1.本题描述如下:解答:添加控件,并按要求修改三个命令按钮的名称和Caption属性,垂直滚动条的名称。
Private Sub C1_Click()VS1.Value = VS1.MinEnd SubPrivate Sub C2_Click()VS1.Value = (VS1.Max + VS1.Min) / 2End SubPrivate Sub C3_Click()VS1.Value = VS1.MaxEnd SubPrivate Sub Form_Load()VS1.Max = 100VS1.Min = 0End Sub2.本题描述如下:Private Sub Command1_Click()EndEnd SubPrivate Sub Form_Load()Text1.Text = ""Command1.Caption = "退出"End SubPrivate Sub Text1_Change()If IsNumeric(Text1.Text) = False Then MsgBox "不可输入非数字字符" Text1.SelStart = 0Text1.SelLength = Len(Text1.Text) End IfEnd Sub3.本题描述如下:解答:首先将计时器的Timer1的Interval属性设置为1000Private Sub Form_Load()Text1.Text = 0Timer1.Enabled = FalseCommand1.Caption = "开始计数"Command2.Caption = "停止计数"End SubPrivate Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()Text1.Text = Text1 + 1End Sub注意:以上方法不是唯一的,对属性的设置(如两个命令按钮的Caption属性设置)也可以在属性窗口中设置。
VB实验书答案
第1章一、选择题1.D 2.C 3.C 4.C 5.B 6.B7.C 8.A 9.D 10.D 11.B 12.A13.D 14.C 15.B 16.D 17.D 18.D19.C 20.A 21.C 22.B 23.B 24.C 25.C 26.C 27.C 28.B 29.B 30.B 二、填空题1.工程2.(1)程序和数据(2)属性3.(1)对象(2)事件4.“按字母顺序”5.(1)窗体(2)控件(3)菜单6.(1)对象属性(2)事件过程7.多8.标准模块9.视图10.对象查看按钮11.窗体布局12.Alt+Q第2章一、选择题1.D 2.B 3.A 4.A 5.D 6.A 7.B 8.C 9.C 10.A 11.B 12.B 13.B 14.B 15.B 16.C 17.A 18.A 19.A 20.B 21.C 22.C 23.A 24.C 25.A 26.C 27.B 28.C 29.D 30.D二、填空题1.(1)Print (2)0,02.(1)左键(2)右键3.(1)窗体(2)Font4.(1)1 (2)MDI父窗体5.Moveable6.(1)在属性窗口中设置(2)在程序代码中设置7.BackColor8.(1)Name (2)Caption9.(1)Print (2)Cls10.工程11.Hide12.Unload13..frm14.工程15.MaxButton第3章一、选择题1.D 2.D 3.A 4.D 5.B 6.B 7.C 8.B9.B 10.C 11.C 12.A 13.D 14.D 15.D 16.A17.B 18.D 19.B 20.C 21.C 22.B 23.D 24.A25.B 26.D 27.D 28.C 29.B 30.C 31.B 32.D33.A 34.B 35.B 36.C 37.D 38.C 39.A 40.C41.A 42.D 43.C 44.B 45.B 46.A47.B 48.D49.B 50.C 51.C 52.B 53.C 54.A 55.A 56.B二、填空题1.(1)窗体(2)图片框(3)Clear2.周期性地自动引发事件3.(1)Enabled (2)Locked4.TabStop5.Name和Caption(或者Name和Text)6.Timer7.Scroll和Change8.(1)0(2)−19.(1)Hide(2)Show10.(1)List(2)Selected11.ASCII码12.(1)Shift (2)Ctrl (3)Alt13.(1)DragMode (2)1 (3)DragMode (4)014.(1)MousePointer (2)99 (3)MouseIcon15.Combo1.List(Combo1.ListIndex)16.Change17.(1)密码验证(2)请输入密码:(3)* (4)验证18.(1)Unload (2)Show19.(1)BorderStyle (2)Shape20.(1)Chk1.Value(2)Text3.Passwordchar = "" (3)Text2.Text 21.(1)选择(2)性别(3)False (4)True22.Pic1.Picture=loadpicture("D:\Pic\Fishing.bmp")23.(1)KeyAscii=13 (2)a<=100(3)Text2.SetFocus (4)Len(Trim(Text1.Text))第4章一、选择题1.B 2.A 3.C 4.C 5.A 6.C 7.A 8.B 9.D 10.B 11.D 12.B 13.A 14.A 15.A 16.A 17.B 18.D 19.B 20.B21.C 22.A 23.C 24.B 25.D 26.C 27.C 28.B 29.A 30.D31.D 32.B 33.A 34.A 35.A 36.D 37.B 38.D 39.A 40.D41.B 42.B 43.D 44.C 45.A 46.D 47.D 48.D 49.A二、填空题1.(1)123 (2)567(3)889 (4)12300(5)02.(1)255 (2)冒号“:”(3)续行符“_”(空格和下划线)3.x>=-5 And x <=54.(1)(X+Y)<10 And (X−Y)>0(2)X*Y>0 And X=Int(X)And Int(Y)=Y(3)X*Y=0 And X+Y<>05.A<>0 And B*B –4*A*C>=06.(1)8888.30(2)628(3)0.67(4)0.57(5)hello(6)THIS IS A GOOD IDEA7.x+y<=8And x−y>88.x <100 And x >=09.x<=−5 or x >=510.6~1011.(1)(x^3-y^3)/(y*(sin(x))^3+7*log(y))(2)Log(y+cos(x)^2)(3)(a^(b*c)+c^(a*b))^(1/3)(4)abs((exp(x)+sin(x)^3)/(x*(x−y)))(5)log((exp(x*y)+abs(tan(z)^(−1)+cos(x)^3))/(x+y+z))12.(1)False(2)False(3)False13.(1)"10"(2)"输入整数"(3)"输入数据:10" (4)"输入的数据是:"第5章一、选择题1.A 2.B 3.D 4.C 5.C 6.C/D 7.C 8.D9.D 10.C 11.B 12.B 13.C 14.C 15.C 16.B 17.B 18.D 19.B 20.D 21.B 22.B 23.D 24.C 25.D 26.B 27.B 28.C 29.C 30.B 31.C 32.D 33.A 34.D 35.D 36.B 37.D 38.D 39.A 40.B 41.C 42.B 43.A 44.A 45.B 46.D 47.B 48.A 49.B 50.C 51.B 52.C 53.C 54.A 55.B 56.C 57.C 58.D 59.C 60.C 61.C 62.B 63.C 64.C 65.D 66.D 67.A 68.B 69.B二、填空题1. −12. −10Trur−613. 6 12312804. BASIC5. (1)6 (2)14 (3)7 (4)13(5)8 (6)3 (7)9 (8)16. (1)Spc(4)(2)Format(Sqr(a),"0.000")7. 3 −38. false9. * *0* *10. (1)a>0 And b>0 And c >0 (2)a<0 And b <0 And c<011. (1)c = Val(InputBox("请输入第三个数"))(2)b > a (3)b < a12. (1)Select Case x (2)Case Else13. (1)Text1 (2)Text1 (3)Form214. (1)Is (2)Else (3)End Select15. (1)Timer1.Enabled (2)Shape2.Top (3)Top (4)Shape2.Left16. 2117. (1)3 (2)−1818. (1)5.6 (2)519. (1)Aa (2)AaBbCc20. 2821.(1)Happy new year! (2)222.(1)For i = 1 To 5000 (2)i Mod 10 = 023.(1)d = d1 * 1000 + d2 * 100 + d3*10 + d4 (2)d = i * 924.(1)s = s + fz / fm (2)fm = fm + t25.(1)Exit Do (2)Right(Str(i),1)26.(1)Int(Rnd * 9 + 1)(2)Int(Rnd * 6 + 5)(3)j = j * 10 + a (4)If i < n Then Print j;"+";Else Print j;27.(1)n = n \ m (2)m = m + 128. If s > Max Then Max = s29.(1)c To 50 (2)b To 100 (3)1 /(a ^ 2)+ 1 /(b ^ 2)= 1 /(c ^ 2)第6章一、选择题1.A 2.C 3.D 4.C 5.A 6.B 7.C 8.C 9.B 10.C二、填空题1.(1)顺序结构(2)选择结构(3)循环结构2.(1)有穷性(2)确定性(3)有零个或多个输入(4)有一个或多个输出(5)有效性3.(1)自顶向下(2)逐步细化(3)模块化设计(4)结构化编码4.(1)伪代码(2)流程图5.模块化第7章一、选择题1.D 2.C 3.D 4.C 5.D 6.C 7.C 8.A9.D 10.C 11.B 12.D 13.B 14.B 15.B 16.B17.C 18.C 19.C 20.D 21.D 22.A 23.A 24.C25.C 26.D 27.D 28.A 29.C 30.A 31.D 32.D二、填空题1.(1)2 (2)6 (3)1 (4)2 (5)−1 (6)1 2.Variant(或变体型)3.454.(1)2 5 (2)3 65.1 2 1 4 46.0 20 25 30 35 407.−1 –2 –3 –4 –50 –1 –2 –3 –41 0 –1 –2 –32 1 0 –1 –23 2 1 0 –14 3 2 1 0s=−158.0 0 0 0 0 12 14 16 18 209.1 2 3 4 5 12 14 16 18 2010.(1)100 (2)10 (3)10 (4)a((I−1)*10+j)11.(1)Int(Rnd * 1000)(2)arr(i)> Max (3)arr(i)< Min 12.(1)preserve a(n)(2)a(I+1)=a(I)(3)a(I)=m (4)a(I+1)=m13.(1)I,J (2)I,I (3)I,5−I14.(1)a(i)= a(i − 1)(2)a(LBound(a))= j1 (3)k = j15.(1)c(2)<"A" or c(2)> "Z" (2)"Z" (3)"A"(4)keyAscii−1(5)keyAscii+116.(1)t = n (2)i To t – 1 (3)i = i + 1(4)b(i)(5)t = t − 117.(1)Redim A(n)(2)P>n or P <1 (3)P+1 (4)D 18.(1)int(Rnd*99+1)(2)In arr (3)x>50 and x <90(4)sum+x (5)x19.(1)Redim a(n,n)(2)1 to n (3)a(j,k)=i (4)Print 20.(1)7 (2)1 (3)16 (4)10 (5)5第8章一、选择题1.D 2.A 3.A 4.B 5.B 6.D 7.D 8.C 9.D 10.A11.A 12.A 13.C 14.D 15.D 16.C 17.D 18.D 19.C 20.A21.A 22.B 23.B 24.A 25.B 26.C 27.D 28.B 29.D 30.C二、填空题1.(1)4 (2)8 (3)162.1 3 14 3 109 27 93.(1)12 (2)18 (3)36 12 18 (4)36 36 124.(1)8 −2 (2)6 −25.(1)15 (2)36 (3)266.(1)34 (2)26 (3)87.3 5 7 9 58.(1)01 05 02 (2)08 (3)039.(1)10 6 (2)5 4 (3)10 −6 10.(1)17 (2)178 (3)17811.3 3 41 3 10 0 11 0 012.1 62 113 1613.(1)11 (2)61 (3)13614.(1)asicB (2)icBas15.(1)1 1 2 (2)1 3 2 (3)1 2 216.(1)Flag或Flag=True (2)Cstr(n)或Trim(Str(n))(3)Mid(x,i,1)< Mid(x,i + 1,1)17.(1)n = i * i(2)List1.AddItem(CStr(n)+ "=" + CStr(i)+ "*" + CStr(i))(3)ByVal n As Long(4)a(n Mod 10)= 1(5)If js = 2 Then Verify = True18.(1)L = 3 − Len(a)Mod 3 (2)n = Len(a)(3)c = c & Zh(b)(4)n = n + Val(Mid(s,p,1))* 2 ^ i 19.(1)Str(n)& "=" (2)P(i)+ P(j)+ P(k)= n (3)Exit Sub (4)idx = idx + 120.(1)n Mod 2 = 1 And n > 1 (2)s = n & "*3+1"(3)Exit Sub (4)Call Yz(n)第9章一、选择题1.D 2.B 3.B 4.C 5.D 6.C 7.C 8.C 9.C 10.B 11.D 12.B 13.D 14.B 15.B 16.B 17.A 18.B 19.C 20.A 21.A 22.A 23.C 24.B 25.B 26.B 27.C 28.C 29.C 30.B 31.C 32.A 33.A 34.D 35.B 36.C 37.A二、填空题1.Put2.Len3.Append4.Lof5.返回一个可供Open语句使用的文件号6.(1)Open "d:\data1.txt" For Random As #1 Len = Len(s)(2)Put #1,,s7.(1)Input (2)Output(3)0 (4)Close #1,#28.(1)For Append As #1 (2)For Input As #2(3)#1,s第10章一、选择题1.A 2.A 3.C 4.A 5.B 6.B 7.D 8.C9.C 10.C 11.A 12.C 13.D 14.D 15.B 16.A17.D 18.B 19.B 20.D 21.A 22.B 23.B 24.B25.D 26.B 27.C 28.C 29.B 30.C二、填空题1.(1)&(2)Alt (3)−2.菜单项显示区3.“→”按钮4.弹出式菜单5.调整菜单项顺序6.(1)Caption (2)Name (3)Index (4)Checked(5)Enabled (6)Visible7.(1)PopupMenu (2)MouseDown8.Ctrl+E9.(1)Height(2)Width10.(1)Microsoft Rich TextBox Control 6.0 (2)64K11.不可见的12.“部件”13.(1)DialogTitle (2)Filter (3)InitDir(4)ShowOpen或Action=1 14.StatusBar15.(1)不能(2)ToolBar。
VB实验复习参考(附详细答案)
1.在窗口中添加一个标签,设置Border Style=1属性为有边框,编写程序代码实现:单击窗体后,标签上显示如图所示的信息,标签文字字体设置为隶书,文字大小20,加粗,倾斜,下画线。
Label1.fontitalic=true label1.fontunderline=true2.在窗体上,按下鼠标左键拖动,在窗体的标题栏中显示鼠标指针的坐标位置。
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button = 1 ThenForm1.Caption = X & "," & YEnd IfEnd Sub3.在两文本框中输入数据,单击等号命令按钮,结果显示在标签中,如图所示。
4.添加2标签和2文本框,运行时在第一个文本框中输入一个字符,然后按回车键,对应字符的ASCII编码值显示在第二个文本框中。
提示:用KeyPress事件,回车键ASCII 值为135.编写程序,调用InputBox函数输入存款的本金X和存款年限N,计算若干年后本金和利息的总和是多少?假设年利率固定为4%,计算公式为:总计=本金*(1+4%)N,计算的结果通过调用MsgBox函数显示。
Private Sub Command1_Click()s = MsgBox(V al(Text1.T ext) * (1 + 0.04) ^ V al(T ext2.T ext))6.Print s7.End Sub8.运行时单击窗口,随机产生一个1000-9999间的整数,判断其是否是6的倍数。
用Print方法把产生的随机数和判断结果显示在窗口上。
(其他倍数判定、奇偶数判定)Private Sub Form_Click()9.Form1.Cls10.Dim i%11.i = Int(Rnd * (9999 - 1000 + 1) + 1000)12.Print i13.If i Mod 6 = 0 Then14.Print "是6的倍数"15.Else16.Print "不是6的倍数"17.End If18.End Sub19.设银行的定期存款利率为:一年期2.52%,二年期3.06%,三年期3.69%,五年期4.14%。
2012级-VB机练13_4_15_pdf
1. 新建工程,界面如下图,将窗体名称改为f1,标题属性为“我的第一个工程”,Text2允许多行,三个命令按钮名称分别为C1、C2、C3,单击C1按钮将Text1的字体改为黑体,Text2 的字体改为隶书。
单击 C2 按钮将 Text1 的文字颜色改为红色,Text2的背景颜色改为蓝色。
单击 C3 按钮结束程序运行。
Text1Text22.新建工程,界面如上图,运行时,鼠标在“改变窗体颜色”按钮上按下时使窗体背景色变为红色,鼠标抬起时使窗体背景色变为绿色。
鼠标在窗体空白地方按下时使 Text1 的内容为“在窗体上按下了鼠标”,鼠标抬起时使Text1的内容为“在窗体上抬起了鼠标”。
3.新建工程,界面如下图,运行时,在文本框Text1中输入内容的同时,在文本框Text2、Text3中显示相同的内容,但字体不同(字体自定)。
4. 设计一个窗体,如上图所示。
当单击某个命令按钮时,对文本框中的文字完成相应的设置。
其中,每单击一次“增大”或“缩小”按钮将使文本框中的文字增大或缩小5磅,“粗体”按钮将使文本框中的文字加粗,“斜体”按钮将使文本框中的文字倾斜,“下划线”按钮将使文本框中的文字加下划线,“删除线”按钮将使文本框中的文字加删除线。
5. 设计一个窗体,如下图所示。
程序中将π定义成符号常量(用 Const ),运行时,输入底面半径r和圆柱高h,然后单击“计算”命令按钮,在相应文本框中显示计算结果。
运算结果为只读。
6. 设计界面如上图所示。
单击“出题”按钮,产生任意两个【1,100】之间的随机整数于Text1、 Text2中,单击“计算”按钮,求两个数的和。
运算结果为只读。
7.设计一个数字钟表程序,界面如图所示。
运行时单击窗体,显示当前的年月日星期及时间。
8.设计一个数学函数程序,界面如图所示。
程序运行时,在文本框中输入任意数值,单击相应按钮标签中显示结果。
文本框始终处于选中状态。
9.请按图设一个大小能自动调整以适应其显示图片的尺寸的图片框(Picture1)以及“显示”和“清空”两个按钮(Command1、Command2)。
程序设计语言VB综合设计题及答案[精选五篇]
程序设计语言VB综合设计题及答案[精选五篇]第一篇:程序设计语言VB综合设计题及答案《程序设计语言VB》综合设计题1.编制程序实现:在窗体上,单击按钮1,在文本框中动态显示当前时间;单击按钮2,则停止动态显示;单击按钮3,清除文本框内容。
提示:可用定时器控制时间,用系统函数Now显示时间(如Text1.Text = Now)。
2.编制程序:求出100-200之间所有可以被3整除的数的总和,将结果用消息框显示输出。
3.编制程序:利用输入框输入10个不同的整数,将它们从小到大排序,并打印输出。
4.编制程序实现:设计在一框架中包含三个复选框,只有当其1,3选中而2未选中时,才在Text1中显示“Hello”字符。
5.编一程序能实现在窗体上打印出如下图所示的图形。
A AAA AAAAA AAAAAAA BBBBBBB BBBBB BBB B 6.编一程序用于判断一正整数是否为素数。
(提示:只能被1和本身整除的正整数称为素数。
为了判断一个数n是不是素数,可以将n被2到sqr(n)之间的所有整数除,如果都除不尽,则n就是素数,否则n是非素数。
)7.选用If和Select判断结构中任意一种编写满足下列条件的计税要求的程序:少于1600元,免税;1601-5000元,征2%的税;多于5000元,超过部分征5%的税。
8.有a、b、c三个数,编一程序实现通过文本框给a、b赋值;再调用能完成a、b比较大小的子过程,用c将大数回传。
要求按值传送a、b。
9.编一程序用于求所有的“水仙花数”。
所谓“水仙花数”是指一个3位数,其各位数字立方和等于该数本身。
例如:153就是一水仙花数,因为153 = 13+53+33。
10.设计一弹出式菜单,用于设置窗体的背景色,背景色包含白色、黄色、红色三种颜色。
11.编写程序实现:输入三角形的三条边a,b,c的值,根据其数值判断能否构成三角形。
如果能,则判断三角形是否是直角三角形,若是则计算该直角三角形的面积。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
2012年VB程序设计实验考试练习题(共40题)第一部分简单应用题(20个)1.本题描述如下:解答:添加控件,并按要求修改三个命令按钮的名称和Caption属性,垂直滚动条的名称。
Private Sub C1_Click()VS1.Value = VS1.MinEnd SubPrivate Sub C2_Click()VS1.Value = (VS1.Max + VS1.Min) / 2End SubPrivate Sub C3_Click()VS1.Value = VS1.MaxEnd SubPrivate Sub Form_Load()VS1.Max = 100VS1.Min = 0End Sub2.本题描述如下:Private Sub Command1_Click()EndEnd SubPrivate Sub Form_Load()Text1.Text = ""Command1.Caption = "退出"End SubPrivate Sub Text1_Change()If IsNumeric(Text1.Text) = False Then MsgBox "不可输入非数字字符" Text1.SelStart = 0Text1.SelLength = Len(Text1.Text) End IfEnd Sub3.本题描述如下:解答:首先将计时器的Timer1的Interval属性设置为1000Private Sub Form_Load()Text1.Text = 0Timer1.Enabled = FalseCommand1.Caption = "开始计数"Command2.Caption = "停止计数"End SubPrivate Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()Text1.Text = Text1 + 1End Sub注意:以上方法不是唯一的,对属性的设置(如两个命令按钮的Caption属性设置)也可以在属性窗口中设置。
4.本题描述如下:解答:首先修改列表框的名称属性为L1,命令按钮的名称属性为C1Private Sub C1_Click()L1.AddItem (Text1.Text)End SubPrivate Sub L1_Click()L1.RemoveItem (L1.ListIndex)End Sub5.本题描述如下:建立如图所示界面,设置适当属性、编写适当程序,程序根据如下公式,由输入的身高计算标准体重。
男:标准体重(kg)= 身高(cm)- 100女:标准体重(kg)= 身高(cm)- 105解答:添加两个标签、两个单选钮和一个命令按钮,设置有关的Caption 属性,添加两个文本框,将文本框的text属性清空。
Private Sub Command1_Click()If Option1.Value = True ThenText2 = Text1 - 100ElseText2 = Text1 - 105End IfEnd Sub6.本题描述如下:解答:添加一个标签,添加一个命令按钮,修改其名称为C1,Caption属性修改为“选课”,再添加三个复选框,将名称分别修改为Ch1、Ch2和Ch3,并设置Caption属性分别为“程序设计”、“数据库原理”、“计算机网络”。
Private Sub C1_Click()s = "我选的课程是"If Ch1.Value Then s = s & Ch1.CaptionIf Ch2.Value Then s = s & Ch2.CaptionIf Ch3.Value Then s = s & Ch3.CaptionLabel1.Caption = sEnd Sub7.本题描述如下:添加一个标签和三个复选框,并按要求修改有关的名称和Caption属性,并将F复选框Chk3的Enabled属性设置为False.Private Sub Form_Load()Label1.FontSize = 14End Sub8.本题描述如下:解答:首先将文本框的Passwordchar属性设置为“*”Private Sub Command1_Click()If LCase(Text1.Text) = "abc" ThenMsgBox ("正确")ElseMsgBox ("错误")End IfEnd Sub9.本题描述如下:Private Sub Text1_Click()Text1.SelStart = 0Text1.SelLength = Len(Text1.Text)End Sub10.本题描述如下:在窗体上使用框架建立一组单选按钮;一个文本框,如图所示。
根据用户选取不同的颜色修改文本框中的显示字体颜色。
注意,3个表示字体颜色的单选框要求用控件数组实现。
添加一个文本框,一个框架控件,并修改其Caption属性,在框架控件中通过复制粘贴的方法创建一个单选按钮控件数组,并修改其Caption属性。
Private Sub Option1_Click(Index As Integer)If Index = 0 ThenText1.ForeColor = vbRedElseIf Index = 1 ThenText1.ForeColor = vbGreenElseText1.ForeColor = vbBlueEnd IfEnd Sub11.本题描述如下:在窗体上有两个文本框和两个命令按钮,程序运行后,在文本框text1中输入字符时显示“*”,单击“显示”按钮,则Text1中的字符显示出来,单击“复制”按钮,则将Text1中的内容复制到Text2中。
Private Sub Form_Load()Text1.PasswordChar = "*"End SubPrivate Sub Command1_Click()Text1.PasswordChar = ""End SubPrivate Sub Command2_Click()Text2.Text = Text1End Sub12.本题描述如下:设计一个窗体Form1,在此窗体上画一个标签Label1,二个复选框控件check1、check2,编写适当的事件过程。
程序运行后,用户可通过这二个复选框改变标签的字体。
Private Sub Check1_Click()If Check1 = 1 ThenLabel1.FontName = "黑体"ElseLabel1.FontName = "宋体"End IfEnd SubPrivate Sub Check2_Click()Label1.FontItalic = Not Label1.FontItalic End Sub13.本题描述如下:注意:修改名称和Caption属性Private Sub C1_Click()Form1.Caption = ""End SubPrivate Sub Form_Load()Command1.Caption = "清除"End Sub14.本题描述如下:注意:添加三个文本框和两个单选钮,并按要求修改两个单选钮的名称和Caption属性Private Sub Form_Load()Text1.Text = "等级考试"Text2.Text = "计算机"End SubPrivate Sub Op1_Click()t = Text1.TextText1.Text = Text2.TextText2.Text = tOp1.Visible = FalseEnd SubPrivate Sub Op2_Click()Text3.Text = Text1.Text + Text2.TextEnd Sub15.本题描述如下:有一个文本框和和三个命令按钮,标题分别为“居中显示”、“文本框下移”、“移动窗体”。
要求程序运行后,在文本框中输入文字,单击“居中显示”按钮,则使文本框中的文字居中显示,单击“文本框下移”,则文本框向下移动10,单击“移动窗体”,则窗体框向右下角移动10,运行结果如图,请编写代码Private Sub Command1_Click() ' 居中显示Text1.Alignment = 2End SubPrivate Sub Command2_Click() ' 文本框下移Text1.Top = Text1.Top + 10End SubPrivate Sub Command3_Click() ' 移动窗体Form1.Move Left + 10, Top + 10End Sub16.本题描述如下:在窗体上画一个名称为Text1的文本框,Text的属性为“改变大小”画一个名称为HS1的水平滚动条,Max、Min、Largechange、Smallchange的属性值分别为30、1、5、2,编写事件过程,程序运行后,拖动滚动条上的滚动框时,文本框中的字体的大小会等于滚动条的Value属性值,停止拖动后,在文本框Text2中显示滚动条的当前值。
解答:添加控件并按要求设置有关的属性Private Sub HS1_Change()Text2.Text = HS1.ValueEnd SubPrivate Sub HS1_Scroll()Text1.FontSize = HS1.V alueEnd Sub17. 本题描述如下:设计一个工程,运行时首先出现一个文本框和两个命令按钮“欢迎(H)”和“时间(T)”按钮。
单击“欢迎(H)”按钮在文本框中显示“欢迎学习VB6.0编程技术”,单击“时间”按钮。
在文本框中显示现在北京时间。
把文本框的multiline属性设置为truePrivate Sub Command1_Click()Text1 = "欢迎使用" + Chr(13) + Chr(10) + "Visual Basic"End SubPrivate Sub Command2_Click()Text1 = "现在北京时间:" + Chr(13) + Chr(10) + Str(Time)End Sub18. 本题描述如下:设计一个工程,使对输入到文本框中的英文字母既可以进行大写转换,也可进行小写转换;还能还原成输入时的状态。