- 基础理论
- 数据及数据库技术
- 人工智能
- 算法理论
- 算法实例
- + 面向对象程序设计 VB开发工具
- 程序设计语言
- 循环结构
- 分支结构
- 顺序结构
- 类、对象、属性、方法、事件和事件处理的概念
- VB应用程序的界面设计与调试
- 基本数据类型
- 常量、变量、数组
- 常用的标准函数
- 基本运算及表达式
- 赋值语句
- 选择语句
- 循环语句
- 算法实例的程序实现
- 算法及算法的表示方法
- 多媒体理论
- 基础软件操作
- 算法软件操作
- 多媒体软件操作
- 网络技术应用
日期判断:从文本框Text1输入一个8位数字表示的日期,其中第1到4位表示年(第1位确定不为零),第5到6位表示月,第7到8位表示日。单击“判断”按钮,判断该日期是否合法,将结果依次输出到列表框List1。程序界面如下图所示:
提示:年份值符合下列两种情况之一的是闰年。
1.年份是4的倍数,但不是100的倍数;
2.年份是400的倍数。

(1)观察程序代码,可知“判断”按钮的对象名为 。(单选,填字母:
(2)为实现上述功能,请在划线处填入合适的代码。
Private Sub Judge_Click()
Dim riqi As String, st As String
Dim year As Integer, month As Integer, day As Integer
Dim rn As Boolean, hefa As Boolean
riqi = Text1.Text
year =" Val(Mid(riqi," 1, 4))
month =" Val(Mid(riqi," 5, 2))
day = ① ‘第①处
st =" Str(year)" + "年" + Str(month) + "月" + Str(day) + "日"
rn = False ‘用于判断是否为闰年
If ② Then rn = True ‘第②处
If year Mod 4 =" 0" And year Mod 100 <> 0 Then rn = True
hefa = True ‘用于判断是否为合法日期
If month =" 0" Or month > 12 Then hefa = False
If day =" 0" Then hefa = False
If (month =" 1" Or month =" 3" Or month =" 5" Or month =" 7" Or ’与下一行语句同行
month =" 8" Or month =" 10" Or month =" 12)" And day > 31 Then hefa = False
If (month =" 4" Or month =" 6" Or month =" 9" Or month = 11) ’与下一行语句同行
And day > 30 Then hefa = False
If ③ Then hefa =" False" ’第③处,判断闰年2月的天数是否合法
If month =" 2" And Rn =" False" And day > 28 Then hefa = False
If hefa =" True" Then st =" st" + " 合法日期" Else st =" st" + " 非法日期"
List1.AddItem st
End Sub
提示:年份值符合下列两种情况之一的是闰年。
1.年份是4的倍数,但不是100的倍数;
2.年份是400的倍数。

(1)观察程序代码,可知“判断”按钮的对象名为 。(单选,填字母:
A.Text1/ | B.List1/ | C.Command1/ | D.Judge/E.判断) |
Private Sub Judge_Click()
Dim riqi As String, st As String
Dim year As Integer, month As Integer, day As Integer
Dim rn As Boolean, hefa As Boolean
riqi = Text1.Text
year =" Val(Mid(riqi," 1, 4))
month =" Val(Mid(riqi," 5, 2))
day = ① ‘第①处
st =" Str(year)" + "年" + Str(month) + "月" + Str(day) + "日"
rn = False ‘用于判断是否为闰年
If ② Then rn = True ‘第②处
If year Mod 4 =" 0" And year Mod 100 <> 0 Then rn = True
hefa = True ‘用于判断是否为合法日期
If month =" 0" Or month > 12 Then hefa = False
If day =" 0" Then hefa = False
If (month =" 1" Or month =" 3" Or month =" 5" Or month =" 7" Or ’与下一行语句同行
month =" 8" Or month =" 10" Or month =" 12)" And day > 31 Then hefa = False
If (month =" 4" Or month =" 6" Or month =" 9" Or month = 11) ’与下一行语句同行
And day > 30 Then hefa = False
If ③ Then hefa =" False" ’第③处,判断闰年2月的天数是否合法
If month =" 2" And Rn =" False" And day > 28 Then hefa = False
If hefa =" True" Then st =" st" + " 合法日期" Else st =" st" + " 非法日期"
List1.AddItem st
End Sub
为了体现人文关怀,某公司规定当气温高于35摄氏度时,停止一切户外作业。如用编程实现这一规定,我们在设计算法时应采用
A.顺序结构 |
B.选择结构 |
C.循环结构 |
D.树型结构 |
有如下VB程序段:
For i =" 1" To 3
For j =" 5" To i Step -1
If a(j) < a(j + 1) Then
k =" a(j):" a(j) =" a(j" + 1): a(j + 1) = k
End If
Next j
List1.AddItem Str(a(i))
Next i
数组元素a(1)到a(6)的数据依次为“1,5,7,6,9,3”,经过该程序段加工后,列表框list1中显示的内容是:
For i =" 1" To 3
For j =" 5" To i Step -1
If a(j) < a(j + 1) Then
k =" a(j):" a(j) =" a(j" + 1): a(j + 1) = k
End If
Next j
List1.AddItem Str(a(i))
Next i
数组元素a(1)到a(6)的数据依次为“1,5,7,6,9,3”,经过该程序段加工后,列表框list1中显示的内容是:
A.9、7、6 | B.1,3,5 | C.9、7、6、1、5、3 | D.9,7,6,5,3,1 |
小明设计了一个VB程序(界面如图所示),随机产生n(n<=100)个大于等于a(a<=100)且小于等于b(b<=100)的整数,并在列表框List1中降序显示。

