- 基础理论
- 数据及数据库技术
- 人工智能
- 算法理论
- 程序设计语言
- 循环结构
- 分支结构
- 顺序结构
- 类、对象、属性、方法、事件和事件处理的概念
- VB应用程序的界面设计与调试
- 基本数据类型
- 常量、变量、数组
- 常用的标准函数
- 基本运算及表达式
- 赋值语句
- 选择语句
- + 循环语句
- 多媒体理论
- 基础软件操作
- 算法软件操作
- 多媒体软件操作
- 网络技术应用
有如下VB程序段:
Private Sub Command1_Click()
Dim i As Integer, x As Integer
x = 1
For i = 1 To 5 Step 2
x = x + i
Text1.Text = Str(x)
Next i
End Sub
则该程序运行后,文本框Text1中显示的数据个数是
Private Sub Command1_Click()
Dim i As Integer, x As Integer
x = 1
For i = 1 To 5 Step 2
x = x + i
Text1.Text = Str(x)
Next i
End Sub
则该程序运行后,文本框Text1中显示的数据个数是
A.1个 | B.2个 | C.3个 | D.5个 |
(加试题)有如下VB程序段:
Private Sub Command1_Click()
Dim i As Integer, s As Integer
s = 0
For i = 1 To 5 Step 3
s = s + fun(i)
Next i
Text1.Text = Str(s)
End Sub
Function fun(n As Integer) As Integer
If n = 1 Then
fun = 2
Else
fun = fun(n - 1) + n
End If
End Function
执行完该程序后,S的值为( )
Private Sub Command1_Click()
Dim i As Integer, s As Integer
s = 0
For i = 1 To 5 Step 3
s = s + fun(i)
Next i
Text1.Text = Str(s)
End Sub
Function fun(n As Integer) As Integer
If n = 1 Then
fun = 2
Else
fun = fun(n - 1) + n
End If
End Function
执行完该程序后,S的值为( )
A.7 | B.11 | C.13 | D.25 |
以下程序段运行时出现如图所示的错误提示:
For i=1 To 100
If Rnd>0.5 Then
n=n+1
Else
m=m+1
Next i
分析该程序段,该代码中缺少了( )

If Rnd>0.5 Then
n=n+1
Else
m=m+1
Next i
分析该程序段,该代码中缺少了( )
A.For | B.End If | C.Next | D.If |
在包含20 个元素的数组a 中,寻找最小值的VB 程序段如下。其中变量min 用于储最小值:
For i=2 To 20
If a(i)<min Then min=a(i)
Next i
则方框中最合适的语句是: ( )
For i=2 To 20
If a(i)<min Then min=a(i)
Next i
则方框中最合适的语句是: ( )
A.a(i)=min | B.min=a(i) | C.a(1)=min | D.min=a(1) |
有如下VB程序段:
Dim a(1 To 10) As Integer, i As Integer, j As Integer
a(1) = 1: a(2) = 1
For i = 3 To 5
a(i) = 1
For j = i - 1 To 2 Step -1
a(j) = a(j) + a(j - 1)
Next j
Next i
Text1.Text = Str(a(3))
该程序段运行后,在文本框Text1中显示的内容是
Dim a(1 To 10) As Integer, i As Integer, j As Integer
a(1) = 1: a(2) = 1
For i = 3 To 5
a(i) = 1
For j = i - 1 To 2 Step -1
a(j) = a(j) + a(j - 1)
Next j
Next i
Text1.Text = Str(a(3))
该程序段运行后,在文本框Text1中显示的内容是
A.1 | B.3 | C.4 | D.6 |
有如下VB程序段:
Dim a(1 To 10) As Integer
s = "7218634594": n = Len(s)
t = 0
For i = 1 To n - 1
a(i) = Val(Mid(s, i, 2))
Next i
For i = 1 To n - 2 Step 2
k = i
For j = i + 2 To n - 1 Step 2
If a(j) < a(k) Then k = j
Next j
If k <> i Then
temp = a(i): a(i) = a(k): a(k) = temp: t = t + 1
End If
Next i
Text1.Text = Str(t)
该程序段运行后,文本框Text1中显示的内容是
Dim a(1 To 10) As Integer
s = "7218634594": n = Len(s)
t = 0
For i = 1 To n - 1
a(i) = Val(Mid(s, i, 2))
Next i
For i = 1 To n - 2 Step 2
k = i
For j = i + 2 To n - 1 Step 2
If a(j) < a(k) Then k = j
Next j
If k <> i Then
temp = a(i): a(i) = a(k): a(k) = temp: t = t + 1
End If
Next i
Text1.Text = Str(t)
该程序段运行后,文本框Text1中显示的内容是
A.1 | B.2 |
C.3 | D.4 |
(加试题)某VB程序功能:输入正整数n,单击命令按钮Command1后,则会衍生出一串有规律的数字,形式为“1 2 3…n-1 n n-1…3 2 1 ”。例如n=6时,显示的数字串为“1 2 3 4 5 6 5 4 3 2 1 ”。
Private Sub Command1_Click()
Dim a As intger, i As intger, s As String
n = Val(Text1.Text)
s = ""
For i = 1 To 2 * n - 1
If i > n Then ① Else ②
Next i
text2.Text = s
End Sub
为实现以上功能,①②处分别填写( )
Private Sub Command1_Click()
Dim a As intger, i As intger, s As String
n = Val(Text1.Text)
s = ""
For i = 1 To 2 * n - 1
If i > n Then ① Else ②
Next i
text2.Text = s
End Sub
为实现以上功能,①②处分别填写( )
A.①s=Str(2*n-i) ②s=Str(i) | B.①s=s+Str(2*n-i) ②s=s+Str(i) |
C.①s=s+Str(2*n-1) ②s=s+Str(2*n) | D.①s= Str(2*n-1) ②s= Str(2*n) |
在一个文档中,每行包含一个字符串。现使用如下规则对其压缩:压缩时,对于每个字符串求其与前一字符串的公共前缀,然后使用公共前缀的长度和字符串的剩余部分(以空格隔开)表示该字符串,每个空格和字符都会占用一个字节空间。图a所示为该压缩规则示意图。小明为此编写了VB程序,功能如下:运行程序时,在列表框List1中显示原字符串内容,单击“压缩”按钮Command1,在列表框List2中显示压缩后字符串,并在标签Label2中显示压缩后容量。程序运行界面如图b所示。

