VB顺序结构及选择结构练习一、单选题1.在窗体上画一个命令按扭(名称为Command1),然后编写如下事件过程Private Sub Command1_Click()b=5c=6Print a = b + cEnd Sub程序运行后,单击命令按扭,其结果为(D)A)a=11 B)a=b + c C)a= D)False2. 在窗体上画一个命令按扭(名称为Command1),然后编写如下事件过程Private Sub Command1_Click(D)a=11b=5c=6Print a = b + cEnd Sub程序运行后,单击命令按扭,其结果为()A)a=11 B)a=b + c C)a= D)True3.以下语句的输出结果是(B)a = Sqr(3)Print Format(a,”$$#### : ###”)A)$1.732 B)$$1.732 C)$1732 D)$$00001.7324.以下程序段的输出结果是(D)a = Sqr(3)b = Sqr(2)c =a>bPrint cA)-1 B)0 C)False D)True5.以下语句的输出结果是(C)Print Format$ (32548.5,”000,000.00”)A)32548.5 B)32,548.5 C)032,548.50 D)32,548.501.假定有如下语句:answer$=MsgBox(“String1”,, “String2”, “String3”,2)执行该语句后,将显示1个信息框,此时如果单击“确定”按扭,则answer$的值为(D)A)String1 B)String2 C)String3 D)12.InputBox函数返回值的类型为(B)A)数值B)字符串C)变体D)数值或字符串(视输入的数据而定)3.在窗体上画1个名为Command1的命令按扭,然后编写如下事件过程。
Private Sub Command1_Click()a = InputBox(“Enter the First integer”)b = InputBox(“Enter the Second integer”)Print b + aEnd Sub程序运行后,单击命令按扭,先后在2个输入对话框中输入456和123,则输出结果是(D)A)579 B)123 C)456123 D)1234564.执行下面的语句后,所产生的信息框的标题是(A)a = MsgBox(“AAAA”,,”BBBB”,””,5)A)BBBB B)空C)AAAA D)出错,不能产生信息框5.在窗体上画1个名为Command1的命令按扭,然后编写如下事件过程Privete Sub Command1_Click()MsgBox Str(123 + 321)End Sub程序运行后,单击命令按扭,则在信息框中显示的提示信息为(B)A)123 + 321 B)字符串”444”C)数值444 D)空白6.MsgBox函数的反回值的类型为(A)A)整型(Integer) B)字符串C)变体D)整数或字符串(视选择的按扭而定)1.假定有如下语句:st$=InputBox(“请输入一串字符”, “输入对话框”, “请输入字符串”)当用户输入完毕,按“确定”按扭后,st$变量的内容是()A)请输入一串字符B)字符串对话框C)请输入字符串D)用户输入内容1. 假定有如下语句:Private Sub Form_Click()Dim a,b,x As Integera = InputBox (“a=?”)b = InputBox (“b=?”)x = a + bIf a > b Then x = a - bPrint xEnd Sub运行时从键盘输入3和4,输入x的值是(C)A)3 B)5 C)7 D)92. 假定有如下语句:Private Sub Form_Click()b = 1 : a = 2Print IIf (a >= b,a,b)End Sub运行后输出的结果是(C)A)0 B)1 C)2 D)33.假定有如下语句:Private Sub Form_Click()s = Val (InputBox ( “Input V alue of s:”))Select Case sCase Is < 6f = s + 1Case Is < 5f = s + 2Case Is < 4f = s + 3Case Elsef = s + 4End SelectPrint s;fEnd Sub运行时从键盘输入6,输出结果是(D)A)6 7 B)6 8 C)6 9 D)6 104. 假定有如下语句:Private Sub Form_Click()score = Int (Rnd * 10) + 80Select Case scoreCase Is < 60a$ = “F”Case 60 To 69a$ = “D”Case 70 To 79a$ = “C”Case 80 To 89a$ = “B”Case Elsea$ = “A”End SelectPrint a$End Sub运行时输出的结果是(B)A)A B)B C)C D)D5. 假定有如下语句Private Sub Form_Click()a = Val (InputBox (“请输入a”))b = Val (InputBox (“请输入b”))x = a*a + bIf b > a Then x = b*b + aPrint xEnd Sub运行时从键盘输入3和4,输出X的值是(C)A)12 B)13 C)19 D)206. 假定有如下语句Private Sub Form_Click()K = 2If K >= 1 Then A = 3If K >= 2 Then A = 2If K >= 3 Then A = 1Print AEnd Sub运行时,输出的结果是(B)A)1 B)2 C)3 D)出错7. 假定有如下语句Private Sub Form_Click()k = Val ( InputBox (“请输入一个数”))If k <= 0 Then Abc = 4 : GoTo aIf k <= 1 Then Abc = 3 : GoTo aIf k <= 2 Then Abc = 2 : GoTo aIf k <= 3 Then Abc = 1a:Print k ; AbcEnd Sub运行时输入3,输出的结果是(A)A)3 1B)3 4 3C)3 4 3 2D)3 4 3 2 18.设有函数r =1 x < 02 x >=0则下列能正确计算该函数值的语句是(D)A)If x < 0 Then r = 1ElseIf x >= 0 Thenr = 2End IfB)If x < 0 Then r = 1ElseIf x >= 0 Then r = 2 Else r = 1End IfC)Print ( IIf (x >0,1,2))D)r = IIf (x < 0,1,2)二、简答(填空)题1.假设有如下程序,程序运行后,单击窗体输出结果是(032,548.60)Private Sub Form_Click ()a = 32548.56Print Format (Int((a*10+0.5)) / 10,”000,000.00”)End Sub2.以下程序段的功能是(对变量X四舍五入后取整)x = 8.6y=Int(x+0.5)Print y3.假设有如下程序,程序运行后,单击窗体输出结果是(4)Private Sub Form_Click ()a = 25 Mod (1-2^3)Print aEnd Sub4.以下语句的输出结果是(Beijing)s$=”China”s$=”Beijing”Print s$5.以下语句的输出结果是(3)a%=3.14156Print a%6.设a=Sqr(2)*Sqr(3),下列语句的输出结果分别是Print Format $ (a,”000.00”) 输出结果:002.45Print Format $ (a,”###.#00”) 输出结果:2.449Print Format $ (a,”00.00E+00”) 输出结果:24.49E-01 Print Format $ (a,”-#.####”) 输出结果:-2.4495三、编程题1.编写打印下面三角形图案的源程序(书上55页4题)*************************程序代码:Private Sub Form_Click()Form1.Print Tab(15); "*"Form1.Print Tab(14); "***"Form1.Print Tab(13); "*****"Form1.Print Tab(12); "*******"Form1.Print Tab(11); "*********"End SubPrivate Sub Form_Load()Form1.AutoRedraw = TrueForm1.Print "显示星号三角形,单击窗体开始" End Sub2.设a=5,b=2.5,c=7.8,编程序计算y=πab/a+b*c程序代码:Private Sub Form_Click()a =5 :b = 2.5 :c = 7.8y = (3.1416*a*b)/(a+b*c)Print “y=”;yEnd Sub1.编写求以10为底,求10000的对数值的源程序。
Private Sub Form_Click()Form1.Print Log(10000) / Log(10)End SubPrivate Sub Form_Load()Form1.AutoRedraw = TrueForm1.Print "计算以10为底,10000的对数"Form1.Print "单击窗体开始"End Sub2.编写求任意数的平方根的源程序,数由键盘输入。
Private Sub Form_Click()x = Val(InputBox$("输入数据"))Form1.Print "输入数据为"; xForm1.Print "平方根为"; Sqr(x)End SubPrivate Sub Form_Load()Form1.AutoRedraw = TrueForm1.Print "求任意数的平方根"Form1.Print "单击窗体开始"End Sub3.求任意半径和高的圆柱的表面积。