vb程序阅读题与填空题_第1页
vb程序阅读题与填空题_第2页
vb程序阅读题与填空题_第3页
vb程序阅读题与填空题_第4页
vb程序阅读题与填空题_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、VB程序阅读题与程序填空题综合练习1、阅读下面程序,当单击窗体之后,窗体上输出的是 。Private Sub Form_Click( )Dim i As Integer, j As IntegerDim k As Integer k=0For i = 0 To 10 Step 3For j = 1 To 10If j > = 5 Then i = i +4: Exit Forj = j + 1k = k + 1NextIf i > 8 Then Exit ForNextPrint kEnd Sub2、阅读下面的事件过程。单击窗体后,在文本框Text1和Text2中显示的内容分别是

2、和 ;若将程序中A语句与B语句的位置互换,再次执行程序,单击窗体后在Text1和Text2中显示的内容分别是 和 。Private Sub Form_Click( )Dim x As Integer, y As Integerx = 1 : y = 0Do While x < 3y = y + x 'A语句x = x + 1 'B语句LoopText1.Text = xText2.Text = yEnd Sub 3、下面程序段中,k循环共执行 次,在窗体上显示的结果是 。Dim b As Integer, k As Integerb = 1For k =1 To 5 b

3、= b * kIf b > = 15 Then Exit ForElsek = k + 1End IfNext kPrint k, b4、以下是按钮cmdl的Click事件过程,求1100之间的所有质数。质数的个数显示在窗体上,在划线处填上缺少的内容。Private Sub cmdl_Click( )Dim intNum As Integer, int1 As Integer, int2 As IntegerintNum = 0For int1 = For int2 = 2 To int1 2If (int1 Mod int2) = 0 Then intNum=1End IfNext I

4、f sNum = sNum + 1End IfNextPrint End Sub5、若命令按钮的名称为CmdExit,程序要求单击以上命令按钮时,程序停止运行。请在画线处中填入适当的内容。Private Sub CmdExit_ ( ) End Sub6、下面的事件过程判断文本框txt1中输入的数所在区间,并在文本框txt2中输出判断结果。在画线处填入正确的内容。Private Sub Comandl_Click( )Dim int1 As Integerint1 =val (txt1.Text)Select Case int1Case txt2.Text = "值为0"C

5、ase txt2.Text = "值在1和10之间(包括1和10)"Case txt2.Text = "值大于10"Case Else txt2.Text = "值小于0"End SelectEnd Sub四、读程序题,写出程序运行结果。1运行结果:Private Sub Form_Click() For I = 1 To 9 For j = 1 To 30 - 3 * I Print " " Next j For k = 1 To I Print k; Next k For k = I - 1 To 1 Step

6、 -1 Print k; Next k Print Next IEnd Sub2运行结果:Private Sub Command1_Click() Static S As Integer Dim i As Integer S = 1 For i = 1 To 5 S = S * i Next i Print SEnd Sub3运行结果:For X = 5 To 1 Step 1 For Y = 1 To 6 - X Print Tab(Y + 5); "*" Next Y PrintNext X4运行结果:S = 0: T = 0: U = 0 For X = 1 To 3

7、 For Y = 1 To X For Z = Y To 3 S = S + 1 Next Z T = T + 1 Next Y U = U + 1Next XPrint S; T; U5运行结果:Private Sub Command1_Click() Dim b As Integera = 3.6b = 3.6Text1.Text = aText2.Text = bEnd Sub2以下程序判断从文本框Text1中输入的数据,如果该数据满足条件:除以3余2,除以5余3,除以7余4,则输出;否则将焦点定位在文本框Text1中,选中其中的文本。 Private Sub Command_Click