实现上述功能的VB代码如下:
请在划线处填入合适代码。
Private Sub Command1_Click()
Dim a As Integer, b As Integer
Dim n As Integer, t As Integer
Dim m(1 To 100) As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
n = Val(Text3.Text)
If a > b Then t =" a:" a =" b:" b = t
Randomize
①
For i =" 2" To n
m(i) =" Int(Rnd" * (b - a + 1)) + a
If m(i) > m(i - 1) Then
②
For j =" i" - 1 To 1 Step -1
If temp < m(j) Then Exit For
m(j + 1) = m(j)
Next j
③
End If
Next i
For i =" 1" To n
List1.AddItem Str(m(i))
Next i
End Sub
程序①处的代码是
程序②处的代码是
程序③处的代码是

实现上述功能的VB代码如下:
请在划线处填入合适代码。
Private Sub Command1_Click()
Dim a As Integer, b As Integer
Dim n As Integer, t As Integer
Dim m(1 To 100) As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
n = Val(Text3.Text)
If a > b Then t =" a:" a =" b:" b = t
Randomize
①
For i =" 2" To n
m(i) =" Int(Rnd" * (b - a + 1)) + a
If m(i) > m(i - 1) Then
②
For j =" i" - 1 To 1 Step -1
If temp < m(j) Then Exit For
m(j + 1) = m(j)
Next j
③
End If
Next i
For i =" 1" To n
List1.AddItem Str(m(i))
Next i
End Sub
程序①处的代码是
程序②处的代码是
程序③处的代码是
某次测验后,一位同学利用VB编写了一个查分系统。他首先把班级所有同学的学号、姓名、总分及名次数据存放在名为“student.accdb”的info表中。查分系统的功能如下:在文本框Text1中输入学号,单击“开始查找”按钮,若找到该学号,则在标签Label4中该学生的学号、姓名、总分及名次;若找不到该学号,则显示“查无此人”。按此要求编写程序如下,但加框处代码有错,请改正。

