VB中常见的错误
1、运行下面的 Visual Basic程序,单击命令按钮 Command1,出现如下图所示的提示信息:
Private Sub Command1_Click() Dim a As Single, b As Single a = Val(Text1.Text) b = 10 If a >= b b = a * a + 2 * b End If Label1.Caption = 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
List1.AddItem Str(a(i))
End Sub
运行程序,单击命令按钮Command1后,出现的错误提示为
(A) 下标越界 (B) 子程序或函数未定义
(C) 溢出 (D) 类型不匹
5、有如下的Visual Basic程序:
Private Sub Command1_Click() Const pi = 3.14 Dim s As Single, r As Single r = Val(text1.Text) pi = 3.1415 s = pi * r ^ 2 Label1.Caption = "面积为" + 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 List1.AddItem Str(a(i)) End Sub | |
运行程序,单击命令按钮Command1后弹出如图所示的出错信息提示,此时程序正执行的语句是
(A)For i = 1 To 10 | (B)a(i) = i * i |
(C)Next i | (D)List1.AddItem Str(a(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) Text1.Text = Str(c) End Sub | |
运行程序,单击命令按钮Command1后弹出如图所示的出错信息提示,此时程序正执行的语句是
(A)a = 1 | (B)b = 5 |
(C)c = Sqr(a - b) | (D)Text1.Text = Str(c) |
8、某同学正编写一个判断酒驾行为的Visual Basic程序,其窗体和代码窗口如下图所示。
根据代码窗口中的程序,要在程序运行时获取输入的x值,窗体上必须增加的对象是
A. 标签Text1 B. 标签Label2 C. 文本框Text1 D. 文本框Label2
9、运行下面的 Visual Basic程序,单击命令按钮 Command1,出现如下图所示的提示信息:
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
Text1.Text = 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
Text1.Text = 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
Text1.Text = 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 List1.AddItem Str(a(i)) End Sub | |
运行程序,单击命令按钮Command1后弹出如图所示的出错信息提示,此时程序正执行的
语句是
(A)For i = 0 To 10 | (B)a(i) = i * i |
(C)Next i | (D)List1.AddItem Str(a(i)) |
14.运行如下Visual Basic程序,单击命令按钮Command1,出现如图所示的出错信息。发生"除数为零"错误时所执行的语句是
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Single
a = 2 '①
b = a + 1 '②
c = a / (b - 3) '③
Text1.Text = Str(c) '④
End Sub
(A)① (B)②
(C)③ (D)④
15.有如下的Visual Basic程序:
Private Sub Command1_Click()
Const pi = 3.14 '①
Dim s As Single, r As Single
r = Val(text1.Text) '②
pi = 3.1415 '③
s = pi * r ^ 2 array在vb什么意思啊'④
Label1.Caption = "面积为" + Str(s)
End Sub
程序运行后,单击命令按钮Command1,出现如图所示的错误提示,下列原因分析正确的是
(A)常量不能用小数 |
(B)pi是常量,不允许赋值 |
(C)文本框Text1中输入的数据不是常量 |
(D)表达式结果超过了变量类型的范围 |
16.题目如上题,问具体是哪条语句出错
(A)① (B)② (C)③ (D)④
17.运行如下Visual Basic程序,单击命令按钮Command1,出现如图所示的出错信息。发生"类型不匹配"错误时所执行的语句是
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论