8、() X = Val(Text1.Text) If (1) Then Print XElse (2) (3) (4) End IfEnd Sub五、编程题1设计一个计算程序。该程序用户界面如图所示,由四个文本框:文本框1(text1)、文本框2(text2)、文本框3(text3)、文本框4(text4),和三个按钮:命令按钮1(command1)、命令按钮2(command2)、命令按钮3(command4)组成程序运行后,用户按清除按钮,则清除文本框中显示的内容,按计算按钮,则计算三科平均成绩。单击退出按钮则退出。Private Sub Command1_Click() Text1.Tex

9、t = 1 Text2. 2= ""2 3.Text = "" 3End SubPrivate Sub Command2_Click() If Text1. 4= " " Or Text2.Text = 5 Or Text3.Text = " " Then4 MsgBox "成绩输入不全!" 5 Else Text4.Text = (6 + Val(Text2.Text) 6 + Val(Text3.Text) / 7 7 8 8 End SubPrivate Sub Command3_Clic

10、k()Unload 99 10 Sub10 3设计一个欢迎程序。该程序用户界面如图所示。要求程序运行后,用户选中粗体复选框时 “欢迎您!”几个字的字体变成粗体,用户选中斜体复选框时 “欢迎您!”几个字的字体变成斜体。若取消选中,则恢复原字体。按结束,则退出。4任给3个数,求其中间数,写出程序代码。三、阅读程序题1阅读下列程序并写出程序运行结果Private Sub Form_Click() Dim s As Long, f As Long, n As Integer, i As Integer n = 3 For i = 1 To n f = f + i s = s + f Next Prin

11、t "s=" sEnd Sub写出程序运行时单击窗体后,窗体Form1上的输出结果。运行结果:2阅读下列程序并写出程序运行结果Private Sub Command1_Click() x = 0 Do While x < 100 x = (x + 2) * (x + 4) n = n + 1 Loop Text1.Text = Str(n) Text2.Text = Str(x) Text3.Text = Val(Text1.Text) + Val(Text2.Text)End Sub文件框Text3的结果是:运行结果:3阅读下列程序并写出程序运行结果Private

12、Sub Command1_Click() Dim Sum1 As Integer, Sum2 As Integer Sum1 = 0: Sum2 = 1 For I = 1 To 4 For J = 1 To I Sum2 = Sum2 * J Next J Sum1 = Sum1 + Sum2Next IPrint Sum1End Sub 写出程序运行时单击命令按纽后,窗体上的输出结果。运行结果:4. 阅读下列程序并写出程序运行结果Private Sub Command1_Click() Dim x As Integer6阅读下列程序并写出程序运行结果Private Sub Command1

13、_Click()Dim A(2 To 7) As Integer Dim b As IntegerFor b = 2 To 7A(b) = bNext bText1.Text = A(b - 2)End Sub程序运行后,单击命令按纽文本框Text1的结果是:Static s As Integer x = Val(InputBox("请输入一个正整数=") If x < 6 Then s = s * x Else s = s + x End If Text1.Text = "s=" & Str(s)End Sub程序运行时连续3次单击Com

14、mand1,且设输入的数据为6、5、4时,分别写出文本框Text1的值。5阅读下列程序并写出程序运行结果Private Sub Form_Click() Dim A(1 To 3) As String Dim c As Integer,j As Integer A(1) = “2” A(2) = “4” A(3) = “6” c=0 For j=1 to 3 c = c + Val(A(j)Next jPrint cEnd Sub 写出程序运行时单击窗体后,窗体Form1上的结果: 11. 阅读下列程序并写出程序运行结果 Private Sub Form_Click( ) Static Sum

15、 As Integer I=1 While i<=3 Sum=Sum+I I=I+1 Wend Print Sum End Sub点击两次后,Sum的值应该是:运行结果:7阅读下列程序并写出程序运行结果Sub test(i As Integer) i = i + 1End SubPrivate Sub Form_Click() Dim x As Integer x = 4 Print "x=" xCall test(x) Print "x=" xEnd Sub8. 阅读下列程序并写出程序运行结果Private Sub Form_Click() a

16、= 1: b = 1 Print "A=" a; ",B=" b Call mult(a) Print "A=" a; ",B=" bEnd SubPrivate Sub mult(x) x = 2 * x b = 3 * bEnd Sub9. 阅读下列程序并写出程序运行结果Private Sub Form_Click() Dim i As Integer, a As Integer k = 0 For i = 1 To 6 If i > 3 Then a = a + 4 Else a = a + 1 End

17、 If Next iPrint i, aEnd Sub 写出程序运行时单击窗体后,Form1上的输出结果。10. 阅读下列程序并写出程序运行结果Sub Change(ByVal x As Integer, ByVal y As Integer) Dim t As Integer t=x x=y y=t Print x,yEnd subPrivate Sub Form_Click() Dim a As Integer, b As Integer a = 3: b = 4Change a, b Print a,bEnd Sub 写出程序运行时单击窗体后,Form1上的输出结果 (20) 

18、下列程序段执行结果为 ( )x=5 y=-6 If Not x>0 Then x=y-3 Else y=x+3 Print x-y; y-x A) -3 3  B) 5 -9 C) 3 -3  D) -6 5 (23) 单击命令按钮时,下列程序的执行结果为 ( )Private Sub Command1_Click()  Dim x As I

