VB实验指导书_理论综合练习题_答案(完结版).doc
【参考文档】vb实验指导书答案-范文word版 (10页)
第6章 过程
一、单选题
二、填空题 2.5 5. 工具 7. &,Click 8. Enabled 9. 窗体
10. 模式,无模式
11. Action
12. CommonDialog1.FileName 13. cdlCCRGBInit 14. Unload,Show 15. 所在窗体的名称 16. 打开 17. Visible 18. 当前 19. 255 20. Show
(6)强制显式声明变量 (7)类 P35 第三章
1. CBAAABCDAD ABBBC ADDBD 2.(1)integer (2)???? (3)text (4)a=0 or b=0 (5)(x+y)*sin(30*3.14/180) (6)int(rnd*100+1)(7)# (8)0
1
C
(9)int(rnd*30+70)(10) CDEF P53 第四章
本文部分内容来自网络整理,本司不为其真实性负责,如有异议或侵权请及时联系,本司将立即删除!
== 本文为word格式,下载后可方便编辑和修改! ==
vb实验指导书答案
篇一:VB程序设计学习与实验指导书答案(包含实验答案)
VB学习与实验指导测试题
参考答案
第一章
第二章
第三章
第四章
第五章
第六章
第七章
第八章
篇二:VB实验指导书答案
(完整版)VB习题册答案()最终版
第一章二、1。
文件/退出2.Alt+Q3.文件/打开工程/打开工程4.vbp/frm5。
Esc第二章二、1。
对象框、属性显示方式、属性列表和属性解释2。
Text1。
text=”Hellor!”3.标准控件/ActiveX控件/可插入对象4。
Top和Left,Width和Height5。
用鼠标单击属性窗口的任何部分;执行“视图”菜单中的“属性窗口”命令;按F4键;单击工具栏上的“属性窗口”按钮;按组合键Ctrl+PgDn或Ctrl+PgUp6.Ctrl/Shift第三章二、1.答案:、ABCD,VB Programming2.答案:建立界面,设置属性、编写代码3.答案:属性窗口,运行4.答案:对象,过程5.答案:工具、选项、选项、自动语法检查6.答案:Frm,Vbp7.答案:工程8.答案:窗体模块,标准模块和类模块第四章二、1.答案:CONTT。
DE+COS(28*3.14/180)2.答案:—3/8 +8*INT(24。
8)3.答案:(8+6)^(4/-2)+SIN(2*3。
14)4.答案:((x+y)+z)*80—5*(C+D)5.答案: A6.答案:17.答案:Good Morning 、 Good Morning8.答案: ABCD 、 HIJK 。
9.答案:CDEF、1110.答案:0、abcdefghijk11.答案:25、8、2001、7、6第五章二、1.答案:Label2.Caption,Text1.Text,Text2。
Text=y2.答案:MsgBox “输入的密码为”&Text2.Text , vbOKOnly, "登录”3.答案:25+32=574.答案:Country &“ “ &City &” “ & CStr(Year(Date))5.答案 Year(Date) &“年“ & Month(Date) &“月" & Day(Date) _ &“日,星期“& WeekDay (Date,vbMonday)第六章二、1.答案:AutoSize2.答案:ScrollBar MultiLine True3.答案:Text1.SetFocus4.答案:0 05.答案:Picture1.Picture=LoadPicture(“pic2.gif”)6.答案:True7.答案:Picture8.答案:Interval9.答案:Enabled10.答案:下拉组合框,简单组合框,下拉列表框 Style 0 1 2 11.答案:下拉列表框12.答案:ItemA和ItemC13.答案:VB14.答案:VB程序设计 VB Programming第七章二、1. __21 38 54__2. sum=14 sum=14 sum=10。
VB实验教材的实验与习题答案
VB实验教材的实验与习题答案第一章VB开发环境与VB概述习题答案习题一、选择题第二章常用控件与界面设计习题答案习题一、选择题第三章实验与习题实验实验3_1…算术运算Private Sub Command1_Click()Const a As Single = 3, b As Single = 2, c As Single = -1, d As Single = 6Dim x As Single, y As Single, z As Single, m As Singlex = 2: y = 1: z = 1: m = 1List1.ClearList1.AddItem a / (b + c / b)List1.AddItem (x + Sqr(x ^ 2 + 1)) ^ (1 / 3)List1.AddItem ((2 * y) / (a * x + b * y) * (a * x - b * y))List1.AddItem 1 + 1 / (1 + 1 / m)List1.AddItem 1 / 2 * (d / 3) ^ (2 * x)List1.AddItem Log(y + Cos(x) ^ 2)List1.AddItem Abs((Exp(x) + Sin(x) ^ 3) / (x + y))List1.AddItem Log((Exp(x * y) + Abs(1 / Tan(z) + Cos(x) ^ 3)) / (x + y - z))List1.AddItem Sin(45 * 3.1415 / 180) + (Exp(10) + Log(10)) / Sqr(x + y + 1) List1.AddItem Log(a) / Log(b)End Sub…关系运算Private Sub Command2_Click()List1.ClearList1.AddItem Mid("Visual Basic", 1, 12) = Right("Language Visual Basic", 12) List1.AddItem "ABCRG" >= "abcde"List1.AddItem Int(134.69) >= CInt(134.9)List1.AddItem 78.9 / 32.77 <= 97.5 / 43.87 And -45.4 > -4.98 List1.AddItem Str(32.345) = CStr(32.345)End Sub…逻辑运算Private Sub Command3_Click()Dim x As Integer, y As IntegerDim C1 As Integer, C2 As Integer, C3 As IntegerC1 = 70: C2 = 80: C3 = 90x = 9: y = -2List1.ClearList1.AddItem x + y < 10 And x - y > 0List1.AddItem (x% >= 0 And y% >= 0) Or (x% < 0 And y% < 0)List1.AddItem x = 0 Xor y = 0List1.AddItem C1 + C2 + C3 >= 255 Or C1 > 90 And C2 > 90 And C3 > 80 End Sub实验3_2略实验3_3略实验3_4…零售结算Private Sub Command1_Click()Dim dj As Single, sl As Single, je As Single, n As IntegerLabel1.Caption = "金额:"dj = InputBox("请输入商品的单价:", "单价框")sl = InputBox("请输入商品的数量:", "数量框", 1)je = dj * sln = MsgBox("共计金额=" & je, vbOKCancel + vbInformation, "结果") If n = vbOK Then Label1.Caption = "金额:" & Str(je) & "元"End Sub…产生随机数Private Sub Command2_Click()Dim m As Integer, n As IntegerDim x1 As Integer, x2 As Integer, x3 As Integerm = V al(Text1.Text): n = Text2.TextRandomizex1 = Int(Rnd * (n - m + 1) + m)x2 = Int(Rnd * (n - m + 1) + m)x3 = Int(Rnd * (n - m + 1) + m)Label4.Caption = "结果为:" & Str(x1) & Str(x2) & Str(x3)End Sub…求逆序数Private Sub Command3_Click()Dim a As Integer, h As Integer, t As Integer, n As IntegerRandomizea = Int(Rnd * (999 - 100 + 1) + 100)h = Mid(CStr(a), 1, 1)t = Mid(CStr(a), 2, 1)n = Right(CStr(a), 1)Label5.Caption = a & "-->" & Format(n * 100 + t * 10 + h, "000")End Sub实验3_5略习题选择题1-20: DBBDB DDBCA DDDCD DB A DB21-40: DCDAA B_ACA BCADA B_BCD41-60: BCBDC CADBA CBDDD ABAAA61-80:BBCAB BDAAA CBBDD CBDAD81-89:CBDBB BADC填空题1、2 -32768~327672、整型长整型单精度双精度3、0 False “”4、Chr(Int(Rnd*(Asc(“L”)-Asc(“C”))+Asc(“C”)))x>0 And y>0 Or x<0 And y<0c>=”a” And c<=”z” Or c>=”A” And c<=”Z”x>=10 And x<20x<z<="">5、False2TrueFalseTrueTrueTrueTrue6、18820010068.568765547、a=1 b=1a=2 b=1a=3 b=1a=4 b=18、Y Mod 4=0 And Y Mod 100<>0 Or Y Mod 400 =09、He Said, “Good morning”.10、EDEF11、(A>0 And A<>Int(A)) And (B<0 And B<>Int(B))12、a+b+c+d(a+b+c+d)/4sumaver13、(f-2*h)/2(4*h-f)/2简答题1、略2、Private Sub Form_Click()Const g = 9.8Dim V0 As Single, t As SingleDim S As SingleV0 = InputBox("请输入V0的值:")t = InputBox("请输入时间t的值:")S = (1 / 2) * g * t ^ 2 + V0 * tMsgBox ("位移量为:" & S)3、Private Sub Command1_Click()Dim l As Single, w As Single, h As Single Dim s As Singlel = Text1.Textw = Text2.Texth = Text3.Texts = (l * w + l * h + w * h) * 2Label1.Caption = sEnd Sub第四章选择分支与循环实验答案实验4-1方法一:x<=5 ; y方法二:Is<=2 ;Case Else实验4-2Shape1.BackColor=vbRed;Inter=15;Inter=Inter-1;Inter;实验4-3b<c< p="">b=aa=k实验4-4方法二:s*n ; t/s<10^-5实验4-5方法一:m>=10^-4 ; (-1)^(n+1)*m实验4-6x2=x3 ; <10^-6实验4-7i+2*j+5*k=10 ; n实验4-9题目一:a) 5b)i=16 p=12 n=5c)i=9 p=8 n=1题目二:120 10实验4-10N=1 ;S=N& "*3 " & "+1 "实验4-11Len(st); Ch=Lcase(ch) ; Case Else ; Mid(Char,I,1)&St 实验4-12i\100 ; (i Mod 100)\10习题一、选择题1.C 2. C 3.A 4. D 5.A 6. B 7. B 8. D 9. B 二、填空题1.Is=0 ; 1 To 10 ; Is >102. 93. 3 ; 4 154. this is a book ;This Is A Book5. 3 ; 3 ; 3 56. 32 07. 48. 15 19. 1 ; 401 ;10410. 1 2 3 ;1 3; 111. (3)12. 2 0 2413. 10 1414. BAABC CBAABC15. X Mod P=0 ; X=X+1 ;Find=False16. abs(t)<10^(-7) ; s+t17. Mid(n,1,1)=Mid(n,2,1) And Mid(n,3,1)=Mid(n,4,1) S=S+118. Mid(n,i,1)>Mid(n,i+1,1)19. "输入n";N/I=0 ;Print I</c<>。
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函数,其功能是将一字符串用分界符分割为一字符串数组。
【精选资料】VB综合练习题二及参考答案
VB综合练习题二一、选择题[ (1)—(15),每小题2分,共30分](1)以下变量名中合法的是A)x2-1 B)print C)str_n D)2x(2)在Viusal Basic中,表达式3 * 2 \ 5 Mod 3的值是A)1B)0C)3D)出现错误提示(3)设窗体文件中有下面的事件过程:Private Sub Command1_Click()Dim sa%=100Print aEnd Sub其中变量a和s的数据类型分别是A) 整型,整型B) 变体型,变体型C) 整型,变体型D) 变体型,整型(4)把数学表达式表示为正确的VB表达式应该是A) (5x+3) / (2y-6) B) X*5+3 / 2*y-6C) (5*x+3)÷(2*y-6) D) (x*5+3)/(y*2-6)(5)“x 是小于105的非负数”,用Visual Basic表达式表示正确的是A) 0<=x<105 B) 0<=x<=105C) 0<=x And x<105 D) 0<=x Or x<105(6)代码“Print “Sqr(16) = “;Sqr(16) ”的输出结果是A) Sqr(16) = Sqr(16) B) Sqr(16) = 4C) ”4” = 4 D) 4 = Sqr(16)(7)设a = "MicrosoftVisualBasic" ,则以下使变量b的值为“VisualBasic”的语句是A) b = Left(a, 10) B) b = Mid(a, 10)C) b = Right(a, 10) D) b = Mid(a, 10, 11)(8)在Visual Basic代码中,将多个语句合并写在一行上的并行符是A) 撇号(') B) 冒号(:) C) 感叹号(!) D) 星号(*)(9)当我们输入代码时,Visual Basic可以自动检测______错误。
VB程序设计学习与实验指导答案-推荐下载
对全部高中资料试卷电气设备,在安装过程中以及安装结束后进行高中资料试卷调整试验;通电检查所有设备高中资料电试力卷保相护互装作置用调与试相技互术关,系电通,力1根保过据护管生高线产中0不工资仅艺料可高试以中卷解资配决料置吊试技顶卷术层要是配求指置,机不对组规电在范气进高设行中备继资进电料行保试空护卷载高问与中题带资2负料2,荷试而下卷且高总可中体保资配障料置2试时32卷,3各调需类控要管试在路验最习;大题对限到设度位备内。进来在行确管调保路整机敷使组设其高过在中程正资1常料中工试,况卷要下安加与全强过,看度并25工且52作尽22下可护都能1关可地于以缩管正小路常故高工障中作高资;中料对资试于料卷继试连电卷接保破管护坏口进范处行围理整,高核或中对者资定对料值某试,些卷审异弯核常扁与高度校中固对资定图料盒纸试位,卷置编工.写况保复进护杂行层设自防备动腐与处跨装理接置,地高尤线中其弯资要曲料避半试免径卷错标调误高试高等方中,案资要,料求编试技5写、卷术重电保交要气护底设设装。备备置管4高调、动线中试电作敷资高气,设料中课并技3试资件且、术卷料中拒管试试调绝路包验卷试动敷含方技作设线案术,技槽以来术、及避管系免架统不等启必多动要项方高方案中式;资,对料为整试解套卷决启突高动然中过停语程机文中。电高因气中此课资,件料电中试力管卷高壁电中薄气资、设料接备试口进卷不行保严调护等试装问工置题作调,并试合且技理进术利行,用过要管关求线运电敷行力设高保技中护术资装。料置线试做缆卷到敷技准设术确原指灵则导活:。。在对对分于于线调差盒试动处过保,程护当中装不高置同中高电资中压料资回试料路卷试交技卷叉术调时问试,题技应,术采作是用为指金调发属试电隔人机板员一进,变行需压隔要器开在组处事在理前发;掌生同握内一图部线纸故槽资障内料时,、,强设需电备要回制进路造行须厂外同家部时出电切具源断高高习中中题资资电料料源试试,卷卷线试切缆验除敷报从设告而完与采毕相用,关高要技中进术资行资料检料试查,卷和并主检且要测了保处解护理现装。场置设。备高中资料试卷布置情况与有关高中资料试卷电气系统接线等情况,然后根据规范与规程规定,制定设备调试高中资料试卷方案。
VB编程实验报告答案 完整版
实验一:一、选择1.D2.D3.B4.A5.B6.C7.CD8.D9.D 10. BC11. A 12.D 13. D 14. C 15. A二、填空1.windows2. 中断3.工具箱4.代码5.分类6.form2.show7. 出现语法错误8. 错9. 事件10. 面向对象11.工程文件结构12. 工程13. 设计程序代码14. 双击窗体15. C:\Program Files\Microsoft Visual Studio\VB98 或者VB的安装文件夹16.属性17.方法18.font 19. form_load() 20.对象实验二:一、选择1.B2.C3. B4.C5.C6.C7.B8.B9.D 10. A11. C 12.C 13. C 14. B 15. A16.C 17.B 18.D 19.C 20. C二、填空1. Form_Click()2. Interval、50003..vbp .frm4.left top Height、Width twip5.picture6.load7. locked8. font Alignment9. GotFocus() LostFocus() 10. 属性窗口程序代码实验三:一、选择1.A2.BC3.BC4.A5.A6.A7.BCD8.D9.B 10. B11. B二、判断题不合法的变量:3. 4. 5. 6. 8. 10. 11. 14.15. 16.三、1、abs(x+y)2. (3+x*y)^23. (-b+sqr(b^2-4*a*c))/(2*a)4.sin(30*3.14/180)+exp(2)四、1. int(rnd* 71+20) 或int(rnd* 71)+202. x<0 and y>0 or x>0 and y<0 或者x*y<03. x mod 3=0 or x mod 7=0或x/3=x\3 or x/7=x\74. x>=10 and x<205. x>="A" and x<="Z"6. left(s,3)实验四:一、选择1.C2.D3. C4.D5.A6.D7.B8.B9.A 10. C二、填空1. 48.71E-01, -4.87122. 关系、逻辑、算术3. 900,100,mid(s,2,1)4.m、1,2,3 、print m & "月是第二季度"、end select 三、1. X=4 y=132. 10实验五一、选择B C B A C二、填空(1)for x=2 to 10s*(1-1/x)(2) 1 t>1E-6(3) j t(4) 5 11 5实验六一、选择B C C C D D D D C A实验七一、选择1C 2C 3D 4A 5B 6D 7AB 8A 9A 10A 二、填空(1)n!(2)1+1+2+3+4+……+n(3)n是否是素数(4)冒泡排序(5)递归调用产生斐波那契数列(6)求最大公约数和最小公倍数第八页编程2-1Private Sub Command1_Click()Label3 = Val(Text1) * Val(Text2)End SubPrivate Sub Command2_Click()Label3 = Val(Text1) / Val(Text2)End Sub2-2Private Sub Command1_Click()Picture1.Picture = LoadPicture("d:\tu1.jpg") End SubPrivate Sub Command2_Click()Picture1.Picture = LoadPicture("d:\tu2.jpg") End SubPrivate Sub Command3_Click()Picture1.Visible = FalseEnd Sub2-5Private Sub Form_Load()Image1.Picture = LoadPicture("C:\Documents and Settings\All Users\Documents\My Pictures\示例图片\Sunset.jpg")End SubPrivate Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Image1_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()Image1.Left = Int(Rnd * (Form1.ScaleWidth - Image1.Width)) Image1.Top = Int(Rnd * (Form1.ScaleHeight - Image1.Height)) End Sub第11页编程2-3Private Sub Command1_Click()Dim x%, y%x = Int(Rnd * 900 + 100)Print "产生的随机数:"; xy = (x Mod 10) * 100 + (x \ 10 Mod 10) * 10 + x \ 100Print "反序数:"; Format(y, "000")End SubPrivate Sub Command2_Click()Dim x%, y As Stringx = Int(Rnd * 900 + 100)Print "产生的随机数:"; xy = Trim(Str(x))Print "反序数:" & Right(y, 1) & Mid(y, 2, 1) & Left(y, 1)End SubPrivate Sub Form_Load()End Sub2-4Private Sub Command1_Click()Dim m%, n%Randomizem = Val(Text1): n = Val(Text2)x = Int(Rnd * (n - m + 1) + m)y = Int(Rnd * (n - m + 1) + m)z = Int(Rnd * (n - m + 1) + m)Label3 = m & "到" & n & "之间的3个随机数为: " & x & Space(3) & y & Space(3) & zEnd SubPrivate Sub Form_Load()End Sub2-5Private Sub Command1_Click()Label1.Caption = DateEnd SubPrivate Sub Command2_Click()Label2.Caption = TimeEnd SubPrivate Sub Command3_Click()Label3.Caption = WeekdayName(Weekday(Date)) End SubPrivate Sub Form_Load()End Sub第十五页2-1方法一Private Sub Command1_Click()Dim x!, a!, aa%, b!, bb%, c!, cc$x = Val(Text1)a = x * 180 / 3.14aa = Int(a)b = (a - aa) * 60bb = Int(b)c = (b - bb) * 60cc = Format(c, "#.000")Label2 = "弧度" & Text1 & "转换为" & aa & "度" & bb & "分" & cc & "秒"End Sub方法二Private Sub Command1_Click()x = InputBox("请输入弧度数值", "弧度转换", 0)xx = Val(x)a = x * 180 / 3.14aa = Int(a)b = (a - aa) * 60bb = Int(b)c = (b - bb) * 60cc = Format(c, "#.000")MsgBox "弧度" & x & "转换为" & aa & "度" & bb & "分" & cc & "秒"End Sub2-2Private Sub Command1_Click()Dim x%x = Val(Text1)If x / 400 = x \ 400 Or x Mod 4 = 0 And x Mod 100 <> 0 ThenLabel2 = Text1 & "年是闰年"ElseLabel2 = Text1 & "年不是闰年"End IfEnd Sub2-3方法二Private Sub Command1_Click()Dim x%, y%, z%x = InputBox("输入第一个数")y = InputBox("输入第二个数") z = InputBox("输入第三个数") If x > y Then t = x: x = y: y = t If y > z Then t = y: y = z: z = t If x > y Then t = x: x = y: y = t Print x, y, zEnd SubPrivate Sub Form_Load()End Sub方法一Private Sub Command1_Click() Dim x%, y%, z%x = Val(Text1)y = Val(Text2)z = Val(Text3)If x > y Then t = x: x = y: y = t If y > z Thent = y: y = z: z = tIf x > y Thent = x: x = y: y = tEnd IfLabel1 = x & Space(5) & y & Space(5) & z End Sub2-4方法一Private Sub Command1_Click()x = Val(InputBox("请输入上网时间:"))If x <> -1 ThenSelect Case xCase Is < 10fei = 25Case 10 To 50fei = x * 2Case 50 To 100fei = x * 1.5Case Is >= 100fei = x * 1End SelectMsgBox "上网费用为:" & fei & "元"End IfPrivate Sub Command2_Click()EndEnd SubPrivate Sub Form_Load()End Sub方法二Private Sub Command1_Click()Dox = Val(InputBox("请输入上网时间:", , -1)) If x <> -1 ThenSelect Case xCase Is < 10fei = 25Case 10 To 50fei = x * 2Case 50 To 100fei = x * 1.5Case Is >= 100fei = x * 1End Selectzongfei = zongfei & Space(3) & fei MsgBox zongfei, , "上网费用为" ElseExit DoEnd IfLoopEnd SubPrivate Sub Command2_Click() EndEnd SubPrivate Sub Form_Load()End Sub2-5第18页2-3Private Sub Command1_Click()n = 0DoIf n Mod 2 = 1 And n Mod 3 = 2 And n Mod 5 = 4 And n Mod 6 = 5 And n Mod 7 = 0 Then Exit Don = n + 1LoopPrint nEnd Sub]2-5Private Sub Command1_Click()x = Val(Text1)y = x * 4n = 0Do While x <= yx = x * (1 + 0.1)n = n + 1Print xLoopPrint x, nEnd Sub2-6Private Sub Command1_Click()n = Val(InputBox("输入计算到第几项:", , 0)) For i = 1 To ns = s + (-1) ^ (i + 1) * iNextPrint n, sEnd SubPrivate Sub Form_Load()-8End Sub2-8Private Sub Command1_Click()Dim s As Double, pi As Doublen = 1: s = 0Do While 1 / (2 * n - 1) >= 0.0001s = s + (-1) ^ (n + 1) * 1 / (2 * n - 1)n = n + 1Looppi = 4 * sPrint piEnd Sub2-9Private Sub Command1_Click()For n = 100 To 999k = Trim(Str(n))If n = Left(k, 1) ^ 3 + Mid(k, 2, 1) ^ 3 + Right(k, 1) ^ 3 Then Print nNextEnd Sub2-11Private Sub Command1_Click()s = 0: Max = 0: Min = 1000For i = 1 To 20Randomizex = Int(Rnd * 50 + 51)Print x;If x > Max Then Max = xIf x < Min Then Min = xs = s + xNext iaver = s / 20PrintPrint "max="; Max, "min="; Min, "aver="; aver End SubPrivate Sub Form_Load()End Sub。
vb实验指导后题目-参考答案
期末自测题(A卷)文件部分的选择题要做,其它类型的题目不用做,不作考察选择题其它部分还没有时间做一、单选题(每题1分,共25分)1、211.66.160.1 是Internet上的( )。
(A) IP地址 (B)域名 (C)密码 (D)软件编号2、在以下四个www网址中,()网址不符合www网址书写规则。
(A) (B) (C) (D) 3、下列字符中,其ASCII码值最小的一个是()。
(A) A (B) a (C) Z (D) X4、下列软件中属于浏览器的是()。
(A) Excel (B) Internet Explorer (C) QQ (D) Visual Basic5、电子邮件(E-mail)地址的正确形式是()。
(A)用户名@域名 (B)用户名#域名 (C)用户名/域名 (D)用户名.域名6、下面变量名不合法的是()。
(A) a2 (B) abcd (C) a$x (D) Cd_E7、下列表达式中,正确的Visual Basic表达式是()。
(A) 2sin45° (B) ∏*R2 (C) x÷y×5 (D) (x+1)/(x^2+1)/28、下面逻辑表达式的值为真的是()。
(A) "A"> "a" (B) "abc"> "bc"(C) "That"> "Thank" (D) 12> 12.19、下列过程定义语句说明不合法的是()。
(A) Sub f1(ByRef n() As Integer) (B) Sub f1(ByRef n As Integer)(C) Sub f1(ByVal n() As Integer) (D) Sub f1(ByVal n As Integer)10、执行下面的4个打印语句,将出错的是()。
VB学习指导练习题答案
练习题一参考答案1.3.1 单项选择题1.3.2 多项选择题1.3.3 分析判断题1.3.4 程序设计题【习题1-49】编写一个华氏温度F 与摄氏温度C 之间转换的应用程序,界面如图1-4所示。
其中F 与C 之间的关系为:3259+=C F 。
参考程序如下:Private Sub Command1_Click() Dim f As Single, c As Single f = V al(Text1.Text) c = (f - 32) * 5 / 9 Text2.Text = Str(C) End SubPrivate Sub Command2_Click() Dim f As Single, c As Single c = V al(Text2.Text) f = 9 / 5 * c + 32 Text1.Text = Str(f)End Sub【习题1-50】编程将弧度值转换为角度值(度、分、秒)的形式,然后在窗体上显示出来。
程序运行界面如图1-5所示。
【提示】利用InputBox()输入弧度值,首先把弧度值转换为原始角度值,然后取整得到角度值,再把原始角度值减去度值,将结果转化为分值,采用类似思维即可求出结果。
参考程序如下:Private Sub Form_Click()Dim s As Single, a As Integer, b As Integer, c As Integer Const pi As Single = 3.14159图1-4 华氏温度与摄氏温度的转换图1-5 弧度值转换为角度值s = V al(InputBox("请输入弧度值:")) s1 = s s = s * 180 / pi a = Int(s) s = s - a s = s * 60 b = Int(s) s = s - bc = s * 60Print "输入的弧度值" & s1; "对应的角度值为:" Print a & "度" & b & "分" & c & "秒。
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程序设计》实验指导书
《VB程序设计》实验指导书18学时实验一VB集成环境及简单应用程序的建立一、实验目的1.掌握Visual Basic启动和退出的方法。
2.熟悉Visual Basic的集成开发环境。
3.掌握Visual Basic程序设计的基本步骤。
4. 掌握窗体的使用方法。
二、实验内容1 启动Visual Basic,然后创建一个“标准 EXE”工程。
了解Visual Basic集成开发环境下各组成部分及其作用。
【要求】(1)在集成开发环境中分别寻找“窗体窗口”、“属性窗口”、“工程资源管理器”、“窗体布局窗口”、“工具箱窗口”,熟悉它们的默认位置。
(2)在“视图”或“工程资源管理器”中切换显示“代码窗口”和“窗体窗口”。
(3)在“视图”菜单中点击“立即窗口”,观察刚刚显示出来的“立即窗口”。
(4)尝试分别将各部分关闭,然后再用“视图”菜单中对应的菜单命令将其显示。
2 编写一个简单的应用程序。
要求窗体的标题为“简单VB实验”;窗体中有一个标题为“显示”的按钮;单击该按钮后在窗体上显示蓝色的“江西农业大学”。
【步骤】(1)设计应用程序的界面;(2)设置对象的属性;(3)编写事件代码;(4)程序的运行及保存。
【提示】在窗体上显示“江西农业大学”有两种方法:(1)用Print方法:颜色应该设置窗体的前景色。
(2)用一个标签控件:颜色应该设置标签控件的前景色。
【思考】为什么在以上两种方法中在颜色的设置问题上有所不同?3 窗体无最大化和最小化按钮。
在窗体装入时,在窗体的标题栏显示“装入窗体”,并在窗体上装入一幅图片作为背景;当用户单击窗体,在标题栏显示“鼠标单击”,在窗体上显示“单击窗体”;当用户双击窗体,在标题栏显示“鼠标双击”。
去除窗体的背景图案,并显示“双击窗体”。
实验二VB常用控件的使用一、实验目的1.掌握基本控件(标签、命令按钮和文本框)的基本使用方法。
2. 掌握Visual Basic程序设计的基本步骤。
二、实验内容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实验书答案
第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综合卷及答案
VB综合试卷(满分100分)姓名:班级:分数:一、选择题(共30小题,每小题2分,共60分)1.下列运算结果中,值最大的是()A.3\4B.3/4C.4mod3D.3mod42.在窗体中添加一个命令按(command1)和一个文本框(名称为text1),并编写如下程序代码:private sub command1_click()dim a as integer,y as integer,z as integerx=1:y=2:z=3x=y:y=z:z=xtext1.text=str(z)end sub程序运行过程中,用户单击命令按钮command1后,文本框text1中显示()A.0B.1C.2D.33.下面程序执行的结果是()private sub form_click()a=”123”:b=”456”c=val(a)+val(b)print c\100end subA.123B.3C.5D.5794.下列逻辑运算结果为“true”的是()A.false or not trueB.false and not trueC.true or not trueD.true and not true5.设有以下程序,当程序运行时,单击窗体,则在窗体上输出结果为()private sub form_click()dim s as integer,c as strings=100:c=”xyz”s%=200:c$=”abc”print s;s%;:print c;c$end subA.100200xyzabcB.100100xyzxyzC.200200abcabcD.100200abcxyz6.以下程序段执行后,整型变量n的值为()y=2001n=y\4+y\400-y\100A.495B.505C.500D.4857.表达式lcase(“AB12”)>left(“abc”,2)and len(“12.3”)=5的值是()A.trueB.falseC.0D.18.在visual basic中,打印机也是一种对象,其名称为()A.printB.printerC.printformD.printor9.表达式2*4^2-2*6/3+3\2的值是()10.在程序中添加一个命令按钮,并编写如下程序代码:private sub command1_click()x=”123.5”y=”-100”z=x+yprint val(z)end sub程序运行时,单击命令按钮后,在窗体上的输出结果为()A.23.5B.123.5C.100D.123.510011.在VB中,下列运算符中优先级最高的是()A.*B.\C.<D.Not12.下列逻辑表达式中,其值为true的是()A.”abc”>”ABC”B.”THAT”>”THE”C.9>”h”D.”A”>”a”13.在窗体上画一个文本框,其名称为Text1,为了在程序运行后隐藏该文本框,应使用的语句为().A.text1.clearB.text1.visible=falseC.text1.hideD.text1.enabled=false14.下列各组变量声明正确的是()A.dim abc as integer,num as singleB.dim l%,n$as integerC.dim a%,b%,c%,a$D.public dim n%15.visual basic表达式sqr(a+b)^3*10中优先进行运算的是()A.sqr函数B.+C.-D.*16.在窗体上画一个命令按钮(名称为command1),然后编写如下事件过程:Private sub command1_click()Dim b as integerB=b+1End sub运行程序,单击命令按钮3次后,变量b的值是()A.0B.1C.2D.317.如果x为一正实数,对x的小数点后第4位进行四舍五入的表达式是()A.0.001*int(x+0.005)B.0.001*int(1000*(x+0.0005))C.0.001*int(1000*9x+0.005))D.0.001*int(x+0.005)18.在表示日期常量时,用符号()将日期型数据括起来。
VB实验作业参考答案
1)单击窗体后在窗体上显示“您好!×××同学”。
要求:(1)程序中用自己的姓名替代“×××”。(2)文字以红色、仿宋体、加粗、三号字显示,并在字下加横线。(3)建立一个命令按钮,结束时单击此按钮退出。
答案参照课本P27的例1-6。
2)设计一窗体,窗体上有1个文本框(Text1)、1个命令按钮(Command1),运行时文本框中显示“Visual Basic程序设计”,命令按钮标题为“结束”,文本框及命令按钮能随窗体大小的调整而自动调整大小及位置,其中调整文本框使其:Left=0,Top=0,宽度和高度都为窗体的一半;命令按钮:始终位于窗体右下角位置。请编写:
Command1.Top = Form1.ScaleHeight - Command1.Height
End Sub
Private Sub Form_Resize()
Call Form_Load
End Sub
Private Sub Command1_Click()
End
Dim r1 As Single, r2 As Single, Rp As Single, Rs As Single
r1 = InputBox("请输入第一个电阻值:")
r2 = InputBox("请输入第二个电阻值:")
Rp = (r1 * r2) / (r1 + r2)
Rs = r1 + r2
程序代码:
Private Sub Command1_Click()
Dim sg As String, tz As String, bz As String
sg = Text1.Text
VB综合练习题及答案
Visual Basic 期末复习题库 单项选择题 判断题 填空题 编程题1) 下列程序运行后,输出的结果为______。
B=1 Do while (b<40) b=b*(b+1) Loop Print b a) 42 b) 39 c) 6 d) 1 2) 设执行以下程序段时依次输入1、3、5,执行结果为_____。
Dim a(4) As Integer Dim b(4) As Integer For K =0 To 2 a(K+1) =Val(InputBox(“请输入数据:")) b(3-K) =a(K+1) Next K Print b(K) a) 1 b) 3 c) 5 d) 0 3) 下列程序执行后,变量s 的值为______。
Dim s As long ,x As Integers=0:x=1Do While (x<10) s=s+xx=x+2LoopPrint sa) 10 b) 25 c) 50 d) 1004) 编写如下事件过程:Private Sub Form_MouseDown(Button AsInteger ,Shift As Integer,X As Single,Y As Single)If Shift=6 And Button=2 Then Print "Hello" End If End Sub 程序运行后,为了在窗体上输出"Hello",应在窗体上执行以下_______操作。
a) 同时按下 Shift 键和鼠标左键 b) 同时按下 Shift 键和鼠标右键 c) 同时按下Ctrl 、Alt 键和鼠标左键d) 同时按下 Ctrl 、Alt 键和鼠标右键 5) 当变量x=2,y=5时,以下程序的输出结果为____。
Do until y>5 x=x*yy=y+1loop print x a) 2 b) 5 c) 10 d) 20 6) 当执行以下程序时,在名为lblResult 的标签框内将显示_____。
【参考文档】vb实验指导书答案-范文word版 (10页)
Dim b As Single Dim c As Single Dim y As Single a = 5 b = 2.5 c = 7.8
y = (a * b * 3.14) / (a + b * c) Print y End Sub
2. 参考代码如下:
Private Sub Form_Click() Dim a As Single Dim b As Single Dim c As Single Dim d As Single
本文部分内容来自网络整理,本司不为其真实性负责,如有异议或侵权请及时联系,本司将立即删除!
== 本文为word格式,下载后可方便编辑和修改! ==
vb实验指导书答案
篇一:VB程序设计学习与实验指导书答案(包含实验答案)
VB学习与实验指导测试题
参考答案
第一章
第二章
第三章
第四章
第五章
第六章
第七章
第八章
篇二:VB实验指导书答案
A
14. C 15. C 16. D 17. B 18. A 19. C 20. A 21. A 22. B 23. D 24. C 25. C 26. B 27. D 28. A 29. B 30. A 31. D 32. C
33. D 34. D 35. A 36. A 37. A 38. D 39. B 40. B 41. B 42. B 43. C 44. C 45. C 46. B 47. B 48.
2
4. sq(x As Integer),Function 5. Val(t.Text) 6. 30,70 7. 5
9. 30
10. nAA N, X ,N1,nT1 * X1
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第二部分综合练习
理论练习一
一单选
1-5 CDCCB 640ABDCD 11-15 CCBBD 16-20 DBCBA
二多选
1 ABCE 2CE 3 BCE 4 ADE 5 ABCD
6ABCDE 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/8
2 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
六程序设计
1
Option Base 1
Private Sub Form_click()
Dim a( 10)
Cis
createdata a()
sort a()
Fori= ITo 10
Print a(i);
Next i
End Sub
Sub createdata(a())
Fori = ITo 10
a(i) = Int(Rnd * 101)
Next i
End Sub
Sub sort(a())
For i = 1 To 9
Forj = 1 To 10-i
If a(j) > a(j + l)Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
End Sub
2
Private Type ks
no As String * 8
Bscj As Integer
Sjcj As Integer
End Type
Dim student As ks
Private Sub Form_Load()
Open "c:\ksxx.dat" For Random As#l Len = Len(student)
End Sub
Private Sub cmdadd_Click()
student.no = Text 1.Text
student.Bscj = Val(Text2.Text)
student.Sjcj = Vai (Tex t3.Text)
lastrecord = LOF( 1) / Len(student) + 1
Put # 1, lastrecord, student
Textl.Text =
Text2.Text = ””
Text3.Text ="
End Sub
Private Sub cmdquit_Click()
Close #1
End
End Sub
1-5 CABCD
理论练习二
6-10 ABCCD 11-15 BBBAB
1 CD
2 AD3CE4BC
6BCDE7CDE8ABCDE
9 ABD
三判断
二多选
1-5 X X X X V 6-10 V V V X X 16-20 DBAAC
5 AD
10ACDE
1n-l 或者Sqr (n)0
2X y
3 1 to 102*i-1
4Button=2start=True 五阅读程序
1-
5
DBDAB
六程序设计
1
Private Sub Form_click()
四填空
japan = 47528
china = 22257
n = 0 True — (x, y)
Do While china <= japan
china = china * 1.098
japan = japan * 1.028 n
= n + 1
Loop
Print n & ”年之后,中国GDP将超过日本”End Sub
•VB6中的Split函数,其功能足将一字符巾用分界符分割为一字符串数组。
,例如:
'Dim a() As String
's = ”l;2;3;4”
*a=Split(s,
,得到的结果如下:
,a(l) = H r,
'a(2) = ”2”
*a(3) = ”3“
*a(4) = M4"
Private Sub Command l_Click()
Dim a() As String
a = Split(Textl.Text,M”)
For i = LBound(a) To UBound(a)
a(i) = UCase(Left(a(i), 1)) & Mid(a(i), 2)
'Mid(a(i), 2)代表从第2位开始取,一,直取到最后一位
Labell.Caption = Label 1.Caption + a(i) + " H
Next i
End Sub
Private Sub Form_Load()
Label 1.Caption = ,,M
End Sub
理论练习三_单选
1-5 DBDBD 6-10 CCBBD 11-15 ADDDC
二多选
1 CDE2ABCD 3 ADE 4
BCE
6ACD7 ADE8 BCE9 AC 三判断
1-5 XXV V X6-10 V V X X V
四填空16-20 BBBBA 5 BCE
1Frm 2Single
352*k-1
4x=2 to n~l n mod x=0false 五阅读程序
1-
4
BDCB
六程序设计
略next j f=true
1-5 CDBBA
6-10 CABAD 11-15 ADCAA
16-20 DACBA
理论练习四
二多选
1 ACDE 2ABDE 3 ACD 4 ABD 5ABCDE 6ABCDE
7 ABDE
8 ABDE
9 ABC
10ABCD
三判断
1-5 XXX V V 6-10 V X V V V
四填空
1 Now 或 Time h<18
2 1 sum+p
3 i=0
n=n+l
4 5-i 或6-i 或… .
1
5
i+1
a(i) mod 2=1 and a(j) mod 2=0
五 阅读程序
1-5 ADACC
六程序设计
理论练习五
_单选
1-5 BCDAA
二多选
6-10C 无BAB 11-15 DCCDA 16-20 BADAB
1BDE 2 AD 6 BCDE 7 AB 三判断
1-5 X X X V V
四填空
1Textl.Text 2 1
31en (si)
5-i 或6-i 或
3 ACD
8 ABDE
6-10 V X V X X
For
suin+p
4CE 5BD
9 ABC 10ABCE
count+1
i (注意:
titleb+mid(strl, i, 1)
在两Next之间少了print)
5a(i) mod 2=1 and a(j) mod 2=0 五阅读程序
1-5 BDCAA 六程序设计
理论练习六
_单选 1-5 BAACB 21-25CBDCB 二多选 1ABCD 2 三判断 1-5 V X V X V 四填空 1 N mod 3=0 and 2 N=textl. text
3 4
6-10 BDABA 11-15 DDDAD 3 BCD
4 ADE
16-20 ACBAD
5 BCE n mod 7=0
val (mid(listl. text , n)) dim a(1 to 10) as integer
5 i>j 五阅读
程序 1-5
ABCBC 六程
序设计
End if 1
sum+pri ce a(j+l)=a(j) print。