1、
选择结构 1. 在窗体上画一个名称为Command1的命令按钮和两个名称分别为Text1、Text2的文本框,然后编写如下事件过程: Private Sub Command1_Click() n=Text1.Text Select Case n Case 1 To 20 x=10 Case 2, 4, 6 x=20 Case Is<10 1="" 3="" 10="" x="" case="" end="" select=""
2、 text2.text="x" sub="" 2.="" private="" if="" then="" y="" else="" print="" 3.="" is="">4 Print "分支 2" Case Else Print "Else 分支 " End Select End Sub 程序运行后,如果在输入对
3、话框中输入2,则窗体上显示的是 Else分支 4. 在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程: Private Sub Command1_Click() A = 75 If A > 60 Then I = 1 ElseIf A > 70 Then I = 2 ElseIf A > 80 Then I = 3 ElseIf A > 90 Then I = 4 End If Print "I=";
4、I End Sub 程序运行后,单击命令按钮,窗体上显示的是 1 5. 阅读下列程序,写出运行结果。 Private Sub Command1_Click() Dim x As Integer, s As Integer x = Val(InputBox("请输入一个正整数")) If x < 5 Then s =x * x Else s = x + x End If Tex
5、t1.Text = Str(s) End Sub 程序运行时连续三次单击Command1,且设输入的数是5,2和4时,分别写出文本框text1.text的值。 10 4 16 6. 阅读程序 Private Sub Form_Click() Dim strC As String*1 strC=InputBox("请输入数据") Select Case strC Case "a" To "z","A" To
6、quot;Z" Form1.Print strC+" Is Alpha Character" Case "0" To "9" Form1.Print strC+" Is Numeral Character" Case Else Form1
7、Print strC+" Is Other Character" End Select End Sub 设输入的数据为“W”时,单击窗体后,窗体上显示是什么? W Is Alpha Character 7. 阅读程序 Private Sub Form_Click() Dim strC As String*1 strC=InputBox("请输入数据") Select Case strC Case "a&q
8、uot; To "z","A" To "Z" Form1.Print strC+" Is Alpha Character" Case "0" To "9" Form1.Print strC+" Is Numeral Character" Case El
9、se Form1.Print strC+" Is Other Character" End Select End Sub 设输入的数据为“8”时,单击窗体后,窗体上显示是什么? 8 Is Numeral Character 8. 阅读程序 Private Sub Form_Click() Dim strC As String*1 strC=InputBox("请输入数据") Select Ca
10、se strC Case "a" To "z","A" To "Z" Form1.Print strC+" Is Alpha Character" Case "0" To "9" Form1.Print strC+" Is Numeral C
11、haracter" Case Else Form1.Print strC+" Is Other Character" End Select End Sub 设输入的数据为“?”时,单击窗体后,窗体上显示是什么? ? Is Other Character 9. 阅读程序 Private Sub Form_Click() A=1:I=0 SELECT CASE A*2 CASE 1 &n
12、bsp; A=A+1 CASE 2 A=A+2 CASE ELSE A=A+3 END SELECT Print A End Sub 单击窗体后,窗体上显示是什么? 3 10. 执行如下程序段,输出结果为: x=2 If x>=3 Then A=3 If x>=2 Then A=2 If x>=1 Then A=1 Print A 1 11. 下列程序段的执行结果为 A=1:B=0 Select Case A Case 1 Select Ca
13、se B Case 0 Print "**O**" Case 1 Print "**1**" End Select Case 2 Print "**2**" End Select **O** 12. 下列程序段的执行结果为 Private Sub Command1_Click() Dim a As Integer, b As Integer a = Int(Rnd() + 1) Select Case a Case 1 Print "****" C
14、ase 2 Print "####" Case Else Print "@@@@" End Select End Sub **** 13. 下列程序段的执行结果为 Private Sub Command1_Click() Dim a As Integer, b As Integer a = Sgn(-10) Select Case a Case 1 Print "****" Case -1 Print "
15、quot; Case Else Print "@@@@" End Select End Sub #### 14. 下列程序段的执行结果为 Private Sub Command1_Click() Dim a As Integer, b As Integer a = Sgn(-10) Select Case a Case 1 Print "****" Case 2 Print "####" Case El
16、se Print "@@@@" End Select End Sub @@@@ 15. 下列程序段的执行结果为 Private Sub Command1_Click() Dim a As String, b As Integer, c As String c = 0 a = InputBox("输入第1个数据:") b = InputBox("输入第2个数据:") If a > b Then c = Int(-11.99) + Int(-100 Mod 7) * Sgn(Rnd(
17、) * 100) Else c = 3 ^ 3 \ 3 * 3 End If Print c End Sub 设输入的数据分别为“-3”和“-4”时,单击后,窗体上显示是什么? -14 16. 下列程序段的执行结果为 Private Sub Command1_Click() Dim a As String, b As Integer, c As String c = 0 a = InputBox("输入第1个数据:") b = InputBox("输入第2个数据:") If a > b Then
18、 c = Int(-11.99) + Int(-100 Mod 7) * Sgn(Rnd() * 100) Else c = 3 ^ 3 \ 3 * 3 End If Print c End Sub 设输入的数据分别为“5”和“7”时,单击后,窗体上显示是什么? 3 17. 阅读程序 Private Sub Command1_Click() Dim a As String, b As Integer, c As String c = 0 a = InputBox("输入第1个数据:") b = InputBox("
19、输入第2个数据:") If a > b Then c = Int(-9.45) + Int(-100 Mod 3) * Sgn(Rnd() * -100) Else c = 3 ^ 3 \ 3 * 3 + a ^ 3 End If Print c End Sub 输入的数据分别为“5”和“7”时,单击后,窗体上显示是什么? 128 18. 阅读程序 Private Sub Command1_Click() Dim a As String, b As Integer, c As String c = 0 a = InputBo
20、x("输入第1个数据:") b = InputBox("输入第2个数据:") If a > b Then c = Int(-9.45) + Int(-100 Mod 3) * Sgn(Rnd() * -100) Else c = 3 ^ 3 \ 3 * 3 + a ^ 3 End If Print c End Sub设输入的数据分别为“7”和“5”时,单击后,窗体上显示是什么? -9 19. 阅读程序 Private Sub Command1_Click() Dim x As Single, y
21、As Single, s As String s = "1234" x = Right(s, 1) Select Case x Case Is <= 1="" 2="" 3="" y="4" x="" case="" to="" mod="" is=""> 3 y = (5 * x + 1) \ (6 * x - 8) End Select Print
22、 y End Sub 单击后,窗体上显示是什么? 1 20. 阅读程序 Private Sub Command1_Click() Dim x As Single, y As Single, s As String s = "1234" x = left(s, 1) Select Case x Case Is <= 1="" 2="" 3="" y="4" x="" case="" to="" mod=&qu
23、ot;" is=""> 3 y = (5 * x + 1) \ (6 * x - 8) End Select Print y End Sub 单击后,窗体上显示是什么? 0 21. 阅读下列程序,写出运行结果。 Private Sub Command1_Click() Dim x As Integer, s As Integer x = Val(InputBox("请输入一个正整数")) If x > 5 Then s =sqr(
24、x) Else s =asb(x) + x End If Text1.Text = Str(s) End Sub 程序运行时连续三次单击Command1,且设输入的数是16,5和-1时,分别写出文本框text1.text的值。 4 10 0 22. 阅读程序 Private Sub Command1_Click() Dim x, a, b, c As Integer Dim b1, b2 As Boolean x = 10: a = 1: b = 2: b1 = -5: b2 = 0
25、 If a < b Then If b <> 3 Then If Not b1 Then x = -10 Else If b2 Then x = -30 x = -50 End If End If End If Print x End Sub 单击命令按钮后,窗体上显示是什么? -10 23. 阅读程序 Private Sub Command1_Click() Dim x, a, b
26、 c As Integer Dim b1, b2 As Boolean x = 10: a = 5: b = 3: b1 = 0: b2 = -1 If a < b Then If b <> 3 Then If Not b1 Then x = -10 Else If b2 Then x = -30 x = -50 End If End If End If Print x End Sub
27、 单击命令按钮后,窗体上显示是什么? 10 24. 阅读程序 Private Sub Command1_Click() Dim s As String Dim n As Integer s = Left(InputBox("请输入字符串"), 1) If s >= "c" Then Print Asc(s) + 1 Else Print Asc(s) - 1 End If End Sub 单击命令按钮输入abcd后,窗体上显示是什么?96 25. 阅读程序 Private S
28、ub Command1_Click() Dim s As String Dim n As Integer s = Right(InputBox("请输入字符串"), 1) If s >= "c" Then Print Asc(s) + 1 Else Print Asc(s) - 1 End If End Sub 单击命令按钮输入abcd后,窗体上显示是什么?101 26. 阅读程序 Private Sub Command1_Click() Dim m, n As Integer m = InputBox(&qu
29、ot;请输入m的值") If m / 2 = Int(m / 2) Then n = m Else n = 1 End If Print n End Sub 单击命令按钮输入6后,窗体上显示是什么?6 27. 阅读程序 Private Sub Command1_Click() Dim m, n As Integer m = InputBox("请输入m的值") If m / 2 = Int(m / 2) Then n = m Else n = 1 End If Print n End Sub 单击
30、命令按钮输入5后,窗体上显示是什么?1 28. 执行下面的语句后显示的结果是 Private Sub Command1_Click() Dim m, n As Integer m = InputBox("请输入m的值") If m / 2 = Int(m / 2) Then m = n + 5 Else m = Sqr(m) End If If n Then Print n Else Print n - 1 End Sub 单击命令按钮输入5后,窗体上显示是什么?-1 29. 阅读程序 Private Sub Command1_C
31、lick() Dim y As Integer y = 10 Select Case y Case 1, 3, Is > 6 Print "ok" Case Else Print "stop" End Select End Sub 单击命令按钮后,窗体上显示是什么?ok 30. 阅读程序 Private Sub Command1_Click() Dim x, i As Integer i = InputBox("") If i = 1 Then x = i &nbs
32、p; If i <= 4 Then x = x + 1 Else x = x + 2 End If Print x End Sub 单击命令按钮输入5后,窗体上显示是什么?2 31. 阅读程序 Private Sub Command1_Click() Dim x, i As Integer i = InputBox("") If i = 1 Then x = i &nbs
33、p; If i <= 4 Then x = x + 1 Else x = x + 2 End If Print x End Sub 单击命令按钮输入1后,窗体上显示是什么?2 32. 阅读程序 Private Sub Command1_Click() Dim x, i As Integer i = InputBox("") If i = 1 Then x = i &n
34、bsp; If i <= 2="" 3="" 4="" then="" x="" i="" else="" end="" if="" print="" sub="" 33.="" private="" dim="" y="x" as="" inte
35、ger="" select="" case="" is="">= 10, Is <= 3="" 9="" 10="" -10="" y="x" case="" to="" end="" select="" print="" sub="" 34.="" private=
36、quot;" dim="" as="" integer="" x="" is="">= 10, Is <= 10="" 20="" -10="" y="x" case="" to="" end="" select="" print="" sub="" 35.="&q
37、uot; private="" dim="" as="" integer="" x="" is="">= 10 y = x Case -10 To 10 y = -x End Select Print y End Sub 单击命令按钮输入20后,窗体上显示是什么?400 36. 阅读程序 Private Sub Command1_Click() Dim x, y As Integer x = InputBox("") Se
38、lect Case sqr(x) Case 1, 3,10,20 y = x * x Case Is >= 10 y = x Case -10 To 10 y = -x End Select Print y End Sub 单击命令按钮输入9后,窗体上显示是什么?81 37. 下列程序段的执行结果为 Private Sub Command1_Click() Dim a As Integer, b As Integer a = Int(Rnd()*10 + 1) Select Case a Case 0 Print
39、 "****" Case is<10 print="" case="" else="" end="" select="" sub="" 38.="" private="" dim="" a="" as="" b="InputBox("输入第2个数据:")" c="" string=&quo
40、t;" if="">b Then c = abs(a)+sqr(b) Else c = 3 ^ 3 \ 3 * 3 End If Print c End Sub 设输入的数据分别为“5”和“6”时,单击后,窗体上显示是什么? 3 39. 下列程序段的执行结果为 Private Sub Command1_Click() Dim a As Integer, b As Integer, c As Integer a = InputBox("输入第1个数据:") b = InputBox("
41、输入第2个数据:") If a > b Then If a then c = abs(a)+sqr(b) end if Else c = a*b mod 3 End If Print c End Sub 设输入的数据分别为“0”和“5”时,单击后,窗体上显示是什么? 0 40. 下列程序段的执行结果为 Private Sub Command1_Click() Dim a As Integer, b As Integer, c As Integer a = InputBox("输入第1个数据:") b
42、 InputBox("输入第2个数据:") If a > b Then If Not a Then c = Abs(a) + Sqr(b) Else c = Abs(a) - Sqr(b) End If Else If Not a Then c = a * b Mod 3 Else c = a ^ 3 + 4 End If End If Print c End Sub 设输入的数据分别为“9”和“3”时,单击后,窗体上显示是什么? 11 1. 在窗体上画一个
43、命令按钮,然后编写如下事件过程: Private Sub Command1_Click() x=0 Do Until x=-1 a = InputBox(“请输入A的值”) a = Val(a) b = InputBox(“请输入B的值”) b = Val(b) x = InputBox(“请输入x的值”) x = Val(x) a = a+b+x Loop Print a End Sub 程序运行后,单击命令按钮,依次在输入对话框中输入5、4、3、2、1、-1,则输出结果为 。2 2. 阅读下面的程序段: For i=1 To 3 For &n
44、bsp;j=1 To i For k=j To 3 a=a+1 Next k Next j Next i Print a 执行上面的三重循环后,a 的值为 。 14 3. 在窗体上画一个文本框(其中Name属性为Text1),然后编写如下事件过程: Private Sub Form_Load() Dim sum as integer text1.text="" For i=1 To 10 Sum=Sum+i Next i Text1.Text=Sum End Sub 上述程序的运行结果是 。55 4. 在窗体上画两个文
45、本框(其Name 属性分别为Text1和Text2)和一个命令按钮(其Name属性为Command1),然后编写如下事件过程: Private Sub Command1_Click() x=0 Do While x<50 x=(x+2)*(x+3) n=n+1 Loop Print x,n End Sub 程序运行后,单击命令按钮,显示为 72 2 5. 阅读下面的程序段: x=2 For i=1 To 5 x=x+i Print x, Next 程序运行后,显示 3 5 8 12 17
46、 6. 阅读下面的程序段: x=0 For i=1 to 2 For j=1 to 3 x=x+j Next j Next i Print x 程序运行后,显示 12 7. 阅读下面的程序段: Dim i As Integer, x As Integer For i = 1 To 6 If i = 1 Then x = i If i <= 1="" 2="&quo
47、t; 4="" 9="" 10="" 11="" then="" x="1" else="" end="" if="" next="" i="" print="" 8.="" private="" sub="" c="ABCD" for="" n="
48、1" to="" d="" cd="" bcd="" abcd="" 9.="" step="" 10.="" y="" do="" until="">4 X=X*Y Y=Y+1 Loop Print X 程序运行后,显示
49、 4 11. 阅读下面的程序段: x=0 For i=1 to 2 For j=1 to 3 x=x+j Next j Next i Print x 程序运行后,显示 12 12. 阅读下面的程序段: Private Sub Form_Click() Dim n1 as integer,n2 as integer,n3 as integer n1=1:n2=1 Do N3=n1+n2
50、Print n3, N1=n2:n2=n3 Loop Until n3>=5 End Sub 程序运行后,显示 2 3 5 13. 阅读下面的程序段: X=1 Y=4 Do Until Y>4 X=X*Y^2 Y=Y+1 Loop Print X 程序运行后,显示 &
51、nbsp; 16 14. 阅读下面的程序段: Private Sub Command1_Click( ) For i = 1 T0 3 For j = 0 TO i S = S + 1 Next j,i Print s End Sub 程序运行后,显示 &n
52、bsp; 9 15. 阅读下面的程序段: Private Sub Command1_Click( ) x =1:y=1 For i=1 T0 3 x = x + y : y = y + x Next i print x,y End Sub 程序运行后,显示 13 21 16. 阅读下面
53、的程序段: For a =1 TO 5 For b = 1 TO 10 a=a +1 b=b+1 Next b Next a Print b End Sub 程序运行后,显示 11 17. 在窗体上画两个文本框(其Name 属性分别为Text1和Text2)和一个命令按钮(其Name属性为Command1),然后编写如下事件过程: Private Sub Command1_
54、Click() x=0 Do While x<50 x=x^2+(x mod 2)+1 n=n+5 Loop Text1.Text=Str(n) Text2.Text=Str(x) End Sub 程序运行后,单击命令按钮,在两个文本框中显示的值分别为 20 123 18. 下面语句运行后的输出结果是 &nb
55、sp;16 Private Sub Command1_Click( ) x=2 do While x < 10 x =x + l x = x * x loop Print x End Sub 19. 在窗体上画两个名称分别为Text1、Texte2的文本框和一个名称为Command1的命令按钮,然后编写如下事件过程: Private Sub Command1_Click() Dim x As Integer,n As Integer x=1 n=0 Do While x<20 x=x*3 n=n+1 Loop Text1.Text=Str
56、x) Text2.Text=Str(n) End Sub 程序运行后,单击命令按钮,在两个文本框中显示的值分别是 27 3 20. 下列程序段的输出结果为________。 0 Private Sub Command1_Click( ) Dim S as integer, N as integer i=1:
57、sum=0 Do While i<=100 sum=sum+i i=i+1 Loop Print Str(S) End Sub 21. 下列程序段的输出结果为________。 37 74 111 148 185 Private Sub Command1_Click( ) a=”” For n=1 To 200
58、 If n Mod 37=0 Then a=a &Str(n)&” ” End If Next Text1.Text=a End Sub 22. 、设有如下程序段,运行后,x的值是:17 x=2 For i=1 To 5 x=x+i Next 23. 执行如下程序段,输出结果为
59、0 a=0 For i=1 to 5 a=a*i Next i Print a 24. 执行如下程序段,输出结果为:12 x=0 For i=1 to 2 For j=1 to 3 x=x+j Next j Next i Print x 25. 命令按钮的Name属性为Command1,编写如下代码,则在程序运行时,单击该命令按钮,输出结果为:1 2 6 Private Sub Command1_Click() For i=1 to 3 x=1 For j=1 to i x=x*j Next j Print j; Next i
60、 End Sub 26. 程序 p = InputBox("请输入字符串:") For i = Len(p) To 2 Step -2 Print Left(p, i) Next i End Sub 如果输入:ABCDEFG ,则结果: ABCDEFG ABCDE ABC 27. 程序 p = InputBox("请输入字符串:") For i = Len(p) To 2 Step -2 Print right(p, i) Next i End Sub 如果输入:ABCDEFG ,则结果: ABCDEF
61、G CDEFG EFG 28. 程序3: Private Sub Form_Click() Dim i As Integer ,j As Integer Dim star As String star="#" For i=1 To 6 For j=i To 6 Form1.Print star; Next j Form1.Print Next i End Sub 写出程序运行后,单击窗体后,Form1上输出