19、nteger, y As Integer x=12:y=32  Call Proc(x,y)  Print x; y End Sub Public Sub Proc(n As Integer, ByVal m As Integer)  n=n Mod 10 m=m Mod 10 End Sub A) 1232  B) 232 C)

20、0;23  D) 123 二、填空题(1) 完成下面的程序,使显示结果如下图所示。 Private Sub Form_Click()  FontSize=18 Sample=" 【1】  " x=(ScaleWidth-TextWidth(Sample) ) /2 y=(ScaleHeight-TextHeight(Sample) ) /2 CurrentX=x CurrentY=y 【2】  Sample End Sub (2)

21、60;下列程序的功能是:当x<50时,y=0.8×x;当50x100时,y=0.7×x;当x>100时,没有意义。请填空。 Private Sub Command1_Click()  Dim x As Single x=InputBox("请输入x的值!")  【3】   Case Is < 50 y=0.8 * x Case 50 To 100 y=0.7 *

22、0;x 【4】   Print "输入的数据出界!" End Select Print x, y End Sub 35.窗体上有Text1、Text2两个文本框及一个命令按钮Command1,编写下列程序: Dim y As Integer Private Sub Command1_Click() Dim x As Integer x=2 Text1.Text= p2(p1(x),y) Text2.Text= p1(

23、x) End Sub  Privage Function P1(x As Integer) As Integer x =x+y:y=x+y P1=x+y End Function Private Function P2(x As Integer, y As Integer) As Integer P2= 2*x+y End Function 当单击1 次和单击2次命令按钮后,文

24、本框Text1和Text2内的值分别是(C) 5执行了以下的程序后,列表框中的数据项有_。Sub Form_click()For i=0 To 4List1.AddItem iNextFor i=1 To 2 List1.RemoveItem iNextEnd sub31.如下程序,运行的结果是(B) Private Sub Form_Click() Dim m As Integer,i As Integer,x(10) As Integer For i= 0 to 

25、;4 x(i)=i + 1 Next i For i=1 to 2 Call proc(x) Next i For i= 0 to 4 Print x(i); Next i End Sub  Public Sub proc(a() As Integer) Static i As Integer Do a(i)=a(i)+a(i+1) i=i+1 Loop W

26、hile i<2 End Sub  32.假设有以下程序段: For I=1 to 3 For j=5 to 1 Step -1 Print I*j Next j Next I 则语句Print I*j的执行次数I、j的值分别是(A) 33.在窗体上一个文本框,其名称为Text1,然后编写如下事件过程: Private Sub Text1_KeyPress(KeyAscii As Integer) D

