十套练习和模拟题的VB题答案001
(完整版)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题库(附答案)
2009级第二学期《Visual Basic程序设计》模拟考试一: 单项选择题A1: 当事件发生时,对象识别并响应事件,执行事件对应的程序代码,这样的编程机制称为________。
A事件驱动编程机制B面向对象方法C过程化编程方法D 可视化程序设计方法C2: 下列不能打开属性窗口的操作是________。
(A)执行菜单中“视图→属性窗口”命令(B)按F4键(C)双击窗体(D)单击工具栏中的“属性窗口”按钮D3:当文本框获得焦点时,将触发文本框控件的_______事件。
(A)SetFocus(B)LostFocus(C)KeyPress(D)GotFocusB4: 以下不属于Visual Basic应用程序文件类型的是________。
(A).frm(B).bat(C).vbg(D).vbpD5: 使程序运行时窗体无法响应用户事件的属性是_______。
(A)Top(B)Cancel(C)Left(D)EnabledB6: 返回当前日期的函数是________。
(A)Time()(B)Date()(C)Year()(D)Timer()D7:用变量x存放数据123456789.987456321,变量x的最佳数据类型是________。
a整型b长整型c单精度型d双精度型A8: 设变量X="123",Y=3,则X&Y的值为________。
(A)"1233"(B)126(C)123(D)假C9: 下列程序段中可以实现X、Y变量值的互换的是________。
(A)Y=X:X=Y (B)Y=X:Y=Z:X=Y(C)Z=X:X=Y:Y=Z(D)Z=X:W=Y:Y=Z:X=YD10: InputBox函数返回值的类型是________。
(A)字符串(B)变体(C)数值(D)数值或字符串(视输入而定)A11:关于多分支选择结构If…ElseIf…EndIf ,下列错误的叙述是________。
vb习题(含答案)
vb习题(含答案)⼀、单项选择题(50道⼩题,共50分)1、VB程序中,通常不会产⽣错误提⽰的是( )。
(1分)A、编译错误B、逻辑错误C、运⾏时错误D、实时错误2、在设计阶段,双击窗体上任⼀空⽩处,打开的窗⼝是( )。
(1分)A、⼯程资源管理器窗⼝B、代码窗⼝C、⼯具箱窗⼝D、属性窗⼝3、下列说法中,正确的说法是( )。
(1分)A、窗体名称和该窗体⽂件名必须⼀致B、窗体名称和该窗体⽂件名可以不相同C、窗体名称和该窗体⽂件名不能使⽤汉字D、窗体名称不能使⽤汉字、但该窗体⽂件名能使⽤汉字4、Visual Basic有完备的Help联机帮助功能,可以通过按下功能键( )得到帮助。
(1分)A、F9B、F8D、F55、以下( )控件可作为容器使⽤。
(1分)A、LabelB、PictureBoxC、TextBoxD、Image6、将窗体的BoderStyle属性设置为( )可使窗⼝不显⽰标题栏。
(1分)A、0B、1C、2D、57、⽂本框没有( )属性(1分)A、TextB、NameC、CaptionD、BorderStyleA B C D A B C D A B C D A B C D A B C D A B C D A B C D A BC D A B C D A B C D A B C D A B C D A B C D A B C D A B C D23、下列( )是不合法的常量。
(1分)A、100B、10E02D、10e0.524、下列对变量的定义中,定义X为变体型变量的是( )。
(1分)A、Dim X as DoubleB、Dim XC、Dim X!D、X%=2325、设有如下变量声明:Dim TestDate As Date,为变量TestDate正确赋值的表达⽅式是( )。
(1分)A、TextDate=#1/1/2002#B、TestDate=#"1/1/2002"#C、TextDate=date("1/1/2002")D、TestDate=Format("m/d/yy","1/1/2002")26、在⽴即窗⼝中运⾏以下语句,a="Beijing" :b="ShangHai" :Print a,b对其输出结果的描述中,正确的是( )。
vb习题答案(1-9章)最全的
第一章VB程序设计概述二、选择题CADAB ACDAB CBDBB第二章VB可视化编程基础二、选择题ABDCA CACBC DADAD BDBBB三、填空题1.可视2.LEFT TOP WIDTH HEIGHT3.按字母序4.查看代码5.工具、选项6.Form1 Font7.Multiline8.只读属性9.工程属性通用Form1.show10.tabindex 0第三章VB语言基础二、选择题BCADB ADBBC DBCBA DAABB三、填空题1.整型、长整型、单精度、双精度2.sin(30*3.14/180)+sqr(x+exp(3))/abs(x-y)-log(3*x)3.160 今天是:3-224.False5.-4 3 -3 3 -4 46.“CDEF”7.(x mod 10)*10+x\108.(35\20)*20=20 ( 35 \ 20 ) * 20 = 209.x mod 3=0 or x mod 5=010.27.6 8.2 8 1 100 397 true false第四章VB程序控制结构二、选择题DBCAD ABCAB D25BAC CBACB DABBC三、填空题1.字符型整型2. 1 2 33.x>74.x<amin5.10246.117.128.6 I “*”;9.0 100 i+1 10.2*I 6 “*”;三、编程题1.Private Sub Form_Click()Dim n As Integer, i As Integer, s As Longs = 1n = Val(InputBox("请输入一个整数:"))For i = 1 To ns = s * iNext iMsgBox n & "!=" & sEnd Sub2.Private Sub Form_Click()Dim i%, k%For j = 3 To 100k = Int(Sqr(j))For i = 2 To kIf j Mod i = 0 Then Exit ForNext iIf i > k Theny$ = y$ & " " & jEnd IfNext jMsgBox y, , "显示质数"End Sub3.Private Sub Form_Click()Dim i%, s%For i = 1 To 100s = s + iNext iMsgBox "1+2+3+……+100=" & sEnd Sub4.Private Sub Form_Click()Dim x%, y%For x = 1 To 50For y = 1 To 33z = 100 - x - yIf 2 * x + 3 * y + 0.5 * z = 100 ThenPrint "小鸡、公鸡、母鸡分别为:"; x; y; z End IfNext yNext xEnd Sub5.Private Sub Command1_Click()Dim a%, b%, c%, p!, s!doa = Val(InputBox("请输入三角形的第一条边"))if a=-1 then exit dob = Val(InputBox("请输入三角形的第二条边"))c = Val(InputBox("请输入三角形的第三条边"))If a + b > c And a + c > b And b + c > a Thenp = (a + b + c) / 2s = Sqr(p * (p - a) * (p - b) * (p - c))Print sElseMsgBox "你输入的三边不能构成三角形,请重新输入"End IfloopEnd Sub6. Private Sub Form_Click()Dim i As Integer, j As Integer,k as integerFor i = 1 To 8For k=1 to 8-iPrint spc(3);Next kFor j = 1 To 2 * i - 1Print i;Next jPrintNext iEnd Sub7. Private Sub Form_Click()Dim i As Integer, j As Integer, k As IntegerFor i = 1 To 30For j = 1 To 30For k = 1 To 30If i ^ 2 + j ^ 2 = k ^ 2 ThenPrint i & " ^ 2 + " & j & "^ 2 =" & k & "^ 2"End IfNext kNext jNext iEnd Sub8.Private Sub Form_Click()Dim x As Integer, a As Integer, b As Integer, c As Integer, ss As String ss = ""For x = 100 To 999a = Int(x / 100)b = Int((x - 100 * a) / 10)c = x - 100 * a - 10 * bIf a ^ 3 + b ^ 3 + c ^ 3 = x Thenss = ss & " " & xEnd IfNext xPrint ssEnd Sub9.Dim sr As Long, r As Singlesr = Val(InputBox("请输入收入:"))Select Case srCase Is < 200r = 0Case 200 To 400r = (sr - 200) * 0.04Case 400 To 5000r = sr * 0.04Case Is >= 5000r = sr * 0.05End SelectPrint "收入为" & sr & "时所缴纳的税为:" & rEnd Sub10.Private Sub Form_Click()Dim t As Single, wf As Singlet = Val(InputBox("请输入上网时间:"))Select Case tCase Is < 10wf = 50Case 10 To 60wf = t * 6Case Is >= 60wf = t * 4End SelectIf wf >= 200 Thenwf = 200End IfPrint "上网时间为" & t & "小时上网的费用为:" & wf End Sub11. Private Sub Form_Click()Dim yf As Integeryf = Val(InputBox("请输入月份"))Select Case yfCase 12, 1, 2MsgBox yf & "月份是冬季"Case 3, 4, 5MsgBox yf & "月份是冬季"Case 6, 7, 8MsgBox yf & "月份是冬季"Case 9, 10, 11MsgBox yf & "月份是冬季"Case ElseMsgBox "输入错误,请重新输入"End SelectEnd Sub12.if的方法Private Sub Form_Click()Dim x As Single, f As Singlex = Val(InputBox("请输入一个数"))If x < 0 Thenf = 2 * x - 1ElseIf x = 0 Thenf = 4 * xElseIf x > 0 Thenf = 7 * x - 5End IfPrint "f(" & x & ")=" & fEnd SubSelect case语句:Private Sub Form_Click()Dim x As Single, f As Singlex = Val(InputBox("请输入一个数"))Select Case xCase Is < 0f = 2 * x - 1Case 0f = 4 * xCase Is > 0f = 7 * x - 5End SelectPrint "f(" & x & ")=" & fEnd Sub第五章数组一、选择题DCACD DBCDC BADAD二、填空题1.名称Index2.preserve3.变体4.235.1 2 3 1 4 16.1 2 3 2 4 67. max max=arr1(i)三、编程题1.Option Base 1Private Sub Form_Click()Dim a(10) As Integer, i%, temp%For i = 1 To 10a(i) = Val(InputBox("请输入第" & i & "个整数")) Next iPrint "原来各元素的值为:"For i = 1 To 10Print a(i);Next iFor i = 1 To 5temp = a(11 - i)a(11 - i) = a(i)a(i) = tempNext iPrintPrint "交换后各元素的值为:"For i = 1 To 10Print a(i);Next iEnd Sub2.Option Base 1Private Sub Form_Click()Dim a As Variant, b As Variant, c As Variant, i%a = Array(2, 8, 7, 6, 4, 28, 70, 25)b = Array(79, 27, 32, 41, 57, 66, 78, 80)ReDim c(8)For i = 1 To UBound(a)c(i) = a(i) + b(i)Next iFor i = 1 To UBound(c)Print c(i);Next iEnd Sub3.Option Base 1Private Sub Form_Click()Dim a() As Variant, i%, j%, n%, m%, max%, hh%, lh%n = Val(InputBox("请输入一个整数:"))m = Val(InputBox("请输入一个整数:"))ReDim a(n, m)For i = 1 To n - 1For j = 1 To m - 1a(i, j) = Int(Rnd * 101 + 50)If max < a(i, j) Then max = a(i, j): hh = i: lh = jNext jNext iPrint "最大值为:"; max; "所在的行号为:"; hh; "所在的列号为:"; lh End Sub4.Option Base 1Private Sub Form_click()Dim a(50) As Integer, b(9) As Integer, i%, j% For i = 1 To 50a(i) = Int(Rnd * 90 + 10)j = Int(a(i) / 10)b(j) = b(j) + 1Next iFor j = 1 To 9Print b(j);Next jEnd Sub5.Option Base 1Private Sub Command1_Click(Index As Integer) Select Case IndexCase 0Text3 = Val(Text1) + Val(Text2)Case 1Text3 = Val(Text1) - Val(Text2)Case 2Text3 = Val(Text1) * Val(Text2)Case 3Text3 = Val(Text1) / Val(Text2)End SelectEnd Sub6.Private Sub Form_click()Dim s!, i&, j&i = 3s = 1j = 0Doj = j + 1s = s + (-1) ^ j / ii = i + 2Loop While 1 / i > 10 ^ (-6)Print 4 * sEnd Sub7.Option Base 1Private Sub Form_click()Dim a(40) As Long, i As Integera(1) = 1a(2) = 1For i = 3 To 39a(i) = a(i - 1) + a(i - 2)Next iFor i = 1 To 40Print a(i);Next iEnd Sub8.冒泡法:Option Base 1Private Sub Form_click()Dim a(10) As Single, ok As Boolean, i%, j%, x!For i = 1 To 10a(i) = Val(InputBox("请输入第" & i & "个数"))Print a(i);Next iFor i = 10 To 2 Step -1ok = TrueFor j = 1 To i - 1If a(j) > a(j + 1) Thenx = a(j)a(j) = a(j + 1)a(j + 1) = xok = FalseEnd IfNext jIf ok Then Exit ForNext iPrintPrint "冒泡排序的结果为:"For i = 1 To 10Print a(i);Next iEnd Sub选择法:Option Base 1Private Sub Form_click()Dim a(10) As Single, p!, i%, j%, min!For i = 1 To 10a(i) = Val(InputBox("请输入第" & i & "个数"))Print a(i);Next iFor i = 1 To 9p = iFor j = i + 1 To 10If a(j) < a(p) Then p = jNext jIf p <> i Thenmin = a(i)a(i) = a(p)a(p) = minEnd IfNext iPrintPrint "排序后的结果为:"For i = 1 To 10Print a(i);Next iEnd Sub第六章过程一、选择题CDBAB DBCCC ABCBD CDB二、填空题1.sub function2.形式实际3.内存的同一地址4.myf(a%,b() as integer ) as Boolean5.值传递地址传递6.lbound ubound7.局部8.通用任何过程9.2 5 9 10.2411.2 12.30 7013.-1三、编程题1. Option Base 1Private Sub Form_Click()Dim m1%, m2%, b() As IntegerFor i = 3 To 7 Step 2ReDim b(i)For j = 1 To ib(j) = Int(Rnd * 90 + 10)Print b(j);Next jm1 = b(1)m2 = b(1)Call mm(m1, m2, b())PrintPrint "最大值为:"; m1Print "最小值为:"; m2Next iEnd SubPublic Sub mm(max%, min%, a() As Integer) Dim i%For i = LBound(a) To UBound(a)If a(i) > max Then max = a(i)If a(i) < min Then min = a(i)Next iEnd Sub2.sub过程:Public Sub jc(n%, s&)Dim i%s = 1For i = 1 To ns = s * iNext iEnd SubPrivate Sub Form_click()Dim s&, a%, b%, c%, s1&a = Val(InputBox("请输入一个整数:"))b = Val(InputBox("请输入一个整数:"))c = Val(InputBox("请输入一个整数:")) Call jc(a, s1)s = s1 + sCall jc(b, s1)s = s1 + sCall jc(c, s1)s = s1 + sPrint a & "!+" & b & "!+" & c & "!=" & s End SubFunction过程:Public Function jc(n%) As LongDim i%, s%s = 1For i = 1 To ns = s * iNext ijc = sEnd FunctionPrivate Sub Form_click()Dim s&, a%, b%, c%, s1&a = Val(InputBox("请输入一个整数:"))b = Val(InputBox("请输入一个整数:"))c = Val(InputBox("请输入一个整数:"))s1 = jc(a) + jc(b) + jc(c)Print a & "!+" & b & "!+" & c & "!=" & s1 End Sub3.Public Sub jo(n As Integer)If n Mod 2 = 0 ThenPrint "false"ElsePrint "true"End IfEnd Sub4.Private Sub Form_click()Dim b(1 To 100) As Integer, i%For i = 1 To 100b(i) = Int(Rnd * 100 + 1)Next iCall sort(b())For i = 1 To 100If i Mod 10 = 0 Then PrintPrint b(i);Next iEnd SubPublic Sub sort(a() As Integer)Dim n%, ok As Boolean, k As Integern = UBound(a)For i = 1 To n - 1ok = TrueFor j = 1 To n - iIf a(j) > a(j + 1) Thenk = a(j): a(j) = a(j + 1): a(j + 1) = k: ok = False End IfNext jIf ok Then Exit ForNext iEnd Sub5.Private Sub Form_click()Dim b(1 To 10) As Integer, i%For i = 1 To 10b(i) = Val(InputBox("请输入第" & i & "个整数")) Next iCall sort(b())Print "排序后的结果"For i = 1 To 10Print b(i);Next iEnd SubPublic Sub sort(a() As Integer)Dim n%, p%, k As Integern = UBound(a)For i = 1 To n - 1p = iFor j = i + 1 To nIf a(j) < a(p) Then p = jNext jIf p <> i ThenMin = a(i)a(i) = a(p)a(p) = MinEnd IfNext iEnd Sub6.Public Sub gys(m%, n%)Dim r%, t%If m <> 0 And n <> 0 ThenIf m < n Thent = m: m = n: n = tEnd Ifr = m Mod nDo While r <> 0m = nn = rr = m Mod nLoopEnd IfEnd Sub7.Public Sub ws(n%, s%)Dim k%, i%For i = 1 To n - 1If n Mod i = 0 Then s = s + iNext iEnd SubPrivate Sub Form_click()Dim m%, sum%, c$For m = 1 To 999sum = 0Call ws(m, sum)If sum = m Then c = c & sum & " " Next mMsgBox cEnd Sub8.Public Function ef(a(), k%, wz%) As Integer Dim i%, low%, mid%, top%low = LBound(a)top = UBound(a)Do While low <= topmid = (low + top) / 2If k > a(mid) Thenlow = mid + 1ElseIf k = a(mid) Thenwz = midExit FunctionElsetop = mid - 1End IfLoopwz = -1End Function9.Function MaxGY(x As Integer, y As Integer) Dim Temp As IntegerTemp = x Mod yIf Temp = 0 ThenMaxGY = yElseMaxGY = MaxGY(y, Temp)End IfEnd FunctionPrivate Sub Form_click()Dim m%, n%m = Val(InputBox("请输入第一个整数:"))n = Val(InputBox("请输入第二个整数:")) Print "最大公约数是:"; MaxGY(m, n)End Sub10. Function Ss(n%)If n = 1 ThenSs = 10ElseSs = Ss(n - 1) + 2End IfEnd FunctionPrivate Sub Form_click()Dim r%, x%r = 5x = Ss(5)Print "第5个小孩的岁数为:"; xEnd Sub第七章应用程序界面设计一、选择题BCDCA CDBBD CADAA CADBD DAAAB CAA二、填空题1.form1.show unload form12.form2.show form1.hide3.属性方法事件4、工程属性工程属性5.子窗体主窗体6、keypress list(i) additem7.0 list1.listindex list1.listcount-18、1000 true time() 9、AA10、下拉式组合框、简单组合框和下拉式列表框第八章VB图形操作一、选择题DCCDA CDAAA BABBC CAAA二、填空题1、不会也不会 2.、Scaleheight Scalewidth3、(300,-150)4、右上5、twip6、0~157、B 8、-2π~09、逆10、drawwidth11、右上12、move13、cls 14、坐标原点、坐标度量单位、坐标轴的长度与方向15、VB程序设计vbprogramming三、编程题1、Private Sub Command1_Click()Const pi = 3.14159P1.Circle (Val(Text1), Val(Text2)), Val(Text3)End SubPrivate Sub Command2_Click()P1.ClsText1 = ""Text2 = ""Text3 = ""End Sub2、Private Sub Form_Load()Pic1.Picture = LoadPicture("F:\VB程序设计\上课课件\tea.jpg")End SubPrivate Sub Pic1_Click()Pic2.Picture = Pic1.PicturePic1.Picture = LoadPicture("")End Sub3、Dim a1!, b1!Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) a1 = Xb1 = YEnd SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Circle (a1, b1), Sqr((a1 - X) ^ 2 + (b1 - Y) ^ 2)End Sub4、Dim a1!, b1!Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Thena1 = Xb1 = YEnd IfEnd SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button = 1 ThenLine (a1, b1)-(X, Y), vbGreen, BFEnd IfEnd Sub5、Private Sub Form_Click()Scale (-200, 200)-(200, -200)Dim i!For i = 0 To 140 Step 20Line (-i - 10, i + 10)-(i + 10, -i - 10), , BNext iEnd Sub第9章vb文件操作一、选择题BDDCC BBAAB二、填空题1、驱动器列表框、目录列表框和文件列表框2、change 3\file1.path=dir1.path4、name “D:\old.doc” as “c:\new.doc”5、dir1.path=drive1.drive file1.path=dir1.path6、filecopy “d:\text.doc”,”e:\text.doc”7、eof 8、input not eof(1)9、for inputFor outputnot eof(1)str1Close #110、pattern 11、空12、字节。
vb考试题库及答案大一
vb考试题库及答案大一一、选择题(每题2分,共20分)1. 在VB中,以下哪个是正确的变量声明语句?A. Dim a$B. Dim a IntegerC. Dim a As StringD. Dim a As Integer答案:C2. VB中,以下哪个是正确的字符串连接操作符?A. +B. ||C. &D. *答案:C3. 在VB中,以下哪个函数用于将字符串转换为数值?A. Val()B. Str()C. CInt()D. CDbl()答案:A4. 在VB中,以下哪个是正确的条件语句?A. If x > 0 Then Print "Positive"B. If x > 0 Print "Positive"C. If x > 0 Then Print "Positive" Else Print "Negative"D. If x > 0 Then "Positive"答案:C5. 在VB中,以下哪个是正确的循环结构?A. For i = 1 To 10B. For i = 1 To 10 Step -1C. For i = 10 To 1D. All of the above答案:D6. 在VB中,以下哪个是正确的数组声明语句?A. Dim arr(10)B. Dim arr(10) As IntegerC. Dim arr() As IntegerD. Dim arr As Integer(10)答案:B7. 在VB中,以下哪个是正确的函数声明语句?A. Function myFunction() As IntegerB. Function myFunction As IntegerC. Function myFunction() IntegerD. Function myFunction Integer答案:A8. 在VB中,以下哪个是正确的事件处理程序声明?A. Private Sub Form_Click()B. Private Sub Form_Click(ByVal sender As Object, ByVal e As EventArgs)C. Private Sub Form_Click(ByVal sender As Object)D. Private Sub Form_Click(ByVal e As EventArgs)答案:A9. 在VB中,以下哪个是正确的窗体属性?A. CaptionB. TextC. NameD. All of the above答案:D10. 在VB中,以下哪个是正确的控件事件?A. ClickB. DoubleClickC. MouseDownD. All of the above答案:D二、填空题(每题2分,共20分)1. 在VB中,使用___________关键字可以声明一个全局变量。
Vb十套模拟题及答案
Vb答案第一套1 在名称为FORM1 的窗体上放置一个名为TEXT1 的文本框控件和一个名为TIMER1的计时器控件,请设置计时器的适当属性并且编写适当的事件过程,使得程序运行后,文本框中显示的是当前的时间,而且每一秒文本框中所显示的时间都会随时间的变化而改变。
(如示例所示)*****注意:程序中不得使用任何变量,只能写一条语句;保存时必须存放在考生文件夹下,窗体文件名为SJT1.FRM,工程文件名为SJT1.VBP。
Private Sub Timer1_Timer()Text1.Text = TimeEnd Sub2 在窗体FORM1上画一个组合框,名称为CBO1,有“长跑”、“游泳”、“跳远”三个可供选择项。
再画一个命令按钮,名称为CMD1,标题为“确定”。
编写适当的事件过程,使得程序运行时,选择组合框中的某项,单击命令按钮后,就会弹出一个消息框,内容为“您选择了(某项)”如[示例]。
注意:1)程序中不得使用任何变量。
2)保存时必须存放在考生文件夹下,窗体文件名为SJT2.FRM,工程文件名为SJT2.VBPPrivate Sub Cmd1_Click()MsgBox "您选择了" & CBO1.TextEnd Sub3 在考生文件夹中有文件SJT3.VBP及其窗体文件SJT3.FRM,该程序是不完整的,请在有?号的地方填入正确内容,然后删除?及所有注释符(即'号),但不能修改其它部分。
存盘时不得改变文件名和文件夹。
本题描述如下:在窗体上画一个名称为TEXT1的文本框,小四号字,再画两个名称分别为CH1和CH2,标题分别为"C 程序设计"和"VB程序设计"的复选框,小四号字,一个名称为C1,标题为"确定"的命令按钮。
编写适当的事件过程,要求程序运行后,如果只选中CH1,然后单击"确定"命令按钮,则在文本框中显示"学习C程序设计";如果只选中CH2,然后单击"确定"命令按钮,则在文本框中显示"学习VB程序设计";如果同时选中CH1和CH2,然后单击"确定"命令按钮,则在文本框中显示"学习C程序设计VB程序设计"。
VB模拟试题试及参考答案
VB模拟试题试及参考答案2016VB模拟题第⼀套单项选择题得分:1: 计算机的基本⼯作原理是__C______。
A. 可靠性与可⽤性B. ⾼速度与⾼精度C. 存储程序与程序控制D. 具有记忆功能2: 计算机中数据的表⽰形式是____A____。
A. ⼆进制B. ⼋进制C. ⼗进制D. ⼗六进制3: 电⼦邮件标识中带有⼀个“别针”,表⽰该邮件_____C_。
A. 设有优先级B. 带有标记C. 带有附件D. 可以转发4: 安装防⽕墙的主要⽬的是__C______。
A. 提⾼⽹络的运⾏效率B. 对⽹络信息进⾏加密C. 保护内⽹不被⾮法⼊侵D. 防⽌计算机数据丢失5: 淘宝⽹的⽹上购物属于计算机现代应⽤领域中的___C___。
A. 计算机辅助系统B. 电⼦政务C. 电⼦商务D. 办公⾃动化6: Visual Basic中标准模块⽂件的扩展名是____D__。
A. FrmB. VbpC. ClsD. Bas7: 启动程序时,系统⾃动执⾏启动窗体的___A___事件过程。
A. LoadB. UnloadC. ClickD. DblClick8: 下列_____C_⽅法可以显⽰窗体。
A. HideB. UnLoadC. ShowD. WindowState9: 已知a="123456789",则表达式Mid(a, 5, 2) + Left(a, 2)的值是_____B___。
A. "5689"B. "5612"C. 68D. 125610: 下列不正确的赋值语句是__C____。
A. x=30-yB. y=x+30C. x+y=30D. y=x\311: 下列选项中,合法的变量名是_B______ 。
A. 1_xB. x_1C. x-1D. x 112: 下列选项不是Visual Basic基本数据类型的是______A__。
A. CharB. StringC. BooleanD. Double13: 在下列表达式中,正确的⽇期型常量是__D____ 。
VB练习题(含答案),推荐文档
考试题型一、单项选择题(每题1分,共35分)二、判断题(每题1分,共15分;正确的打",错误的打x。
)三、填空题(每空1分,共10分)四、读程序写出结果(每题5分,共20分)五、程序填空(每空2分,共10分)六、编程题(每小题10分,共10分)2006年4月全国计算机等级考试二级笔试试卷Visual Basic语言程序设计11. 以下关于Visual Basic特点的叙述中,错误的是A)Visual Basic是采用事件驱动编程机制的语言B)Visual Basic程序既可以编译运行,也可以解释运行C)构成Visual Basic程序的多个过程没有固定的执行顺序D)Visual Basic程序不是结构化程序,不具备结构化程序的三种基本结构12. 以下叙述中,错误的是A)一个Visual Basic应用程序可以含有多个标准模块文件B)一个Visual Basic工程可以含有多个窗体文件D)标准模块文件的扩展名是.bas13. 以下叙述中,错误的是A)在Visual Basic中,对象所能响应的事件是由系统定义的C)Visual Basic中允许不同对象使用相同名称的方法D)Visual Basic中的对象具有自己的属性和方法14. 设有如下语句:Dim a,b As In tegerC= "VisualBasic ”D=#7/20/2005#以下关于这段代码的叙述中,错误的是A)a被定义为Integer类型变量B) b被定义为Integer类型变量C) c中的数据是字符串D)d中的数据是日期类型15. 以下能从字符串"VisualBasic "中直接取出子字符串"Basic"的函数是A)Left |B) Mid | C) Stri ng D) In str16. 设a=4,b=3,c=2,d=1下列表达式的值是a>b+1 Or c<d And b Mod cA) True B) 1 C) -1 D) 017.以下可以作为Visual Basic变量名的是A) A#A B)counstA C) 3A D) ?AA18.设x-4,y-6,则以下不能在窗体上显示出A=10 的语句是C) Print “ A= ” +Str(x+y)D) Print “ A= ” & x+y19. 假定有如下的命令按钮(名称为Comma ndl)事件过程:Private Sub Comma nd1_Click()X=lnputBox(输入::“'输入整数”)MsgBox ”输入的数据是:”,,”输入数据:”+XEnd Sub程序运行后,单击命令按钮,如果从键盘上输入整数10,则以下叙述中错误的是A)x的值是数值10B)输入对话框的标题是“输入整数“C)信息框的标题是“输入数据:10 “D)信息框中显示的是“输入的数据是:“20. 在窗体上画1个命令按钮(名称为Command1 )和1个文本框(名称为Text1),然后编写如下事件过程:Private Sub Comma nd1_Click()X=Val(Text1.Text)Select Case xCase 1,3Y=x*xCase Is>=10,Is<=-10Y=xCase -10 To 10Y=-xEnd SelectEnd Sub程序运行后,在文本框中输入3,然后单击命令按钮,则以下叙述中正确的是A) 执行Y=x*x B)执行Y=-xC)先执行Y=x*x,再执行Y=-x D)程序出错21. 设有命令按钮Comma nd1的单击事件过程,代码如下:Private Sub Comma nd1_Click()Dim a(30) As In tegerFor i=1 to 30a(i)=I nt(R nd*100)NextFor Each arritem In aIf arrItem Mod 7=0 Then Print arrItem;If arrItem >90 Then Exit ForNextEnd Sub对于该事件过程,以下程序中错误的是B) 语句For Each arrltem In a 有语法错误C) ........................................... If arrltem Mod 7=0 语句的功能是输出数组中能够被........................... 7整除的数D) ................................ If arrItem >90 语句的作用是当数组元素的值大于....................... 90时退出For循环22. 设有命令按钮Comma nd1的单击事件过程,代码如下:Private Sub Comma nd1_Click()Dim a(3,3) As In tegerFor i=1 to 3For j=1 to 3a(i,j)=i*j+iNext jNext iSum=0For i=1 to 3Sum=Sum+a(i,4-i)Next iPrint SumEnd Sub运行程序,单击命令按钮,输出结果是A) 20 B) 7 | C) 16 ~| D) 1723. 在窗体上画1个名称为Command1的命令按钮,然后编写如下事件过程:Private Sub Comma nd1_Click()a=0For i=1 to 2For j=1 to 4If j Mod 2<>0 Thena=a-1End Ifa=a+1Next jNext iPrint aEnd Sub程序运行后,单击命令按钮,输出结果是A)0 B) 2 C) 3 | D)424. 窗体上有名称分别为Text1、Text2的2个文本框,有一个由3个单选按钮构成的控件数组Option1,程序运行后,如果单击某个单选按钮,则执行Text1中的数值与该单选按钮所对应的运算(乘以1、10或100),并将结果显示在Text2中,如图2所示。
VB模拟试题试及参考答案
2016VB模拟题第一套单项选择题得分:1: 计算机的基本工作原理是__C______。
A. 可靠性与可用性B. 高速度与高精度C. 存储程序与程序控制D. 具有记忆功能2: 计算机中数据的表示形式是____A____。
A. 二进制B. 八进制C. 十进制D. 十六进制3: 电子邮件标识中带有一个“别针”,表示该邮件_____C_。
A. 设有优先级B. 带有标记C. 带有附件D. 可以转发4: 安装防火墙的主要目的是__C______。
A. 提高网络的运行效率B. 对网络信息进行加密C. 保护内网不被非法入侵D. 防止计算机数据丢失5: 淘宝网的网上购物属于计算机现代应用领域中的___C___。
A. 计算机辅助系统B. 电子政务C. 电子商务D. 办公自动化6: Visual Basic中标准模块文件的扩展名是____D__。
A. FrmB. VbpC. ClsD. Bas7: 启动程序时,系统自动执行启动窗体的___A___事件过程。
A. LoadB. UnloadC. ClickD. DblClick8: 下列_____C_方法可以显示窗体。
A. HideB. UnLoadC. ShowD. WindowState9: 已知a="123456789",则表达式Mid(a, 5, 2) + Left(a, 2)的值是_____B___。
A. "5689"B. "5612"C. 68D. 125610: 下列不正确的赋值语句是__C____。
A. x=30-yB. y=x+30C. x+y=30D. y=x\311: 下列选项中,合法的变量名是_B______ 。
A. 1_xB. x_1C. x-1D. x 112: 下列选项不是Visual Basic基本数据类型的是______A__。
A. CharB. StringC. BooleanD. Double13: 在下列表达式中,正确的日期型常量是__D____ 。
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上机模拟考试习题集(01-50)解答
1.1上机模拟试题1解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Command1_Click()Image1.Picture = LoadPicture(App.Path & "\图片.jpg") End SubPrivate Sub Command2_Click()Image1.Picture = LoadPicture("")End Sub2. 简单操作(1) 程序代码如下:Private Sub Command2_Click()Dim i As Integer, max As Integer, N As IntegerFor i = 1 To 100If a(i) = (Int(Sqr(a(i)))) ^ 2 ThenIf a(i) > max Thenmax = a(i)End IfN = N + 1End IfNext iText1.Text = CStr(max)Text2.Text = CStr(N)End Sub(2)' ? "a0001" 其中?改为:List1.AddItem' For i = 0 To ? 其中?改为:List1.ListCount - 1' List1.ListIndex = ? 其中?改为:i' ? Text1.Text 其中?改为:List1.AddItem' ? 其中?改为:End3. 综合应用' a(i) = Fix(Rnd * ? + 1) 其中?改为:100' For j = 1 To ? 其中?改为:i - 1' i = ? 其中?改为:i - 1' If a(i) = ? Then 其中?改为:num' If ? > 10 Then 其中?改为:i1.2上机模拟试题2解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub HS1_Change()Text1.Width = HS1.ValueEnd Sub2. 简单操作(1)' While (k < List2.?) 其中?改为:ListCount' If ?.Selected(k) = True Then 中?改为:List2' List2.RemoveItem ? 其中?改为:k' List1.RemoveItem List1.? 其中?改为:List1.ListIndex(2) 程序代码如下:Private Sub C1_Click()For i = 0 To 2If Op1(i).Value = True Thenn = Left(Op1(i).Caption, 2)t = 1For j = 1 To nt = t * jNext jEnd IfNext iText1 = tEnd Sub3. 综合应用' CD1.FilterIndex = ? 其中?改为:2' Text1.Text = ? 其中?改为:a' CD1.Action = ? 其中?改为:2程序代码如下:Private Sub C2_Click()Text1.Text= UCase(Text1.Text)End Sub1.3上机模拟试题3解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub C1_Click()Text2.Text = Text1.TextEnd Sub2. 简单操作(1)' S1 = ? 其中?改为:Text1.Text' Do While Mid(S1, I1, 1) <> ? And I1 <= Len(S1) 其中?改为:" "' List1.AddItem ? 其中?改为:S2' S2 = ? 其中?改为:""(2) 程序代码如下:' For i = ? To Cb1.ListCount - 1其中?改为:0' If Cb1.List(i) = Cb1.? Then 其中?改为:Text' Cb1.? Cb1.Text 其中?改为:AddItem3. 综合应用程序代码如下:Private Sub Form_Load()Dim str As StringOpen App.Path + "\in5.txt" For Input As #1Do While Not EOF(1)Input #1, strText1.Text = Text1.Text + strLoopClose #1End SubPrivate Sub C1_Click()Open App.Path + "\out5.txt" For Output As #2Print #2, Text1.TextClose #2End Sub1.4上机模拟试题4解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Command1_Click()Shape1.Shape = 3End SubPrivate Sub Command2_Click()Shape1.BorderColor = &HFF&End Sub2. 简单操作(1)' Select Case ? 其中?改为:Index' Timer1.Enabled =? 其中?改为:True' If Picture1.Left + Picture1.Width >= ? Then 其中?改为:Form2.Width ' Picture1.Left = ? 其中?改为:0(2)' If ? = True Then 其中?改为:Option1.Value = True' If ? = True Then 其中?改为:Option3.Value = True' Label2.Caption = ? 其中?改为:s3. 综合应用程序代码如下:Private Sub Command1_Click()'====考生编写程序开始====Dim i As Integer, j As Integer, max As Integermax = a(1, 1)For i = 1 To 4For j = 1 To 4If max < a(i, j) Then max = a(i, j)Next jNext iLabel3.Caption = max'====考生编写程序结束===='不得修改以下部分save Label3End SubPrivate Sub Command2_Click()'====考生编写程序开始====Dim i As Integer, j As Integer, sum As Integer sum = 0For i = 1 To 4For j = 1 To 4If i = j Then sum = sum + a(i, j)Next jNext iLabel4.Caption = sum'====考生编写程序结束===='不得修改以下部分save Label4End Sub1.5上机模拟试题5解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Command3_Click()Call sub1End SubPrivate Sub Timer1_Timer()Text1.Text = Text1.Text + 1End Sub2.简单操作(1)' For i = 1 To ? 其中?改为:5' For j = 1 To ? 其中?改为:2 * i - 1' For j = 1 To ? 其中?改为:i + 1' For j = 1 To ? 其中?改为:9 - 2 * i(2)' ? = False 其中?改为:Timer1.Enabled' Shape2.Top = ? + d * 50 其中?改为:Shape2.Top' If Shape2.Top <= Shape1.? Or Shape2.Top + Shape2.Width >= Shape1.Top + Shape1.Height Then 其中?改为:Top' Shape2.Left = ? + d * 50 其中?改为:Shape2.Left3. 综合应用' n = n + ? 其中?改为:1' List1.AddItem ? 其中?改为:ch$程序代码如下:Private Sub Command2_Click()'需要考生编写的内容Dim x As Single, p As Singlex = Val(Text1.Text)If x < 500 Thenp = 1ElseIf x < 1000 Thenp = 0.98ElseIf x < 1500 Thenp = 0.95ElseIf x < 2000 Thenp = 0.92Elsep = 0.9End IfText2.Text = CStr(Int(x * 0.3 * p))End SubPrivate Sub List1_Click()'需要考生编写的内容Dim i As IntegerFor i = 0 To List1.ListCount - 1If List1.Selected(i) = True ThenText1.Text = CStr(a(i + 1))End IfNext iEnd Sub1.6上机模拟试题6解答1. 基本操作(1) 程序代码如下:Private Sub Command1_Click()Command1.Width = Command1.Width + 100End Sub(2) 程序代码如下:Private Sub L1_Click()Shape1.Shape = Val(L1.List(L1.ListIndex))End Sub2. 简单操作(1)' Call ? 其中?改为:calc(i)' Label2.Caption = ? 其中?改为:Option1(i).Caption' x = ? 其中?改为:Text1' If i Mod 2 ? Then 其中?改为:<>0' Label3.Caption = ? 其中?改为:result(2)' Timer1.Enabled = ? 其中?改为:False' Timer1.Interval = ? 其中?改为:500' If Picture1.Left > ? Then 其中?改为:Form1.Width' Picture1.Left = ? 其中?改为:03. 综合应用程序代码如下:Private Sub Command1_Click()'========考生编写程序开始========Dim i As Integer, N1 As Integer, N2 As Integer, avg As Single, sum As Single For i = 1 To nIf arr(i) >= 60 ThenN1 = N1 + 1ElseN2 = N2 + 1End Ifsum = sum + arr(i)Next iavg = sumText1.Text = CStr(n)Text2.Text = CStr(CInt(avg / n))Text3.Text = CStr(N1)Text4.Text = CStr(N2)'==========考生编写程序结束==============End Sub1.7上机模拟试题7解答1. 基本操作(1) 程序代码如下:Private Sub T1_Change()T2.Text = T1.TextEnd Sub(2) 程序代码如下:Private Sub C1_Click()Text1.Left = 0End Sub2. 简单操作(1)' L1.? Text1.Text 其中?改为:AddItem' L1.RemoveItem ? 其中?改为:L1.ListIndex(2) 程序代码如下:Private Sub C1_Click()If Op1 = True Then Text1 = "需要1小时"If Op2 = True Then Text1 = "需要10小时"If Op3 = True Then Text1 = "需要15小时"End Sub3. 综合应用程序代码如下:Private Sub Command2_Click()'考生应完成的程序Dim i As Integer, sum As Integer, avg As Single, tem1 As Integer, tem2 As Integer, tem3 As IntegerDim str As String, n As IntegerFor i = 1 To 100str = CStr(a(i))tem1 = Val(Mid(str, 1, 1))tem2 = Val(Mid(str, 2, 1))tem3 = Val(Mid(str, 3, 1))If tem1 ^ 3 + tem2 ^ 3 + tem3 ^ 3 = a(i) Thensum = sum + a(i)n = n + 1End IfNext iavg = Int(sum / n)Text1.Text = CStr(avg)End Sub1.8上机模拟试题8解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub HScroll1_Change()Text1.Text = HScroll1.ValueEnd SubPrivate Sub HScroll1_Scroll()Text1.Text = HScroll1.ValueEnd Sub2. 简单操作(1)' Timer1.Enabled = ? 其中?改为:True' If Shape1.Top <= ? Then 其中?改为:Line1.Y1' If Shape1.Top + ? >= Line2.Y1 Then 其中?改为:Shape1.Height(2) 程序代码如下:Private Sub Command2_Click()'考生编写Dim i As Integer, javg As Single, oavg As Single, avg As SingleDim n1 As Integer, n2 As IntegerFor i = 1 To 100If a(i) Mod 2 = 0 Thenoavg = oavg + a(i)n1 = n1 + 1Elsejavg = javg + a(i)n2 = n2 + 1End Ifavg = avg + a(i)Next ioavg = CInt(oavg / n1)javg = CInt(oavg / n2)avg = CInt(avg / 100)If Combo1.Text = "所有偶数" ThenText1.Text = CStr(oavg)ElseIf Combo1.Text = "所有奇数" ThenText1.Text = CStr(javg)ElseText1.Text = CStr(avg)End IfEnd Sub3. 综合应用' Dim ? 其中?改为:mat(M, N)' Open App.Path & "\" & "datain.txt" ? As #1 其中?改为:For Input ' ? 其中?改为:Input #1, mat(i, j)' ? 其中?改为:mat(i, 4) = t1.9上机模拟试题9解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Command1_Click()Image1.Picture = LoadPicture(App.Path + "\Misc34.ico")End SubPrivate Sub Command2_Click()Image1.Picture = LoadPicture(App.Path + "\Misc37.ico")End SubPrivate Sub Command3_Click()Image1.Picture = LoadPicture("")End Sub2. 简单操作(1)' For k = 1 To ? 其中?改为:5' If ? < Val(Text1(k).Text) Then 其中?改为:a' s = (s - a - b) / ? 其中?改为:4' s = ? * 3 * Val(Text2.Text) 其中?改为:s' ? = Int(s * 100) / 100 其中?改为:Text3(2) 程序代码如下:'需考生编写的程序Private Sub Command1_Click()Dim i As Integer, j As Integer, sum As Long, mul As Long sum = 0: mul = 1If Option1.Value = True ThenFor i = 1 To nmul = mul * iNext iText1.Text = CStr(mul)ElseFor j = 1 To nsum = sum + jNext jText1.Text = CStr(sum)End IfEnd Sub3. 综合应用' Text4 = Text4 & a & " " & ? 其中?改为:b' a = ? 其中?改为:b' If k <= ? Then 其中?改为:n' ? = d 其中?改为:b1.10上机模拟试题10解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Form_Click()Label1.Top = 0Label1.Left = Form1.Width - Label1.WidthEnd Sub2. 简单操作(1)' arrN(i) = Int(Rnd * ?) 其中?改为:1001' ? = arrN(1) 其中?改为:Min' If ? Then 其中?改为:arrN(i) < Min(2) 程序代码如下:Function Fun()Dim i As Integer, j As IntegerFor i = 0 To 1000If i Mod 7 <> 0 Then j = j + 1Next iFun = jEnd Function3. 综合应用程序代码如下:Private Sub C1_Click()Call ReadData1Call ReadData2End SubPrivate Sub C2_Click()Dim Arr3(20) As Integer, i As Integer, sum As IntegerFor i = 1 To 20Arr3(i) = Arr1(i) - Arr2(i)sum = sum + Arr3(i)Next iPrint sumCall WriteData("dataout.txt", sum)End Sub1.11上机模拟试题11解答1. 基本操作(1) 程序代码如下:Private Sub Command1_Click()Text1.Text = InputBox("请输入身高:")Text2.Text = InputBox("请输入体重:")End Sub(2) 程序代码如下:Private Sub Command1_Click()VScroll1.Min = 100VScroll1.Max = 2400rgeChange = 200VScroll1.SmallChange = 20End SubPrivate Sub VScroll1_Change()Picture1.Height = VScroll1.ValueEnd Sub2. 简单操作(1)' List1.AddItem ? 其中?改为:Text1.Text' For i = 0 To ? 其中?改为:List1.ListCount - 1' If List1.List(i) = ? Then 其中?改为:Text1.Text ' List1.RemoveItem ? 其中?改为:i(2)' Start = ?(a) 其中?改为:LBound' Finish = ?(a) 其中?改为:UBound' Max = ?(Start) 其中?改为:a' If a(i) ? Max Then Max = ? 其中?改为:>、a(i)' arr2(i) = CInt(?) 其中?改为:arr1(i)' M = FindMax(?) 其中?改为:arr23. 综合应用程序代码如下:Option Base 1Dim Arr(100) As Integer, sum As IntegerSub ReadData()Open App.Path & "\" & "datain1.txt" For Input As #1For i = 1 To 100Input #1, Arr(i)Next iClose #1End SubSub WriteData(Filename As String, Num As Integer)Open App.Path & "\" & Filename For Output As #1 Print #1, NumClose #1End SubPrivate Sub Calc_Click()Dim i As IntegerFor i = 1 To 100If i Mod 2 <> 0 ThenText1.Text = Text1.Text & Arr(i) & " "sum = sum + Arr(i)End IfNext iPrint sumEnd SubPrivate Sub Read_Click()Call ReadDataEnd SubPrivate Sub Save_Click()Call WriteData("dataout.txt", sum)End Sub1.12上机模拟试题12解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Command1_Click()Text1.FontBold = TrueEnd SubPrivate Sub Command2_Click()Text1.FontItalic = TrueEnd Sub2. 简单操作(1)' Select Case ? 其中?改为:Index' Text1.Text = ?.Text + 1 其中?改为:Text1(2)' If num = ? Then Exit For 其中?改为:num ' If ? Then 其中?改为:i > n' For j = i To ? 其中?改为:n' a(j) = ? 其中?改为:a(j + 1)' For k = 1 To ? 其中?改为:n3. 综合应用' sl = ? 其中?改为:Text1.SelLength' a(n) = ? 其中?改为:a(n) + 1' For j = ? To 26 其中?改为:2' If ? Then 其中?改为:a(j) > max_n' If ? Then 其中?改为:a(i) = max_n1.13上机模拟试题13解答1. 基本操作(1) 程序代码如下:Private Sub C1_Click()Form1.BackColor = &HFF&End Sub(2) 程序代码如下:Private Sub Form_Load()List1.AddItem 1List1.AddItem 2List1.AddItem 3List1.AddItem 4List1.AddItem 5End SubPrivate Sub List1_Click()Shape1.FillStyle = List1.TextEnd Sub2. 简单操作(1)' If ? = True Then 其中?改为:Option1(i).Value' y = val(Option1(i).?) 其中?改为:Caption' Do While i <= ? 其中?改为:5' List1.AddItem ? 其中?改为:x(2)' Timer1.Interval = ? 其中?改为:500' VScroll1.? = Picture1.Top 其中?改为:Value' Picture1.Top = ? 其中?改为:03. 综合应用程序代码如下:Private Sub Command1_Click()'========以下考生编写程序开始=======Dim i As Integer, n1 As Integer, n2 As Integer, n3 As Integer, n4 As Integer, n5 As IntegerFor i = 1 To nIf arr(i) <= 59 Thenn1 = n1 + 1ElseIf arr(i) <= 69 Thenn2 = n2 + 1ElseIf arr(i) <= 79 Thenn3 = n3 + 1ElseIf arr(i) <= 89 Thenn4 = n4 + 1Elsen5 = n5 + 1End IfNext iText1.Text = CStr(n)Text2.Text = CStr(n1)Text3.Text = CStr(n2)Text4.Text = CStr(n3)Text5.Text = CStr(n4)Text6.Text = CStr(n5)'======"考生编写程序结束"=======================End Sub1.14上机模拟试题14解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub C1_Click()HS1.Value = HS1.Value + 10End Sub2. 简单操作(1) 程序代码如下:Private Sub M1_Click()Text1.FontBold = TrueEnd SubPrivate Sub M2_Click()Text1.FontItalic = TrueEnd SubPrivate Sub M3_Click()Text1.FontUnderline = TrueEnd SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button = 2 ThenPopupMenu FormatEnd IfEnd Sub(2)' Form2. ? 其中?改为:Show' Form2.Print Form1.Frame1. ? ; ":"; 其中?改为:Caption' If Form1.Op1( ? ).Value Then 其中?改为:k' Text2. ? = "*" 其中?改为:PasswordChar3. 综合应用程序代码如下:' If ? = "123456" Then 其中?改为:Text1.Text' Text1.? = "" 其中?改为:PasswordChar' If Text2.Text > ? Then 其中?改为:0' Text1.Enabled = ? 其中?改为:False1.15上机模拟试题15解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Form_Click()List1.RemoveItem List1.ListCount - 1End SubPrivate Sub Form_Load()List1.List(List1.ListCount - 1) = "英语"End Sub2. 简单操作(1) 程序代码如下:Private Sub Option1_Click()Text1.Alignment = 0End SubPrivate Sub Option2_Click()Text1.Alignment = 2End SubPrivate Sub Option3_Click()Text1.Alignment = 1End SubPrivate Sub Option4_Click()Text1.FontName = "宋体"End SubPrivate Sub Option5_Click()Text1.FontName = "黑体"End Sub(2)' ? 其中?改为:Timer1.Enabled = False' For k = 0 To 359 Step ? 其中?改为:30' x = radius * Cos(k * 3.14159 / 180) + ? 其中?改为:X0' Line1.? = y0 - len1 * Sin(a * 3.14159 / 180) 其中?改为:Y2 ' b = ? - 30 / 12 其中?改为:b3. 综合应用' s = ? 其中?改为:0' For k = 2 To ? 其中?改为:7' getmark = s * 3 * ? 其中?改为:a(n, 8)程序代码如下:Private Sub Command2_Click()' 要求考生编写的程序Dim i As Integer, max As Single, str As String max = getmark(1)str = athlete(1)For i = 2 To 5If max < getmark(i) Thenmax = getmark(i)str = athlete(i)End IfNext iText2.Text = strText3.Text = CStr(max)End Sub1.16上机模拟试题16解答1. 基本操作(1) 程序代码如下:Private Sub Dis_Click()Text1 = "等级考试"End SubPrivate Sub Clea_Click()Text1 = ""End Sub(2) 程序代码如下:Private Sub L1_DblClick()L1.AddItem Text1End Sub2. 简单操作(1) 程序代码如下:Private Sub Form_Click()If Op1.Value = True ThenIf Op3.Value ThenLab1.Caption = "坐飞机去广州"ElseIf Op4.Value ThenLab1.Caption = "坐飞机去昆明"End IfElseIf Op3.Value ThenLab1.Caption = "坐火车去广州"ElseIf Op4.Value ThenLab1.Caption = "坐火车去昆明"End IfEnd IfEnd Sub(2) 程序代码如下:Private Sub C1_Click()If Op1.Value Thent = Text1.TextText1.Text = Text2.TextText2.Text = tLab1.Caption = "交换成功"ElseLab1.Caption = Text1.Text + Text2.TextEnd IfEnd Sub3. 综合应用程序代码如下:Dim sum as IntegerPrivate Sub C1_Click()Call ReadData1Call ReadData2End SubPrivate Sub C2_Click()Dim i As Integer, Arr3(20) As IntegerFor i = 1 To 20Arr3(i) = Int(Arr1(i) / 10) * Int(Arr2(i) / 10) sum = sum + Arr3(i)Next iPrint sumEnd SubPrivate Sub C3_Click()Call WriteData("dataout.txt", sum)End Sub1.17上机模拟试题17解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Command1_Click()Label1 = DateEnd SubPrivate Sub Command2_Click()Label1 = TimeEnd Sub2. 简单操作(1) 程序代码如下:Private Sub Command2_Click()'考生编写Dim i As Integer, avg As Single, N As IntegerFor i = 1 To 100If a(i) = (Int(Sqr(a(i)))) ^ 2 Thenavg = avg + a(i)N = N + 1End IfNext iavg = Int(avg / N)Text1.Text = CStr(avg)End Sub(2)' If Command1.Caption = ? Then 其中?改为:"演示"' ? = True 其中?改为:Timer1.Enabled' ? = False 其中?改为:Timer1.Enabled' If ? > Form1.Width Then 其中?改为:Label1.Left' Label1.Left = ? + 100 其中?改为:Label1.Left3. 综合应用' a(i) = Fix(Rnd * ? + 1) 其中?改为:9' For j = 1 To ? 其中?改为:i - 1' If b(i) > ? Then fmax = b(i) 其中?改为:fmax' If b(i) = ? Then 其中?改为:fmax' ? 其中?改为:End1.18上机模拟试题18解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Command1_Click()Text2 = Text1.SelLengthEnd Sub2. 简单操作(1)' st = ? & ch 其中?改为:st' ? = Mid(st, k, 1) 其中?改为:c' ? = "" 其中?改为:word(2)' CD1.? = "所有文件|*.*|文本文件|*.txt|Word文档|*.doc" 其中?改为:Filter ' CD1.? 其中?改为:ShowOpen' Open ? For Input As #1 其中?改为:CD1.FileName' ? 其中?改为:Close #13. 综合应用程序代码如下:Private Sub Command1_Click()'考生编写程序开始'======================================Dim i As Integer, j As Integer, a As Integer, b As Integer, max As IntegerDim n As Integern = Val(Text1.Text)For i = 2 To nFor j = 2 To nIf IsPrime(i) And IsPrime(j) ThenIf i + j = n ThenIf max < Abs(i - j) Thenmax = Abs(i - j)a = ib = jEnd IfEnd IfEnd IfNext jNext iLabel1.Caption = aLabel2.Caption = b'========================================='考生编写程序结束Open App.Path & "\out5.dat" For Output As #1Print #1, Text1.Text, Label1.Caption, Label2.CaptionClose #1End Sub1.19上机模拟试题19解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Command1_Click()Text1.PasswordChar = ""End SubPrivate Sub Command2_Click()Text1.PasswordChar = "*"End SubPrivate Sub Command3_Click()Text1.Text = ""Text1.SetFocusEnd Sub2. 简单操作(1)' ? = InputBox("请输入一个整数") 其中?改为:n' If m Mod k = ? Then 其中?改为:0' ? 其中?改为:fun = s(2)' For k = List1.ListCount - 1 To 0 ? 其中?改为:Step -1' List2.AddItem ? 其中?改为:List1.List(k)' List1.RemoveItem ? 其中?改为:k' Text1 = ? & " " & List2.List(k) 其中?改为:Text13. 综合应用' stepx = ? 其中?改为:Sgn(x - x0) * 50' ? = a * stepx 其中?改为:stepy' ? = True 其中?改为:Timer1.Enabled' ? = False 其中?改为:Timer1.Enabled' Shape1.Move Shape1.Left + stepx, Shape1.Top + ? 其中?改为:stepy1.20上机模拟试题20解答1. 基本操作(1) 程序代码如下:Private Sub Clea_Click()P1.ClsEnd SubPrivate Sub Dis_Click()P1.Print "等级考试"End Sub(2) 程序代码如下:Private Sub L1_DblClick()L1.AddItem L1.TextEnd Sub2. 简单操作(1) 程序代码如下:Private Sub Form_Click()If Op1.Value ThenIf Op3.Value ThenText1.Text = "坐" & Op1.Caption & "去" & Op3.Caption ElseIf Op4.Value ThenText1.Text = "坐" & Op1.Caption & "去" & Op4.Caption End IfElseIf Op2.Value ThenIf Op3.Value ThenText1.Text = "坐" & Op2.Caption & "去" & Op3.Caption ElseIf Op4.Value ThenText1.Text = "坐" & Op2.Caption & "去" & Op4.Caption End IfEnd IfEnd Sub(2) 程序代码如下:Private Sub Text3_Click()If Op1.Value Thent = Text1.TextText1.Text = Text2.TextText2.Text = tText3.Text = "交换成功"ElseText3.Text = Text1.Text + Text2.TextEnd IfEnd Sub3. 综合应用程序代码如下:Private Sub C1_Click()ReadData1ReadData2End SubPrivate Sub C2_Click()Dim c(20) As IntegerFor i = 1 To 20c(i) = Arr1(i) \ Arr2(i)s = s + c(i)Print sNext iEnd SubPrivate Sub C3_Click()WriteData "dataout.txt", sEnd Sub1.21上机模拟试题21解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Command1_Click()Text1.Enabled = TrueEnd SubPrivate Sub Text1_Change()Text2 = UCase(Text1)End Sub2. 简单操作(1) 程序代码如下:Private Sub Command2_Click()'考生编写Dim i As Integer, t As IntegerFor i = 1 To 10t = a(i)a(i) = a(21 - i)a(21 - i) = tNext i' 以下程序段将已变换的数组元素显示在Text2文本框中 For k = 1 To 20Text2 = Text2 + Str(a(k)) + Space(2)Next kEnd Sub(2)' If ? Then 其中?改为:sl = 0' For i = 1 To ? 其中?改为:sl' a(n) = ? 其中?改为:1' For i = 1 To ? 其中?改为:263. 综合应用' n =? 其中?改为:n - 1' ? = Text1 其中?改为:stud(n).Num' For k = ? To n 其中?改为:j + 1 To n' If stud(k).Average > stud(j).? Then 其中?改为:Average ' stud(k) = ? 其中?改为:stud(j)1.22上机模拟试题22解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Command1_Click()CommonDialog1.Action = 2End Sub2. 简单操作(1)' Line1.Y2 = ? 其中?改为:Y' Line1.X2 = Line1.? 其中?改为:X1' Line1.Y2 = y0 - ? 其中?改为:radius' ? = "鼠标位置不对" 其中?改为:Label1.Caption(2)' If n > ? Or n < 8 Then 其中?改为:12程序代码如下:Private Sub Command2_Click()Dim s As Long, k As Integers = 0For k = 1 To ns = s + f(k)Next kText1.Text = sEnd SubFunction f(n As Integer) As Long' s = ? 其中?改为:1' f = ? 其中?改为:sEnd Function3. 综合应用' n = n + ? 其中?改为:1' ElseIf finduser(Trim$(Text1)) > ? Then 其中?改为:0' ? = "注册成功!" 其中?改为:bel1.Caption' If k = ? Then 其中?改为:0' ElseIf Trim$(Text2) <> users( ? ) Then 其中?改为:k, 2 1.23上机模拟试题23解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Command1_Click()Text2.Text = Text1.SelStartText3.Text = Text1.SelLengthEnd Sub2. 简单操作(1)' HScroll1.Max = Shape2.Width + Shape2.Left - Shape1. ? 其中?改为:Shape1.Width ' VScroll1.Max = Shape2.Height + ? - Shape1.Height 其中?改为:Shape2.Top ' ? = HScroll1.Value 其中?改为:Shape1.Left' Shape1.Top = ? 其中?改为:VScroll1.Value(2)' Timer1.? = True 其中?改为:Enabled' ? = False 其中?改为:Timer1.Enabled' d = ? - Image1.Top 其中?改为:d' t = ? 其中?改为:t + 13. 综合应用程序代码如下:Private Sub Command2_Click()'考生编写程序开始'======================================For k = 1 To 30c(k) = a(k)c(30 + k) = b(k)Next kFor i = 1 To 59For j = i + 1 To 60If c(i) > c(j) Thent = c(i)c(i) = c(j)c(j) = tEnd IfNext jNext i'========================================='考生编写程序结束' 以下程序将合并后的数组C显示在Text3中For k = 1 To 60Text3 = Text3 + Str(c(k)) + Space(2)Next kEnd Sub1.24上机模拟试题24解答1. 基本操作(1) 程序代码如下:Private Sub Clea_Click()ClsEnd SubPrivate Sub Dis_Click()Print "等级考试"End Sub(2) 程序代码如下:Private Sub L1_DblClick()Lab1.Caption = L1.ListCountEnd Sub2. 简单操作(1) 程序代码如下:Private Sub Text1_Click()If Op1 = True ThenIf Op3 = True ThenText1 = "坐汽车去青岛"ElseText1 = "坐汽车去大连"End IfElseIf Op3 = True ThenText1 = "坐轮船去青岛"ElseText1 = "坐轮船去大连"End IfEnd IfEnd Sub(2) 程序代码如下:Private Sub C1_Click()If Op1 = True ThenText1 = "计算机"Text2 = "等级考试"Lab1 = "交换成功"ElseLab1 = "计算机" & "等级考试"End IfEnd Sub3. 综合应用程序代码如下:1.25上机模拟试题25解答1. 基本操作(1) 程序代码如下:Private Sub Command1_Click()Form1.Caption = Text1.Text & "," & Label2.Caption & " " & Text2.Text End Sub(2) 程序代码如下:Private Sub HScroll1_Scroll()Form1.Width = HScroll1.ValueForm1.Height = HScroll1.ValueEnd SubPrivate Sub VScroll1_Change()Form1.Width = VScroll1.ValueForm1.Height = VScroll1.ValueEnd Sub2. 简单操作(1)' List1.AddItem ? 其中?改为:Text1.Text' For i = 0 To ? 其中?改为:List1.ListCount - 1' If List1.List(i) = ? Then 其中?改为:Text1' List1.RemoveItem ? 其中?改为:i(2)' Start = ?(a) 其中?改为:LBound' Finish = ?(a) 其中?改为:UBound' Sum = ? 其中?改为:0' Sum = Sum + ? 其中?改为:a(i)' Average = ? 其中?改为:Sum / (Finish - Start + 1) ' Aver = Average(?) 其中?改为:arr23. 综合应用程序代码如下:Private Sub Calc_Click()For i = 1 To 100If Arr(i) Mod 3 = 0 Thensum = sum + Arr(i)Text1.Text = Text1.Text + CStr(Arr(i)) + Space(2)End IfNext iPrint sumEnd SubPrivate Sub Read_Click()Call ReadDataEnd SubPrivate Sub Save_Click()Call WriteData("dataout.txt", sum)End Sub1.26上机模拟试题26解答1. 基本操作(1) 程序代码如下:Private Sub Dis_Click()Text1 = "等级考试"End SubPrivate Sub Exit_Click()EndEnd Sub(2) 程序代码如下:Private Sub L1_DblClick()L1.RemoveItem L1.ListIndexEnd Sub2. 简单操作(1) 程序代码如下:Private Sub C1_Click()If Op1.Value ThenIf Op3.Value ThenText1.Text = "坐" & Op1.Caption & "去" & Op3.Caption ElseIf Op4.Value ThenText1.Text = "坐" & Op1.Caption & "去" & Op4.Caption End IfElseIf Op2.Value ThenIf Op3.Value ThenText1.Text = "坐" & Op2.Caption & "去" & Op3.Caption ElseIf Op4.Value ThenText1.Text = "坐" & Op2.Caption & "去" & Op4.Caption End IfEnd IfEnd Sub(2) 程序代码如下:Private Sub Op1_Click()t = Text1.TextText1.Text = Text2.TextText2.Text = tText3.Text = "交换成功"Op1.Visible = FalseEnd SubPrivate Sub Op2_Click()Text3.Text = Text1.Text + Text2.TextEnd Sub 3. 综合应用程序代码如下:Private Sub C1_Click()ReadData1ReadData2End SubPrivate Sub C2_Click()Dim Arr3(20) As IntegerFor i = 1 To 20Arr3(i) = Arr1(i) + Arr2(i)s = s + Arr3(i)Next iPrint sEnd SubPrivate Sub C3_Click()WriteData "dataout", sEnd Sub1.27上机模拟试题27解答1. 基本操作(1) 略(2) 程序代码如下:Private Sub Command1_Click()Label1.FontName = "宋体"End SubPrivate Sub Command2_Click()Label1.FontName = "黑体"End Sub2. 简单操作(1)' ? = Str(Time()) 其中?改为:Text1(0).Text' s = ? + (m - 3) * 0.15 其中?改为:s' ?= True 其中?改为:Cmd1.Enabled' ?= False 其中?改为:Cmd2.Enabled(2)' Open App.Path & "\in4.txt" For ? As #1 其中?改为:Input' s(i) = ? 其中?改为:s(i) + a(i, j)' ? = CInt(s(i) / 10) 其中?改为:s(i)' Shape1(k - 1).Top = ? - Shape1(k - 1).Height 其中?改为:m' Shape1(k - 1).? = True 其中?改为:Visible3. 综合应用程序代码如下:Private Sub Command2_Click()'需考生编写Dim n As Integer, i As Integer, c As String, lastword As StringDim curword As String, maxword As String, curlen As Integer, maxlen As Integer n = Len(s)For i = 1 To nc = Mid(s, i, 1)If c <> " " Thencurword = curword & ccurlen = curlen + 1ElseIf maxlen <= curlen Thenmaxlen = curlenmaxword = curwordEnd Ifcurlen = 0curword = ""End IfNext iIf maxlen <= curlen Thenmaxlen = curlenmaxword = curwordEnd IfText1.Text = CStr(maxlen)Text2.Text = maxwordEnd Sub。
vb习题集和答案
第一章选择题1. VB是一种面向对象的可视化程序设计语言,采取了( A )的编程机制。
(A)事件驱动 (B) 按过程顺序执行(C)从主程序开始执行 (D) 按模块顺序执行2. 以下不属于VB的工作模式的是(c )模式。
(A) 运行(B)设计(C) 编译(D)中断3. 在VB集成环境创建VB应用程序时,除了工具箱窗口、窗体窗口、属性窗口外,必不可少的窗口是( C )。
(A)窗体布局窗口(B)立即窗口(C)代码窗口(D)监视窗口4. 保存新建工程时,默认的路径是( B )。
(A)My Documents (B)VB98 (C)\ (D)Windows5. 将调试通过的VB工程经“文件”菜单的“生成.exe文件”编译成.exe后,将该可执行文件拿到其他机器上不能运行的主要原因是( A )。
(A)运行的机器上无VB系统(B)缺少.frm窗体文件(C)该可执行文件有病毒(D)以上原因都不对6. VB6.0集成开发环境可以( D )。
(A)编辑、调试、运行程序,但不能生成可执行程序(B)编辑、调试、生成可执行程序,但不能运行程序(C)编辑、生成可执行程序、运行程序,但不能调试(D)编辑、调试、运行程序,也能生成可执行程序7. VB6.0集成环境的主窗口中不包含( B )。
(A)菜单栏(B)状态栏(C)标题栏(D)工具栏8. 在设计阶段,当双击窗体上的某个控件时,所打开的窗口是( C )。
(A)工程资源管理器窗口(B)工具箱窗口(C)代码窗口(D)属性窗口9. 下面四个选项中,不是VB6.0工具箱的标准控件的是( C )。
(A)滚动条(B)定时器(C)多媒体(D)框架10. VB6.0的(C )版本,可供专业编程人员开发功能强大的组内分布式应用程序。
(A)初级版(B)学习版(C)企业版(D)专业版11. 英文缩写“OOP”的含义是( A )。
(A)面向对象程序设计(B)结构化程序设计语言(C)事件驱动的编程机制(D)可视化程序设计12. 不能打开代码窗口的操作是( B )。
VB 课后习题参考答案
第1章 习题参考答案一、思考题 略二、选择题1. C2. B第2章 习题参考答案一、判断题二、填空题1. 窗体font2. 不能在代码中设置 3. selstart 4. Locked5. TabIndex 、 0 6. vbModal 或 17. Activate 、 Deactivate 8.PictureBox 和 Frame -三、选择题第3章 习题参考答案一、思考题1、double2、 xyC@abc , 15eyd , Is , #END X8[P]3、变量有 (1) (4) (6) (8),常量有 (2)字符串型 (3)逻辑型 (5)字符串型 (7)字符串型 (9)日期型 (10)实型 4、 fe d cb a++5、 (1) 26 (2) 3.75 (3) 36、写出下列Visual Basic 表达式的值:(1) False (2) True (3) True (4) False (5) True(6) True (7) False (8) False7、将下列命题用Visual Basic布尔表达式表示:(1) z>x and z>y (2) abs(a)<=abs(b+2) or a > b+2(3) p mod q=0 (4) x<-5 or x>-2 and x<2 or x>5(5) x<z and y>z or x>z and y<z (6) a<b and a mod 2=08、写出下列函数的值:(1) -4 (2) 换行符(3) –3 (4) -1 (5) hello(6) ello (7) 16 (8) “-459.65” (9) 5二、填空题1.整型、长整型、双精度型、双精度型2.(X mod 10)*10+X\103.sin(1/4*3.14)+sqr(x+2*exp(y))/abs(x-y)4.(a+b)/(c*d-sqr(1-a^2))5.x mod 5=0 or x mod 9=06.False7.-3 、 2 、-2 、 28.CDEF9.x>0 and y>0 or x<0 and y<0 或x*y>010.s>=”A” and s<=”Z” or s>=”a” and s<=”z”三、选择题四、编程题1、Private Sub Form_Click()Dim x%, Ten%, hundred%x = Val(Text1.Text)Ten = (x \ 10) Mod 10hundred = x \ 100Print "百位数是: " & hundredPrint "十位数是: " & TenEnd Sub2Private Sub Form_Click()Dim char As String * 1Form1.CurrentX = Rnd * Form1.ScaleWidthForm1.CurrentY = Rnd * Form1.ScaleHeightchar = Chr(Int(Rnd * 16) + 65)Print charEnd Sub第4章习题参考答案一、判断题二、选择题三、程序阅读写出下列各段程序执行后的输出结果。
VB程序设计练习册参考答案
参考答案第1章Visual Basic 简介一、选择题1、B2、C3、A4、D5、C6、A7、D8、C9、D 10、B11、C 12、B二、填空题1 过程对象事件驱动2 学习版专业版企业版企业版3 Alt+F4 Alt+Q4 设计运行中断5 设置在应用程序运行时,各窗体在屏幕上的显示位置6 内部(标准)7 资源管理器8 编译方式解释方式9 选择“视图/工具箱”命令10 print 或?“大家都来学用Visual Basic”11按字母序按分类序12编辑代码三、思考题略第2章Visual Basic程序设计概述一、选择题1、A2、A3、D4、D5、D6、C7、A 8、C 9、A 10、C 11、B 12、D13、C 14、C 15、B 16、B 17、D 18、B三、编程题1、(1)建立应用程序用户界面。
选择”新建”工程,进入窗体设汁器,在窗体中增加一个标签控件Labe11和两个命令按钮 Commandl 、 Comlnand2。
(2)设置对象属性,见表。
(可自由设置)3编写代码private sub command1_clicklabel1.visible=false1 窗体 控件2 Left Top Width Height3 Ctrl 或shift4 Scrollbars Multiline True Passwordchar5 事件过程6 在属性窗口设置 在代码窗口设置7 对象名 下划线 事件名8 Form_Click9 Form1.Hide10 界面设计 属性设置 代码编写 保存运行11 窗体文件 工程文件12 部件13 窗体文件 模块文件 类模块文件private sub command2_clicklabel1.visible=trueend sub2、Private Sub Command1_ClickIf Text1.Text<>””And Text2.Text<>””Then ′组合条件判断文本框是否为空Form1.Caption=Text1.Text & ″,″& Label2.Caption & ″″& Text2.Text End IfEnd Sub第3章Visual Basic程序设计基础一选择题1.B2.C3.D4.B5.B6.B7.D8.D9.C10.C11.D 12.C 13.D 14.D 15.A 16.D 17.D 18.D 19.C 20.C21.A22.D23.B24.A 25.B 26.A二、填空题1 our name is2 13 True4 字母数字下划线2555 56 07 Logx/log10/0.5+x^2或者Logx/log10/0.5+x*x8 0,1,2,3,49 x>=0 and x<10010 511 false12 6三、编程题1.提示:Ucase、Lcase的使用2.提示:属性设置中,“计算”按钮的default属性设为True.“清除”按钮的Cancel属性设为True.第4章数据输入输出一、选择题1、D2、A3、A4、B5、D6、B7、C 8、C 9、D 10、D二、填空题1. 1+1= 22+2=42. 500.00%3.将当前字体放大两倍4. 20-11-025. 11 1三、编程题1.提示:(1)流程图。
VB机试模拟试卷1(题后含答案及解析)
VB机试模拟试卷1(题后含答案及解析)题型有:1. 基本操作题 2. 简单应用题 3. 综合应用题基本操作题(30分)1.注意:下面出现的“考生文件夹”均为c;\wexam\25160001。
请根据以下各小题的要求设计Visual Basic应用程序(包括界面和代码)。
(1)在窗体上建立一个二级菜单,该菜单含有“文件”和“帮助”(名称分别为vbFile和vbHelp)两个主菜单项,其中“文件”菜单包括“打开”、“关闭”和“退出”三个子菜单项(名称分别为vbOpen、vbClose和vbExit),如图1-1所示。
只建立菜单,不必定义其事件过程。
注意:保存时必须存放在考生文件夹下,窗体文件名为sjt1.frm,工程文件名为sjt1.vbp。
(2)在名为Form1的窗体上画一个框架,名称为Frm1,标题为“框架”,高度为2500,宽度为4000,框架内建立一文本框,距左边框600,距框架的上边框1200,文本框中的初始内容设置为“文本框”。
如图1-2所示。
注意:保存时必须存放在考生文件夹下,窗体文件名为sjt2.frm,工程文件名为sjt2.vbp。
正确答案:(1)在Visual Basic中,菜单项通过菜单编辑器来建立。
解题步骤:第一步:打开“菜单编辑器”窗口,建立菜单项。
用到的菜单项及其属性见表1-1。
第二步:调试并运行程序。
第三步:按题目要求存盘。
(2)在窗体上建立好控件后,再按题目要求设置各自的属性即可。
需要指出的是在框架里的控件需要画出框架后,单击工具箱里的控件然后在框架里拖动画出所需控件,不可以用双击的方法,否则所需的控件放不到框架里。
窗体中的控件的具体位置由控件的Top、Left属性设置,大小由属性Height Width设置。
解题步骤:第一步:设置框架的Height、Width属性分别为2500,4000;文本框的Left、Top 属性值分别为600,1200。
(以上均可在属性栏里没置) 第二步:调试并运行程序。
vb题库及答案
vb题库及答案最新VB题库及答案⼀、选择题第1部分1、在窗体(名称为Form1)上画⼀个名称为Text1的⽂本框和⼀个名称为Command1的命令按钮,然后编写⼀个事件过程。
程序运⾏后,如果在⽂本框中输⼊⼀个字符,则把命令按钮的标题设置为“计算机等级考试”。
以下能实现上述操作的事件过程是A、Private Sub Text1_Change()= "计算机等级考试"End SubB、Private Sub Command1_Click()Caption = "计算机等级考试"End SubC、Private Sub Form_Click()= "计算机等级考试"End SubD、Private Sub Command1_Click()= "计算机等级考试"End Sub2、在⼀⾏内写多条语句时,每个语句之间⽤()符号分隔。
A、,B、:C、.D、;3、下⾯()是合法的变量名。
A、X_YZB、123ABCC、INTEGERD、X-Y4、下⾯()是合法的字符常量。
A、ABC$B、“ABC”C、‘ABC’D、ABC5、表达式16/4 - 2^5*8 MOD 5\2的值为()。
A、14B、4C、20D、26、设a=”MicrosoftVisualBasic”,则以下使变量的b值为”VisualBasic”的语句是A、b=Left(a,10)B、b=Mid(a,10)C、b=Right(a,10)D、b=Mid(a,11,10)7、设a="a",b="b",c="c",d="d",执⾏语句x = IIf((a < b) Or (c > d), "A", "B")后,x 的值为A、"a"B、"b"C、"B"D、"A"8、在窗体上画⼀个⽂本框,然后编写如下事件过程:Private Sub Form_Click()x = InputBox("请输⼊⼀个整数")Print x +End Sub程序运⾏时,在⽂本框中输⼊456,然后单击窗体,在输⼊对话框中输⼊123,单击“确定”按钮后,在窗体上显⽰的内容为A、123B、456C、579D、1234569、在BASIC中,三个逻辑运算符NOT,AND,OR在运算过程中,优先级从⾼到低的顺序是()。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
程序之外的是注释说明,程序本身不需要。
第一套VB'完善程序代码实现当单击"输入并排序"按钮后,从键盘输入5个数,保存在数组中,并显示在窗体上,然后把这5'个数按照从小到大的顺序排列并显示在窗体上。
'注:请不要更改原程序结构,删除①、②、③及下划线,并在对应位置填写正确的代码。
Private Sub Command1_Click()Dim x As LongDim n As Integer, i As Integer, s As LongDim a(1 To 5) As SingleFor i = 1 To 5a(i) = Val(InputBox("请在输入第" + Str(i) + "/5个数"))Print a(i);Next iPrintFor i = 1 To 4 (排序数的个数减1,5-1=4)Min = a(i): m = iFor x = i + 1 To 5If Min > a(x) Then Min = a(x): m = x (求最小值min ,min比其他值大则min要新值,保持最小)Next xk = a(i): a( I ) = a(m): a(m) = k (两变量交换数值)Next iPrint "从小到大排序后的数据为:"For i = 1 To 5Print a(i);Next iEnd Sub第二套'完善程序代码实现:输入三角形的三条边长,首先判断给出的三条边能否构成三角形(三角形的两边之和大于第'三边),如可以,则计算并输出该三角形的面积;否则输出"不能构成三角形"。
'注:请不要更改原程序结构,删除①、②、③及下划线,并在对应位置填写正确的代码。
Private Sub Command1_Click()Dim a, b, c, q, s As Singlea = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)q = (a + b + c) / 2Print "不能构成三角形"Elses = Sqr(q * (q - a) * (q - b) * (q - c)) (Sqr 平方根函数,Abs 绝对值函数)Print "三角形的面积是" & sEnd IfEnd Sub第三套'删除①②③及下划线,填上正确的代码,画出如下所示的图形,请不要更改原程序结构。
'*******' *****' ***' *Private Sub Command1_Click()Dim i, j, k As IntegerFor i = 4 To 1 Step -1 (循环变量初值比终值大,步长为负数)For j = 1 To 2 * i - 1Step 1 (终值与外循变量结合起来,达到循环次数变化需要)Print "*"; '打印符号*Next j (FOR循环的结束语句)Print '换行For k = i - 3 To 1Print " ";'打印空格Next kNext iEnd Sub第四套'判断某年是否为闰年的方法是如果该年份的数值能被4整除但不能被100整除,或者能被400整除则该年份是闰年。
'注:请不要更改原程序结构,删除①、②、③及下划线,并在对应位置填写正确的代码。
Private Sub Command1_Click()Dim i As Longi = Val(Text1.Text) (V AL是把字符型转换数值型的转换函数)If i Mod 4 = 0 And i Mod 100 <> 0 Or i Mod 400 = 0 Then (Mod是求余函数)Label2.Caption = "该年是闰年!"ElseLabel2.Caption = "该年不是闰年!"第五套先新建命令按钮,并将命令按钮的外观文字设为开始'(1)删除①②及下划线,填空完成程序。
'(2)完善程序代码实现:手动输入0到10以内的一个整数,如果这个数字正好等于随机产生的整数(0到10之内),'那么输出"恭喜您猜中了!",否则输出"谢谢,重在参与!"。
'注:请不要更改原程序结构,删除①、②及下划线,并在对应位置填写正确的代码。
Private Sub Command1_Click()Dim i, j As IntegerRandomizei = Int(Rnd * 10) (Int(n)是取不大于n的整数部分,如int(4.5)=4,int(-4.5)=-5Rnd是产生0到1的随机小数,Rnd*10得到0到10的随机数)j = Val(InputBox("请您输入一个0-10之间的整数:"))Print "您选中的数字为:" & jPrint "随机产生的数为:" & iIf j = i ThenPrint "恭喜您猜中了!"ElsePrint "谢谢,重在参与!"第六套先新建命令按钮,并将命令按钮的外观文字设为计算'凡在商场消费满500元以上(含500元),享受9折优惠;消费满1000元以上(含1000元),享受8折优惠;消费在500元以下不优惠。
'输入消费金额,计算出实收金额。
'注:请不要更改原程序结构,删除①、②、③及下划线,并在对应位置填写正确的代码。
Private Sub command1_click()Dim m As Single '消费金额m = Val(Text1.Text) (V AL是把字符型转换数值型的转换函数)If m >= 1000 ThenText2.Text = m * 0.8If m >= 500 ThenText2.Text = m * 0.9ElseText2.Text = mEnd IfEnd IfEnd Sub第七套'在Text1中输入每月用电量,单击按钮"应收电费"后,在Text2中输出电费。
收费标准:家庭每月用电量不超过260度'按原价1.3元/度收费;超过260度,不超过400度每度电费用增加0.1元;超过400度后每度电费用增加0.3元。
'注:请不要更改原程序结构,删除①、②、③及下划线,并在对应位置填写正确的代码。
Private Sub Command1_Click()Dim i As Singlei =Val(Text1.Text) (V AL是把字符型转换数值型的转换函数)If i >= 0 And i <= 260 Then s = i * 1.3If i > 260 And i <= 400 Then s = i * (1.3 + 0.1)If i > 400 Then s = i * (1.3 + 0.3)Text2.Text = s & "元" (结果显示在文本框2中)End Sub第八套'完善程序代码实现:任意输入一个1到100以内的整数,并求出它的阶乘。
'注:请不要更改原程序结构,删除①、②、③及下划线,并在对应位置填写正确的代码。
Private Sub Command1_Click()Dim i As IntegerDim j As IntegerDim s As Doubles = 1 (S为积,初值为1。
)i = Val(InputBox("请您输入一个1到100以内的整数"))For j = 1 To is = s * j (阶乘运算,2!=1*2;3!=1*2*3)Next (For循环的结束语句)Print i & "的阶乘等于" & sEnd Sub第九套'下面的程序是求100以内所有奇数之和,程序中有三处错误,请更正。
'注:请不要更改原程序结构。
Private Sub Command1_Click()Dim s As IntegerDim i As Integers = 0For i = 1 To 99 Step 2 (奇数,1、3、5、7等,步长为2)s = s + I (求和运算)Next (For循环的结束语句)Print "s=" & sEnd Sub第十套先新建命令按钮,并将命令按钮的外观文字设为转换'在Text1中输入学生的成绩,点击“转换”按钮后,转换成相应的等级并显示在Label1中!'Private Sub Command1_Click()Dim exam As Integerexam = Int(Val(Text1.Text)) (INT取整,V AL 转换)Select Case exam (exam为考查变量)Case Is < 60Label1.Caption = "该学生的成绩等级为:D"Case 60 To 69Label1.Caption = "该学生的成绩等级为:C"Case 70 To 84Label1.Caption = "该学生的成绩等级为:B"Case 85 To 100Label1.Caption = "该学生的成绩等级为:A"Case ElseLabel1.Caption = "输入的数据不合法"End Select (结束语句)End Sub模拟题'(1)删除①②③④及下划线,填空完成程序。
'(2)在文本框Text1中输入成绩,点击"等级"按钮时,文本框里就显示相应的等级。
具体等级划分如下:' 90分以上为"优",80到89分为"好",70到79分为"良",60到69分为"及格",60分以下为"不及格"。
'注:请不要更改原程序结构,删除①、②、③、④及下划线,并在对应位置填写正确的代码。