您的当前位置:首页正文

VB程序改错题收集

2024-10-18 来源:威能网
VB中常见的错误

1、运行下面的 Visual Basic程序,单击命令按钮 Command1,出现如下图所示的提示信息: Private Sub Command1_Click()

Dim a As Single, b As Single a = Val b = 10 If a >= b

b = a * a + 2 * b End If = Str(b) End Sub

出现该错误的原因是

A.If语句缺少Then B.If语句缺少Else

C.变量a的数据类型说明错误 D.变量b的数据类型说明错误 2、某VB程序的事件过程如下所示:

Private Sub Command1_Click ( ) Dim a As Integer a = Val(Text1.Text)

Text1.Text = Str(Int( a )) End Sub

运行程序,单击按钮Command1后弹出如下图所示的错误提示。导致该错误的原因可能是(

A.Int函数计算时出现错误 B.Val函数应用不正确 C.窗体上缺少Text1文本框对象 D.变量a数据类型定义错误 3、某Visual Basic程序段如下: Dim a(1 To 10) As Integer Dim i As Integer a(1) = 1 For i = 2 To 10 a(i) = a(i - 1) * i Next i

运行该程序段,会出现的错误提示为

(A)下标越界 (B)子程序或函数未定义 (C)要求对象 (D)溢出

Interger类型范围在-32768~32767,而1到10相乘超出这个范围 4、某Visual Basic程序如下: Private Sub Command1_Click() Dim a(1 To 10) As Integer Dim i As Integer For i = 1 To 10 a(i) = i * i Next i Str(a(i)) End Sub

运行程序,单击命令按钮Command1后,出现的错误提示为 (A) 下标越界 (B) 子程序或函数未定义 (C) 溢出 (D) 类型不匹

5、有如下的Visual Basic程序: Private Sub Command1_Click() Const pi =

Dim s As Single, r As Single r = Val pi =

s = pi * r ^ 2 = \"面积为\" + Str(s) End Sub

程序运行后,单击命令按钮Command1,出现如图所示的错误提示,下列原因分析正确的是 (A)常量不能用小数

(B)pi是常量,不允许赋值

(C)文本框Text1中输入的数据不是常量 (D)表达式结果超过了变量类型的范围

6、某Visual Basic程序如下: Private Sub Command1_Click() Dim a(1 To 10) As Integer Dim i As Integer For i = 1 To 10 a(i) = i * i Next i Str(a(i)) End Sub

运行程序,单击命令按钮Command1后弹出如图所示的出错信息提示,此时程序正执行的语句是 (A)For i = 1 To 10 (C)Next i

7、某Visual Basic程序如下: Private Sub Command1_Click() Dim a As Single, b As Single Dim c As Single a = 1 b = 5

c = Sqr(a - b) = Str(c) End Sub

运行程序,单击命令按钮Command1后弹出如图所示的出错信息提示,此时程序正执行的语句是 (A)a = 1

(C)c = Sqr(a - b)

根据代码窗口中的程序,要在程序运行时获取输入的x值,窗体上必须增加的对象是 A. 标签Text1 B. 标签Label2 C. 文本框Text1 D. 文本框Label2 9、运行下面的 Visual Basic程序,单击命令按钮 Command1,出现如下图所示的提示信息:

(B)b = 5 (D) = Str(c)

(B)a(i) = i * i (D) Str(a(i))

8、某同学正编写一个判断酒驾行为的Visual Basic程序,其窗体和代码窗口如下图所示。

Private Sub Command1_Click()

Dim i As Integer, c As String, s As String, t As String s = \"2012 Hero\" t = \"\"

For i = 1 To Len(s) c = Mid(s, i, 1)

If c >= \"a\" And c <= \"z\" t = t + c End If Next i = t End Sub

出现该错误的原因是

A.If语句缺少Then B.If语句缺少Else

C.变量t的数据类型说明错误 D.变量s的数据类型说明错误

10、某VB程序在调试中弹出如图所示的错误窗口,产生该错误的可能原因是( )

A.该VB程序代码中,缺少Next B.该VB程序窗体界面中,缺少某控件 C.该VB程序代码中,某个常量或变量没有声明 D.该VB程序设计软件没有正确安装

11.运行如下Visual Basic程序,单击命令按钮Command1,出现如图所示的出错信息。发生\"下标越界\"错误时所执行的语句是

Private Sub Command1_Click() Dim a(0 To 5) As Integer

Dim i As Integer '① a(0) = 1 '② For i = 1 To 5

a(i) = 2 * a(i - 1) + 1 '③ Next i

= Str(a(i)) '④ End Sub

(A)① (B)② (C)③ (D)④

12.运行如下Visual Basic程序,单击命令按钮Command1,出现如图所示的出错信息。发生\"下标越界\"错误时所执行的语句是

Private Sub Command1_Click() Dim a(0 To 5) As Integer Dim i As Integer '① a(0) = 1 '② For i = 1 To 6

a(i) = 2 * a(i - 1) + 1 '③ Next i

= Str(a(5)) '④ End Sub

(A)① (B)② (C)③ (D)④ 13.某Visual Basic程序如下:

Private Sub Command1_Click()

Dim a(1 To 10) As Integer Dim i As Integer For i = 1 To 10 a(i) = i * i Next i Str(a(i)) End Sub

运行程序,单击命令按钮Command1后弹出如图所示的出错信息提示,此时程序正执行的语句是 (A)For i = 0 To 10 (C)Next i 误时所执行的语句是

Private Sub Command1_Click()

Dim a As Integer, b As Integer, c As Single a = 2 '① b = a + 1 '② c = a / (b - 3) '③ = Str(c) '④ End Sub (A)①

(B)②

(C)③ (D)④ 15.有如下的Visual Basic程序: Private Sub Command1_Click() Const pi = '① Dim s As Single, r As Single r = Val '② pi = '③ s = pi * r ^ 2 '④ = \"面积为\" + Str(s) End Sub

程序运行后,单击命令按钮Command1,出现如图所示的错误提示,下列原因分析正确的是 (A)常量不能用小数 (B)pi是常量,不允许赋值

(C)文本框Text1中输入的数据不是常量 (D)表达式结果超过了变量类型的范围 16.题目如上题,问具体是哪条语句出错

(A)① (B)② (C)③ (D)④

17.运行如下Visual Basic程序,单击命令按钮Command1,出现如图所示的出错信息。发生\"类型不匹配\"错误时所执行的语句是 Private Sub Command1_Click() Dim a As Integer, b As Integer a = 10 '① b = 20 '② = \"a+b=\" + Val(a + b) '③

(B)a(i) = i * i (D) Str(a(i))

14.运行如下Visual Basic程序,单击命令按钮Command1,出现如图所示的出错信息。发生\"除数为零\"错

End Sub '④

(A)① (B)② (C)③ (D)④

18.某Visual Basic程序如下: Private Sub Command1_Click() Dim a As Single, b As Single Dim c As Single a = 1 b = 5

c = Sqr(a - b) = Str(c) End Sub

运行程序,单击命令按钮Command1后弹出如图所示的出错信息提示,此时程序正执行的语句是 (A)a = 1

(C)c = Sqr(a - b)

19.某Visual Basic程序如下: Private Sub Command1_Click() Dim i As Integer, sum As Integer sum = 0

For i = 10 To 2 Step -2 sum = sum + i Next i = Str(sum) End Sub

运行程序,单击命令按钮Command1后弹出如图所示的出错信息提示,此时程序正执行的语句是 (A)Sum = 0 (C)sum = sum + i

20.某Visual Basic程序如下: Private Sub Command1_Click() Dim a As String a = \"d\"

a = Chr(Asc(a) - 32) = a End Sub

运行程序,单击命令按钮Command1后弹出如图所示的出错信息提示,此时程序正执行的语句是 (A)a = \"d\"

(C)a = Chr(Asc(a) - 32) 21.某Visual Basic程序如下: Private Sub Command1_Click() Dim x As Integer, i As Integer For i = 1 To 10 Step 3 x = i * (i + 2)

(B)End Sub (D) = a

(B)For i = 10 To 2 Step -2 (D) = Str(sum) (B)b = 5 (D) = Str(c)

List1AddItem Str(x) Next i End Sub

运行程序,单击命令按钮Command1后弹出如图所示的出错信息提示,引起该错误的语句是 (A)For i = 1 To 10 Step 3 (C)List1AddItem Str(x) 22.某Visual Basic程序如下: Private Sub Command1_Click()

Dim x As Integer, c As Integer, i As Integer c = 0

For i = 1 To 12 If 12 Mod i = 0 Then c = c + 1 End If Next i = Str(c) End Sub

运行程序,单击命令按钮Command1后弹出如图所示的出错信息提示,引起该错误的语句是 (A)For i = 1 To 12 (C)Next i

(B)c = c + 1 (D) = Str(c) (B)x = i * (i + 2) (D)Next i

23.下图所示是一个求和程序,程序界面上有标签Label1、标签Label2和一个命令按钮Command1。程序运行时,单击命令按钮Command1后弹出“编译错误”信息提示并指向错误语句所在代码。请问下面修改方法可以让程序正确运行的是:

(A)=s (B)=s (C)Text1=s (D)=s

24.某Visual Basic程序如下,执行该程序后,将会出现的错误提示为 Private Sub Command1_Click() Dim a(1 To 10) As Integer Dim i As Integer a(1) = 1 For i = 2 To 10 a(i) = a(i - 1) + i List1AddItem Str(a(i)) Next i End Sub

(A)下标越界 (B)子程序或函数未定义 (C)溢出 (D)类型不匹配 25.小王同学在调试VB程序时,会出现下图错误提示信息的是:

(A)Function sina(n) As Integer ....... End Function (B)Private Sub abc(a, b) as double ....... End Sub (C)Private Sub Command1_click() ....... End Sub (D)

Private Sub Command1_click() Private Sub Command1_click() ....... End Sub

26. VB语句s = s + Val(Key)在运行时出现“类型不匹配”信息,则变量s的数据类型可能是:

(A)Integer (B)double (C)single (D)string

27. 某VB程序段代码如下,它的作用是计算1*2*3*„„*99*100的值: Private Sub Command1_Click()

Dim s As Integer ------①

s = 1 ------② For i = 1 To 100 ------③ s = s * i ------④ Next i Print s End Sub

程序运行后出现“溢出”错误信息,下面对于出错原因分析正确的是: (A)把语句①改为dim s as double,原来s的数据类型不适合 (B)把语句②改为s=0,这样就不会出现数据溢出错误

(C)把语句③改为do……loop 循环结构就不会出现数据溢出错误

(D)VB不能用于计算1*2*3*……*99*100的值,否则一定会出现数据溢出错误 1 A 16 C

2 C 17 C 3 D 18 C 4 A 19 D 5 B 20 D 6 D 21 C 7 C 22 D 8 C 23 D 9 A 24 B 10 A 25 D 11 D 26 D 12 C 27 A 13 D 28 14 C 29 15 B 30

因篇幅问题不能全部显示,请点此查看更多更全内容