27、im str As String ,n As Integer str = UCase (Chr(KeyAscii) n=Len(str) Text1=String(n, str) End Sub  程序运行后,如果在键盘上输入单字母"K",则在文本框Text1中显示的内容为() 5.下面的程序输入X的值,按以下公式求Y值。Private Sub Command1_Click()X=Val(Text1.Text)Select Case XCase 【1 】P

28、rint "X<-100 OR X>200"Case 【2 】Y=100-XCase 【3 】Y=100+XCase 【4 】Y=400End SelectText2.Text=YEnd Sub6以下程序是利用公式来计算的值。其中,变量k表示当前符号项,t表示当前项,n表示当前项的序号,要求精度控制在0.00001内。试分析程序,完成空格处填的内容。Dim pi As Single,t As SingleDim n As Single,k As Singlepi=0 : n=1k=1 : t=1Do While(【1 】)pi =pi+tk=-kt=【2 】n=

29、n+1Looppi=【3 】Print "pi="pi7下列程序的功能是输出的前20项,按每行5个数的形式输出。Fibonacci数列:F1=1,F2=1,Fn=Fn-1+Fn-2(n>=2)Dim a As Integer, b As IntegerDim c As Integer, i As Integera = 1: b = 1: i = 3Print a, b,Do While (i <= 20) c = a + b a = b b = c 【1 】 If 【2 】Then Print End If 【3 】LoopEnd Sub4执行下面的程序段后,s

30、的值为_。a=5For i=2.6 To 4.9 Step 0.6s=s+1Next i5下面是一个体操评分程序。20位评委,除去一个最高分和一个最低分,计算平均分(设满分为10分)。Max=0Min=10For i=1 To 20n=Val(InputBox"请输入分数")If _Then Max=nIf _Then Min=ns=s+nNext is=_ p=s/18Print"最高分"Max,"最低分"MinPrint"最后得分:"p6下面程序的功能是求1到100的平方和,如果平方和超过了1000则跳出循环,

31、输出此时的和S。9以下程序段,程序运行后,要求执行4次循环。x=1Do x=x+1print 15loop Until_10下列程序运行后,内层循环的循环总次数_。For x= 1 to 4For y =1 to xPrint yNext yNext xFor I=1 To 100s=s+i*iIf s>1000 Then_ End Ifnext iabc:Print s7以下程序段的输出结果是_。num=0While num<=2num=num+1Print numWend8以下程序段的输出结果是_。Dim j As Integer,s As IntegerDo3写出下面程序的运

32、行结果。Private Sub Form_Click()For i=1 To 4x=4For j=1 To 3x=3For k=1 To 2x=x+6Next kNext jNext iprint xEnd Subs=s+jj=j+1Loop Until j=5Print "s="s四、程序阅读题1写出下面程序的运行结果。Private Sub Form_Click()Dim s As Integer,k As Integer,m As Integer,n As Integers=1For m=1 To 3For n=m To 3For k=n To m Step -1s=

33、s*kNext k,n,mPrint sEnd Sub2写出下面程序的运行结果。Private Sub Form_Click()6写出下面程序的运行结果。Private Sub Form_Click()Dim m As Integer,n As Integer,k As Integerm=1 : n=a : k=5Do While m<=k*n m=m*nn=n+1Print m;nLoopPrint m;nEnd SubFor i=3 To 1 Step -1Print Spc(10-i);For j=1 To 2*i-1Print "*"Next jPrint N

34、ext iEnd Sub4写出下面程序的运行结果。Private Sub Form_Click()m=0Do m=m+1If m>10 Then Exit DoLoop Until m<10Print mEnd Sub5写出下面程序的运行结果。7写出下面程序的运行结果。Dim i As Integer,a As IntegerDo While i<20Do While TrueIf i Mod 10=0 ThenExit DoElsei=i-1End IfLoopi=i+11 a=a+iLoopPrint aPrivate Sub Form_Click()Dim m As I

35、nteger,n As Integerm=10Do m=m+nFor n=10 To m step -1m=m+nNext nLoop While m<50Print m;nEnd Sub18下列程序的输出结果是_。Dim y As Integery=10While y<>0y=y-1WendPrint "y=" ; yA) y=0B) y=1C) y=随机值D) y=-119以下程序的输出结果是_。Dim m As Integerm=1While m<=3m=m+1Print m;WendA) 2B) 2 3C) 2 3 4D) 2 3 4 520