Dim a (1 To 50) As String ’用来存放学号数据
Dim b (1 To 50) As String ’用来存放姓名数据
Dim c (1 To 50) As Single ’用来存放总分数据
Dim d (1 To 50) As Integer ’用来存放名次数据
Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
conn.ConnectionString=“Provider=Microsoft.ACE.OLEDB.12.0;DATA Soure=”+App.Path+“/Student.accdb”
conn.Open
Set rs.ActiveConnection=conn
rs.Open “SELECT*FROM info”
n=0
Do While Not rs.EOF
n=n+1
a(n)=rs.Fields(“学号”)
b(n)=rs.Fields(“姓名”)
c(n)=rs.Fields(“总分”)
d(n)=rs.Fields(“名次”)
rs.Move Next
Loop
rs.Close
conn.Close
Set rs=Nothing
Set conn=Nothing
End Sub
Private Sub Command1_click()
Dim key As String,i As Integer
Dim find As Boolean
key=Text1.Text
i=1
find=True
Do While And find①
If key=a(i) Then
find=False
Else
②
End If
Loop
If find=False Then
Label4.Caption=“学号为”+key+“的名字为”+b(i)+“总分为”+c(i)+“名次为”+d(i)
Else
Label4.Caption=“查无此人”
End If
End Sub
程序中①加框处改为:_____________________________________。
程序中②加框处改为:_____________________________________。

Dim a (1 To 50) As String ’用来存放学号数据
Dim b (1 To 50) As String ’用来存放姓名数据
Dim c (1 To 50) As Single ’用来存放总分数据
Dim d (1 To 50) As Integer ’用来存放名次数据
Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
conn.ConnectionString=“Provider=Microsoft.ACE.OLEDB.12.0;DATA Soure=”+App.Path+“/Student.accdb”
conn.Open
Set rs.ActiveConnection=conn
rs.Open “SELECT*FROM info”
n=0
Do While Not rs.EOF
n=n+1
a(n)=rs.Fields(“学号”)
b(n)=rs.Fields(“姓名”)
c(n)=rs.Fields(“总分”)
d(n)=rs.Fields(“名次”)
rs.Move Next
Loop
rs.Close
conn.Close
Set rs=Nothing
Set conn=Nothing
End Sub
Private Sub Command1_click()
Dim key As String,i As Integer
Dim find As Boolean
key=Text1.Text
i=1
find=True
Do While And find①
If key=a(i) Then
find=False
Else
②
End If
Loop
If find=False Then
Label4.Caption=“学号为”+key+“的名字为”+b(i)+“总分为”+c(i)+“名次为”+d(i)
Else
Label4.Caption=“查无此人”
End If
End Sub
程序中①加框处改为:_____________________________________。
程序中②加框处改为:_____________________________________。
使用VB中的ADO访问文件名为“Course.accdb”的Access数据库,与数据库建立连接的程序段如下:
Dim conn As New ADODB.Connection
conn.ConnectionString=“Provider=Microsoft.AC
Dim conn As New ADODB.Connection
conn.ConnectionString=“Provider=Microsoft.AC
A.OLEDB.12.0;Data Source=”+App.Path+“/monkey.accdb” conn.Open 在调试时出现了如图所示的错误提示框。 ![]() 产生该错误提示的原因可能是( ) |
B.没有定义ADO的Connection对象实例 B. 没有打开Connection对象实例到数据库的连接 |
C.指定的数据库文件不存在 |
D.没有添加选择Microsoft ActiveX Data Objects 6.1 Library组件 |
下面VB程序的功能是判断一个整数是否为素数。在文本框Text1中输入一个整数x,如果x是素数,则在标签Label1中显示“Y”,否则显示“N”。程序中有两处错误,请改正。
Private Sub Command1_Click( )
Dim i As Integer,x As Integer,pd As Boolean
Val(Text1.Text)=x
pd=True
i=1
Do While i<x And pd=True
If x Mod i=0 Then
pd=False
Else
i=i+1
End If
Loop
If pd=True Then
Label1.Caption=“Y”
Else
Label1.Caption=“N”
End If
End Sub
错误语句1:________改为:________;
错误语句2:________改为:________。
Private Sub Command1_Click( )
Dim i As Integer,x As Integer,pd As Boolean
Val(Text1.Text)=x
pd=True
i=1
Do While i<x And pd=True
If x Mod i=0 Then
pd=False
Else
i=i+1
End If
Loop
If pd=True Then
Label1.Caption=“Y”
Else
Label1.Caption=“N”
End If
End Sub
错误语句1:________改为:________;
错误语句2:________改为:________。