实现上述功能的 VB 代码如下,但划线处代码有错,请改正。
Dim word(3000) As String, pre(3000) As String
Const n = 2000
Private Sub Form_Load()
'该过程的作用是从数据库读取 n 个单词,按字典顺序存储在数组 word 中,并在 Label1输出单词数量和容量
'代码略
End Sub
Private Sub Command1_Click()
Dim conp As Integer '存储压缩后的容量
Dim f As Boolean,m As Integer,k As Integer 'k 存储公共前缀的长度
conp=0
For i=1 To n
k=0
If i=1 Then f=False Else f=True
k=Len(word(i)) '(1)______________
Do While k<m And f=True
If Mid(word(i),1,k+1)=Mid(word(i-1),1,k+1) Then
k=k-1 '(2)____________
Else
f=False
End If
Loop
pre(i)=CStr(k)+" "+Mid(word(i),k+1,Len(word(i)))
'Cstr()函数能够将数字类型的值转换为字符类型的值,并却掉前导空格。
List2.AddItem pre(i)
conp=conp+Len(word(i)) '(3)______________
Next i
Label2.Caption="压缩后容量为"+Str(conp)+"字节"
End Sub

实现上述功能的 VB 代码如下,但划线处代码有错,请改正。
Dim word(3000) As String, pre(3000) As String
Const n = 2000
Private Sub Form_Load()
'该过程的作用是从数据库读取 n 个单词,按字典顺序存储在数组 word 中,并在 Label1输出单词数量和容量
'代码略
End Sub
Private Sub Command1_Click()
Dim conp As Integer '存储压缩后的容量
Dim f As Boolean,m As Integer,k As Integer 'k 存储公共前缀的长度
conp=0
For i=1 To n
k=0
If i=1 Then f=False Else f=True
k=Len(word(i)) '(1)______________
Do While k<m And f=True
If Mid(word(i),1,k+1)=Mid(word(i-1),1,k+1) Then
k=k-1 '(2)____________
Else
f=False
End If
Loop
pre(i)=CStr(k)+" "+Mid(word(i),k+1,Len(word(i)))
'Cstr()函数能够将数字类型的值转换为字符类型的值,并却掉前导空格。
List2.AddItem pre(i)
conp=conp+Len(word(i)) '(3)______________
Next i
Label2.Caption="压缩后容量为"+Str(conp)+"字节"
End Sub
编写“数字序列”程序,实现如下功能:在文本框Text1中输入[100,500]范围内的整数,单击“生成”按钮Command1,在列表框List1中显示9个该序列的数字。数字序列的生成规则为:该项的数字+该数百位上的数字+该数十位上的数字+该数个位上的数字=下一项的数字,例如:365+3+6+5=379。小明编写了VB程序,运行的界面如图所示,程序代码如下:

(1)代码“Private Sub Command1_Click()”中的Command1_Click()是_________。
(单选,填字母:
(2)为实现上述功能,请在划线处填入合适的代码。
Private Sub Command1_Click( )
Dim n As Integer, i As Integer
Dim a As Integer,b As Integer
Dim c As Integer
List1.Clear
n = Val(Text1.Text)
If n >= 100 And n <= 500 Then
For i = 1 To 9
a = n \ 100
b = (n - 100 * a) \ 10
c = n Mod 10
_______________________
Next i
Else
List1.AddItem "输入数值有误"
End If

End Sub
(3)上述代码段中缺少了List1.AddItem Str(i)+"."+Str(n),此句代码应该加在_____(填字母)位置。
(4)若输入的数字为123,则List1中第三行为__________________。

(1)代码“Private Sub Command1_Click()”中的Command1_Click()是_________。
(单选,填字母:
A.对象名 | B.事件 | C.事件处理过程 | D.方法 ) |
Private Sub Command1_Click( )
Dim n As Integer, i As Integer
Dim a As Integer,b As Integer
Dim c As Integer
List1.Clear
n = Val(Text1.Text)
If n >= 100 And n <= 500 Then
For i = 1 To 9

a = n \ 100
b = (n - 100 * a) \ 10
c = n Mod 10
_______________________

Next i

Else
List1.AddItem "输入数值有误"
End If

End Sub
(3)上述代码段中缺少了List1.AddItem Str(i)+"."+Str(n),此句代码应该加在_____(填字母)位置。
(4)若输入的数字为123,则List1中第三行为__________________。