36、下面的程序运行结果是_。Private Sub Form_Click()m=0Do Until 0m=m+1If m>10 Then Exit DoLoopPrint mEnd Sub1下列过程的功能是:在对多个文本框进行输入时,对第一个文本框(Text1)输入完毕后用回车键使焦点跳到第二个文本框(Text2),而不是Tab键来切换。请完成该程序。Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)If 【1 】 Then Text2. 【2 】End IfEnd Sub1编写如下两个事件过程:Private Su

37、b Form_KeyDown(KeyCode As Integer, Shift As Integer)Print Chr(KeyCode)End SubPrivate Sub Form_KeyPress(KeyAscii As Integer)Print Chr(KeyAscii)End Sub在一般情况下(即不按住Shift键和锁定大写),运行程序,如果按A键,则程序的输出结果是什么?2在窗体上画一个命令按钮和一个文本框,并把窗体的KeyPreview属性设置为True,然后编写如下代码:Dim saveall As StringPrivate Sub Command1_Click()Te

38、xt1.Text = UCase(saveall)End SubPrivate Sub Form_KeyPress(KeyAscii As Integer)saveall = saveall + Chr(KeyAscii)End SubPrivate Sub Form_Load()Text1.Text = ""End Sub程序运行后,在键盘上输入abcdefg,单击命令按钮,写出文本框上显示的内容。3.单击窗体时,下列程序的执行结果为_。Private Sub Form_Click() Test (2)End SubPrivate Sub Test(x As Intege

39、r) x = x * 2 + 1 If x < 6 Then Call Test(x) End If x = x * 2 + 1 Print x;End Sub6单击窗体时,下列程序代码的执行结果为_,如果在Procl过程的第二形参y前加ByVal关键字,那么单击窗体时,程序代码的执行结果为_。Private Sub Form_Click() Dim x As Integer, y As Integer, z As Integer x = 1: y = 2: z = 3 Call procl(x, x, z) Call procl(x, y, y)End SubPrivate Sub p

40、rocl(x As Integer, y As Integer, z As Integer) x = 3 * z y = 2 * z z = x + y Print x; y; zEnd Sub9下列程序连续运行三次的结果为_。Option ExplicitSub First()Static s As IntegerDim i As IntegerFor i = 1 To 10 Step 2 s = s + iNext iPrint s;End SubPrivate Sub Command1_Click()Dim a As Integer, b As Integer, c As Integer

41、Call FirstEnd Sub10运行下列程序,在立即窗口上第二行显示_;第三行显示_。1写出下列程序的运行结果。Private Sub Command1_Click()Dim x%, y%x = 18y = 28Call swap(x, y)Print x, yEnd SubPrivate Sub swap(a%, b%)Dim t%t = aa = bb = tEnd SubOption ExplicitDim a As IntegerPrivate Sub Command1_Click()Dim b As IntegerDim d As Integera = 1: b = 2d =

