End Sub
程序运行后,如果在输入对话框中输入2,则窗体上显示的是
(A)分支1 (B)分支2 (C)Else分支 (D)程序出错 10. 以下Case语句中错误的是
(A)Case 0 To 10 (B)Case Is>10 (C)Case Is>10 And Is<50 (D)Case 3,5,Is>10
11. 在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程:
Private Sub Command1_Click() x = -5
If Sgn(x) Then ?y = Sgn(x ^ 2) Else
?y = Sgn(x) End If Print y End Sub
程序运行后,单击命令按钮,窗体上显示的是
(A)-5 (B)25 (C)1 (D)-1
12. 在窗体上画一个名称为Text1的文本框,要求文本框只能接收大写字母的
输入。以下能实现该操作的事件过程是
(A)Private Sub Text1_KeyPress(KeyAscii As Integer) ?? If KeyAscii < 65 Or KeyAscii > 90 Then ?? MsgBox \请输入大写字母\?? KeyAscii = 0 ?? End If ? End Sub
(B)Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) ?? If KeyCode < 65 Or KeyCode > 90 Then ?? MsgBox \请输入大写字母\?? KeyCode = 0 ?? End If ? End Sub (C)Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
? If Asc(Text1.Text) < 65 Or Asc(Text1.Text) > 90 Then ?? MsgBox \请输入大写字母\? End If ? End Sub
(D)Private Sub Text1_Change()
11
?? If Asc(Text1.Text) > 64 And Asc(Text1.Text) < 91 Then ?? MsgBox \请输入大写字母\?? End If ?? End Sub
13. 设a=6,则执行x=IIF(a>5,-1,0)后,x的值为
(A)5 (B)6 (C)0 (D)-1 14. 下列语句正确的是
(A)If A ≠ B Then Print \不等于 B\(B)If A <> B Then Printf \不等于 B\(C)If A <> B Then Print \不等于 B\(D)If A ≠ B Then Printf \不等于 B\15. 下面程序段执行结果为 x = Int(Rnd() + 4) Select Case x Case 5
Print \ Case 4
Print \ Case 3
Print \ Case Else
Print \
End Select
(A)excellent (B)good (C)pass (D)fail 16. 设a = \,b = \,c = \,d = \,执行语句x = IIf((a < b) Or (c > d), \
\后,x的值为
(A)a (B)b (C)A (D)B 17. 下列程序执行后,变量a的值为
Dim a, b, c, d As Single a = 100: b = 20: c = 1000 If b > a Then
d = a: a = b: b = d End If
If c > a Then
d = b: b = c: c = d End If
(A)0 (B)1000 (C)20 (D)100 18. 执行下面的程序段后,变量c的值为
a = 14 b = 30
Select Case b \\ 10 Case 0
12
c = a * 10 + b Case 1 To 9
c = a * 100 + b Case 10 To 99 c = a * 1000 + b End Select Print c
(A)363 (B)2548 (C)1430 (D)9875
3.2 填空题
1.下面程序运行后输出的结果是( )。 x=Int(Rnd)+3
If x^2>8 Then y=x^2+1 If x^2=9 Then y=x^2-2 If x^2<8 Then y=x^3 Print y
2.下面程序的功能是( )。
Dim n%,m%
Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii=13 Then
If IsNumeric(Text1.Text) Then Select Case Text1.Text Mod 2 Case 0
n=n+Text1.Text Case 1
m=m+Text1.Text End Select End If
Text1.Text=\ Text1.SetFocus End If End Sub
3.下面的程序段是检查输入的算术表达式中圆括号是否配对,并显示相应的结果。本程序在文本框输入表达式,边输入,边统计,以输入回车符作为表达式输入结束,然后显示结果。 Dim count1%
Private Sub Text1_KeyPress(KeyAscii As Integer) If( )= \ count1=count1+1
ElseIf( )= \
13
( ) End If
If KeyAscii=13 Then If( )Then Print \左右括号配对\ Else If( )Then
Print\左括号多于右括号\;count1;\个\ Else
Print\右括号多于左括号\;-count1;\个\ End If End If End Sub
4. 输入文本框中若干字符,统计有多少个元音字母、有多少个其他字母,直
到按Enter键结束,并显示结果,大小写不区分。其中CountY中放元音字母个数,CountC中放其他字符数。 Dim CountY%,CountC%
Private Sub Textl_KeyPress(KeyAscii As Integer) Dim C$
C=( )
If \
Select Case( ) Case( ) CountY=CountY+1 Case( ) CountC=CountC+1 End Select End If
If( )Then
Print \元音字母有\;CountY;\个\ Print\其他字母有\;CountC;\个\ End If End Sub 3.3 编程题
1. 输入三角形的三条边a,b,c的值,根据其数值,判断能否构成三角形。
若能,还要显示三角形的性质:等边三角形、等腰三角形、直角三角形、任意三角形。
2. 输入一年份,判断它是否为闰年,并显示有关信息。判断闰年的条件是:
年份能被4整除但不能被100整除,或者能被400整除。
14
习题三 参考答案
3.1 选择题 1.D 2.B
3.A x没有赋值,默认为0。而在VB中,0作为逻辑常量False,非0作为True。
4.C 5.C 6.D 7.A 8.D 9.C 10.C 11.C 12.A 13.D 14.C 15.B 16.C 17.D 18.C
3.2 填空题 1.7
2.分别统计输入若干数的奇数和、偶数和,存放在m、n中 3.Chr(KeyAscii) 4.Chr(KeyAscii)
5.countl=countl-1 若遇右括号,括号数减l。 6.countl=0 括号配对。
7.countl>0 左括号多于右括号,多于的个数是countl的值。 8.UCase(Chr(KeyAscii)) 大小写不区分。 9.C
10.”A”,”E”,”I”,”O”,”U” 11.Else 其他字符。 12.KeyAscii=13
3.3 编程题
1. Private Sub Command1_Click()
Dim a#, b#, c#
Dim flag As Boolean a = Val(Text1) b = Val(Text2) c = Val(Text3)
If a+b>c and a+c>b and b+c>a then print “构成三角形,是:”; If a = b and b= c Then Print \等边三角形\
ElseIf a = b Or a = c Or c = b Then Print \等腰三角形\
ElseIf a^2 + b^2 = c^2 Or a^2 + c^2 = b^2 Or c^2 + b^2 = a^2 Then
Print \直角三角形\Else
15