42、fun(a, fun(a, b)Debug.Print a, b, dEnd SubPrivate Function fun(k As Integer, n As Integer) As IntegerDebug.Print k, n;k = n + a + kn = k + a + nfun = k + nDebug.Print funEnd Function三、程序阅读题:3写出下列程序的执行结果。Option ExplicitSub Ss(ByVal x As Integer, ByRef y As Integer, z As Integer)x = x + 1y = y + 1z =

43、z + 1End SubPrivate Sub Command1_Click()Dim a As Integer, b As Integer, c As Integera = 1: b = 2: c = 3Call Ss(a, b, c)Print a, b, cEnd Sub7写出下面程序的输出结果。Private Function f() As Integer Static i As Integer Dim s As Integer i=i+1 s=s+i f=sEnd FunctionPrivate Sub Command1_Click() Dim i As Integer Dim a

44、As Integer For i=1 To 4 a=a+f() Next i Print aEnd Sub4在窗体上画一个命令按钮,名称为Command1,程序运行后,写出下面程序的输出结果。Function M(x As Integer,y As Integer) As Integer M=IIf(x>y,x,y)End FunctionPrivate Sub Command1_Click() Dim a As Integer,b As Integer a=100 b=200 print M(a,b)End Sub5写出下面程序的输出结果。Private Sub Command1_Cl

45、ick() Dim k As Integer For i=3 To 5 Step 2 k=i Call text(k) m=m+k Next i Print m;iEnd SubPrivate Sub test(n As Integer) n=1+2*nEnd Sub6写出下面程序的输出结果。Function F(a As Integer) b=0 Static c b=b+1 c=c+1 F=a+b+cEnd FunctionPrivate Sub Command1_Click()8写出下面程序的输出结果。Public Function myfun(m!,n%) As Integer If

46、n=0 Then myfun=1 Else If n Mod 2=1 Then myfun=m*myfun(m,n2) Else myfun=myfun(m,n2)m End If End IfEnd FunctionPrivate Sub Command1_Click() Print myfun(3,11) Dim a As Integer a=2 For i=1 To 3 Print F(a) Next iEnd SubEnd Sub9当发生了Command1_Click事件后,写出下面程序的输出结果。Public Function age(n As Integer) As Integer

47、 Dim k As Integer If n=1 Then k=1 Else k=2*age(n-1)+3 End If age=kEnd FunctionPrivate Sub Command1_Click() Dim a As Integer,k As Integer k=5 : a=age(5) : Print aEnd Sub四、程序填空题:3以下Function过程Odd用于判断一个数是否为奇数。当单击命令按钮时,随机产生一个二位数,设用Odd过程判断该数是否是奇数。如果是奇数,则显示True,否则显示False。Option ExplicitPrivate Sub Command1

48、_Click()Dim x As Integerx = 【1 】Print x, Odd(x)End SubFunction Odd(ByVal n As Integer) As BooleanIf 【2 】 Then Odd = FalseElse Odd = TrueEnd IfEnd Function4下列程序的功能是求两个正整数的最大公约数。阅读下列程序,请在空格处天如相应的语句,使之完成上述功能。Option ExplicitPrivate Sub Command1_Click()Dim a As Integer, b As Integer, g As Integera = Inpu

49、tBox("输入数字a:")b = InputBox("输入数字b:")【1 】 = Gc(a, b)Print a; "和" b; "的最大公约数是:" gEnd SubPrivate Function Gc(ByVal x As Integer, 【2 】As Integer)Dim z As Integerz = x Mod yDo While z <> 0 x = y y = z z = x Mod yLoopGc = 【3 】End Function5下列程序的功能是将一个数的各位数字相乘并打

50、印在窗体上。阅读下列程序,请在空格处天如相应的语句,使之完成上述功能。Option ExplicitPrivate Sub Command1_Click()Dim n As Longn = InputBox("请输入一个数")Print Fun1(n)End SubPrivate Function Fun1(Num As Long) As LongDim s As Longs = 1Num = Abs(Num)Do While【1 】 s = s * (Num Mod 10) Num = 【2 】LoopFun1 = 【3 】End Function三、程序阅读题1在窗体上画一个文本框和一个图片框,然后编写如下两个事件过程,程序运行后,在文本框中显示的内容是什么?在图片框中显示的内容是什么?Private Sub Form_Load()Text1.Text="计算机"End SubPrivate Sub Text1_Change()Picture1.Print "文化基础"End Sub2窗体上有一按钮和一个列表框,执行下列程序,写出运行结果。Private Sub Command1_Click()List1.AddItem "China"List1.AddItem "USA

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论