Private Sub Command1_Click() ''' 不得删除本行注释
TxtWelCome.Value = "欢迎使用VBA !" End Sub 一
-2
Private Sub Command1_Click() ''' 不得删除本行注释 Dim s%, i%, M%, N% M = Text1.Value N = Text2.Value s = 0
For i = M To N
s = s + i Next
Label1.Caption = s End Sub 一
-3
Private Sub Command1_Click() ''' 不得删改本行注释
Dim rs As ADODB.Recordset Dim strSQL As String
Set rs = New ADODB.Recordset
strSQL = "Select * from course where 课程编号='" & Text1.Value & "'" '本行需要补充代码 rs.Open strSQL, CurrentProject.Connection, 2, 2 ' 本行需要补充代码 If rs.EOF Then rs.AddNew
rs("课程编号") = Text1 rs("课程名称") = Text2 rs("学时") = Text3
rs("学分") = Text4 ' 本行需要补充代码 rs.Update End If rs.Close
Set rs = Nothing End Sub 二-1
Private Sub Command1_Click() ''' 不得删除本行注释 Label1.Visible = True End Sub
Private Sub Command2_Click() ''' 不得删除本行注释 Label1.Visible = False End Sub 二-2
Private Sub Command1_Click() ''' 不得删除本行注释
Dim x As Integer, y As Integer, z As Integer x = Text1.Value y = Text2.Value
If Frame1.Value = 1 Then z = x + y
ElseIf Frame1.Value = 2 Then z = x - y Else
z = x * y End If
Label6.Caption = z End Sub 二-3
Private Sub Command1_Click() ' 成绩等级评定
' *** User Code Begin *** Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset ' 本行需补充代码 rs.Open "select * from 学生", CurrentProject.Connection, 2, 2
Do While Not rs.EOF() ' 本行需补充代码 Select Case rs("综合分") Case Is >= 90
rs("等级") = "优秀" Case Is >= 80
rs("等级") = "良好" ' 本行需补充代码 Case Is >= 70
rs("等级") = "中等" Case Is >= 60
rs("等级") = "及格" Case Else
rs("等级") = "不及格" ' 本行需补充代码 End Select
rs.Update ' 本行需补充代码 rs.MoveNext Loop
rs.Close
Set rs = Nothing
' *** User Code End ***
等级评定后学生信息.Form.RecordSource = "select * from 学生" MsgBox "完成等级评定!", 0 + 64, "提示" End Sub 三
-1
Private Sub Command1_Click() ''' 不得删除本行注释
Label1.ForeColor = RGB(255, 0, 0) End Sub
Private Sub Command2_Click() ''' 不得删除本行注释
Label1.ForeColor = RGB(0, 0, 255) End Sub 三-2
Private Sub Command1_Click() ''' 不得删除本行注释
Dim a As Integer, b As Integer a = Text1.Value b = Text2.Value If a > b Then
Label1.Caption = "a>b" ElseIf a = b Then
Label1.Caption = "a=b" Else
Label1.Caption = "a
-3
Private Sub Combo1_Change() ''' 不得删改本行注释
Dim rs As ADODB.Recordset Dim strSQL As String
Set rs = New ADODB.Recordset
strSQL = "Select * From book where 书号='" & Combo1.Value & "'" ' 本行需要补充代码 rs.Open strSQL, CurrentProject.Connection, 2, 2 ' 本行需要补充代码
If Not rs.EOF() Then Text1 = rs("书名") Text2 = rs("单价") Text3 = rs("数量")
Text4 = rs("单价") * rs("数量") ' 本行需要补充代码 End If rs.Close
Set rs = Nothing End Sub 四
-1
Private Sub Command1_Click() ''' 不得删除本行注释
TxtEnabled.Enabled = True End Sub
Private Sub Command2_Click() ''' 不得删除本行注释
TxtEnabled.Enabled = False End Sub
四
-2
Private Sub Command1_Click() ' 按分段函数求y
Dim x As Single, y As Single ' *** Code Begin *** x = Text1.Value If x
y = 3 * x - 2 End If
Label3.Caption = y ' *** Code End *** End Sub 四-3
Private Sub Command1_Click() ' 按姓名查找教师信息 ' *** User Code Begin *** Dim f_mark As Boolean Dim SQLstr As String
Dim rs As ADODB.Recordset ' 本行需补充代码 Set rs = New ADODB.Recordset
SQLstr = "select 教师. 姓名, 教师. 性别, 教师. 出生日期, 教师. 职称, 专业. 专业名称 from 教师, 专业 where 教师. 专业编号=专业. 专业编号"
rs.Open SQLstr, CurrentProject.Connection, 2, 2 ' 本行需补充代码 f_mark = False
Do While Not rs.EOF() And Not f_mark
If rs("姓名") = Text1.Value Then ' 本行需补充代码 Text2.Value = rs("姓名") Text3.Value = rs("性别") Text4.Value = rs("出生日期") Text5.Value = rs("专业名称")
Select Case rs("职称") ' 本行需补充代码 Case "讲师"
Frame1.Value = 1
Case "副教授" ' 本行需补充代码 Frame1.Value = 2 Case "教授"
Frame1.Value = 3 ' 本行需补充代码
End Select f_mark = True End If
rs.MoveNext ' 本行需补充代码 Loop
If Not f_mark Then
MsgBox "查无此人!", 0 + 64, "提示" End If rs.Close
Set rs = Nothing
' *** User Code End *** End Sub 五
-1
Private Sub ComboFont_Change() ''' 不得删除本行注释
TxtTest.FontName = ComboFont.Value End Sub 五-2
Private Sub Command1_Click() ''' 不得删除本行注释 Dim x As Integer x = Text1.Value If x
Label1.Caption = "请输入一个自然数" ElseIf x Mod 2 = 0 Then
Label1.Caption = x & "是偶数" Else
Label1.Caption = x & "是奇数" End If End Sub 五
-3
Private Sub Command1_Click() Dim rs As ADODB.Recordset
Dim strSQL As String ' 用于存储SQL 语句
strSQL = "Select 姓名 From ExamStu Where 生源='" & Text1.Value & "'" ' 本行需要补充
代码
Set rs = New ADODB.Recordset ' 本行需要补充代码 rs.Open strSQL, CurrentProject.Connection, 2, 2
Do While Not rs.EOF ' 本行需要补充代码 List1.AddItem rs("姓名") rs.MoveNext Loop rs.Close
Set rs = Nothing End Sub 六
-1
Private Sub ListFontS_Click() ''' 不得删除本行注释
TxtTest.FontSize = ListFontS.Value End Sub 六-2
Private Sub Command1_Click() ' 字符串转换
' *** Code Begin ***
Dim str1 As String, str2 As String, char As String Dim n As Integer str1 = Text1.Value n = Len(str1) For i = 1 To n
char = Mid(str1, i, 1)
If Asc(char) >= Asc("a") And Asc(char)
str2 = str2 + char End If Next i
Label2.Caption = str2 ' *** Code End *** End Sub 六-3
Private Sub Command1_Click() ' 计算平均身高并筛选学生 ' *** User Code Begin *** ' 计算平均身高
Dim H_Avg As Single
Dim Avg_rs As ADODB.Recordset ' 本行需补充代码 Set Avg_rs = New ADODB.Recordset
Avg_rs.Open "select avg(身高) as 平均身高 from 学生", CurrentProject.Connection, 2, 2 ' 将平均身高值赋予变量H_Avg H_Avg = Avg_rs("平均身高")
Text1.Value = H_Avg ' 本行需补充代码 Avg_rs.Close
Set Avg_rs = Nothing ' 本行需补充代码 'Sou_rs记录集来源于' 学生' 表 Dim n As Integer
Dim Sou_rs As ADODB.Recordset Set Sou_rs = New ADODB.Recordset
Sou_rs.Open "select * from 学生", CurrentProject.Connection, 2, 2 ' 本行需补充代码 'Tar_rs记录集来源于' 符合条件学生' 表 Dim Tar_rs As ADODB.Recordset
Set Tar_rs = New ADODB.Recordset ' 本行需补充代码 Tar_rs.Open "select * from 符合条件学生", CurrentProject.Connection, 2, 2 n = 0
Do While Not Sou_rs.EOF()
If Sou_rs("身高") >= H_Avg Then
Tar_rs.AddNew ' 本行需补充代码 Tar_rs("学号") = Sou_rs("学号") Tar_rs("姓名") = Sou_rs("姓名") Tar_rs("性别") = Sou_rs("性别")
Tar_rs("出生日期") = Sou_rs("出生日期") ' 本行需补充代码 Tar_rs("生源") = Sou_rs("生源") Tar_rs("身高") = Sou_rs("身高")
n = n + 1 ' 本行需补充代码 End If
Sou_rs.MoveNext Loop
Tar_rs.Update ' 本行需补充代码 Sou_rs.Close
Set Sou_rs = Nothing Tar_rs.Close
Set Tar_rs = Nothing Text2.Value = n
' *** User Code End ***
符合条件学生信息.Form.RecordSource = "select * from 符合条件学生" MsgBox "完成筛选!", 0 + 64, "提示" End Sub 七
-1
Private Sub Command1_Click()
''' 不得删除本行注释 TxtDate.Value = Date End Sub
Private Sub Command7_Click() Text5.Value = Time End Sub 七
-2
Private Sub Command1_Click() ''' 不得删除本行注释 Dim i%, s% s = 0
For i = 100 To 200 If i Mod 2 = 1 Then s = s + i End If Next
Text1.Value = s End Sub 七-3
Private Sub Command1_Click() Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset ' 本行需补充代码 rs.Open "select * from stu", CurrentProject.Connection, 2, 2 ' 本行需补充代码 Do While Not rs.EOF
Select Case rs("综合分") Case Is >= 90
rs("等级") = "A"
Case Is >= 80 ' 本行需补充代码 rs("等级") = "B" Case Is >= 70
rs("等级") = "C" Case Is >= 60
rs("等级") = "D" Case Else
rs("等级") = "E" End Select rs.Update
rs.MoveNext ' 本行需补充代码 Loop rs.Close
Set rs = Nothing
AFT.Form.RecordSource = "select * from Stu" End Sub 八
-1
Private Sub Command1_Click() ''' 请不要删除本行注释
LblUserPassW.Caption = Trim(Text1.Value) & Trim(Text2.Value) End Sub 八-2
Private Sub Command1_Click()
' 求8个随机整数的最大数与最小数和的平均值 Dim x(8) As Integer, max As Integer, min As Integer Dim avg As Single Text1.Value = "" Randomize
' 产生8个100到200之间的随机数,并显示在文本框Text1中 For i = 1 To 8
x(i) = Round((200 - 100) * Rnd, 0) + 100 Text1.Value = Text1.Value & x(i) & " " Next i
' 查找8个随机数的最大值和最小值,分别存入max 和min max = x(1) min = x(1) For i = 2 To 8
If max
If min > x(i) Then min = x(i) End If Next i
' 计算最大值和最小值的平均值avg ,并显示在标签Label3中 avg = (max + min) / 2 Label3.Caption = avg End Sub 八-3
Private Sub Command1_Click()
' 商品销售
' *** User Code Begin ***
Dim yn As Boolean
Dim s As Single
yn = MsgBox("确定销售吗?", 1 + 32, "提示")
If yn Then
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset ' 本行需补充代码
rs.Open "select * from 商品表 where 商品编号='" + combo1 + "'", CurrentProject.Connection, 3, 3
If Val(Text5.Value) > rs("库存量") Then
MsgBox " 商品拟销售数量超过库存量, 无法完成销售!", 0 + 64, " 提示" ' 本行需补充代码
Text5.Value = 0
Text5.SetFocus
ElseIf Val(Text5.Value) = rs("库存量") Then
s = text4.Value * Text5.Value
rs.Delete ' 本行需补充代码
MsgBox "应收金额:" & s & "元, 且该商品销售后无库存, 请注意进货!", 0 + 64, "提示" ElseIf rs("库存量") - Val(Text5.Value)
rs("库存量") = rs("库存量") - Val(Text5.Value)
MsgBox "应收金额:" & s & "元, 且该商品销售后库存量不多, 请注意进货!", 0 + 64, "提示"
Else
s = text4.Value * Text5.Value
rs("库存量") = rs("库存量") - Val(Text5.Value) ' 本行需补充代码 MsgBox "应收金额:" & s & "元, 商品销售成功!", 0 + 64, "提示"
End If
rs.Update
End If
' *** User Code End ***
combo1.Value = ""
Text1.Value = ""
text2.Value = ""
text3.Value = ""
text4.Value = ""
Text5.Value = 0
rs.Close
Set rs = Nothing
End Sub
九-1
Private Sub Command1_Click()
''' 不得删除本行注释
Box1.BorderColor = RGB(0, 0, 255)
End Sub
九
-2
Private Sub Command1_Click()
''' 不得删除本行注释
If Text1.Value = "1234" Then
Label2.Caption = "欢迎进入本系统!"
Else
Label2.Caption = "密码错误,请重新输入!"
End If
End Sub
九
-3
Private Sub Command1_Click()
Dim H_Avg As Single
Dim Avg_rs As ADODB.Recordset
Set Avg_rs = New ADODB.Recordset ' 本行需补充代码
Avg_rs.Open "Select Avg(身高) as 平均身高 from stu", CurrentProject.Connection, 2, 2 ' 本行需补充代码
H_Avg = Avg_rs("平均身高")
Text1.Value = H_Avg
Avg_rs.Close
Set Avg_rs = Nothing ' 本行需补充代码 End Sub
十-1
Private Sub Frame1_Click()
''' 不得删除本行注释
Text1.Width = Frame1.Value
End Sub
Private Sub Frame2_Click()
''' 不得删除本行注释
Text1.FontSize = Frame2.Value
End Sub
十-2
Private Sub Command1_Click()
' 按指定公式计算f
' *** Code Begin ***
Dim f As Long, x As Long
n = Text1.Value
f = 0
x = 0
For I = 1 To n
x = x + I
f = f + x
Next I
Label2.Caption = f
' *** Code End ***
End Sub
十
-3
Private Sub Command1_Click()
Dim rs As adodb.Recordset ' 本行需补充代码
Set rs = New adodb.Recordset
Dim strSQL As String ' 用于存储SQL 语句
strSQL = "Select distinct 职称 from teacher" ' 本行需补充代码
rs.Open strSQL, CurrentProject.Connection, 2, 2 ' 本行需补充代码 Do While Not rs.EOF
Select Case rs("职称")
Case "教授"
Check1.Value = True
Case "副教授"
Check2.Value = True
Case "讲师"
Check3.Value = True
Case "助教"
Check4.Value = True
End Select
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub ' 本行需补充代码 ' 本行需补充代码 ' 本行需补充代码
Private Sub Command1_Click() ''' 不得删除本行注释
TxtWelCome.Value = "欢迎使用VBA !" End Sub 一
-2
Private Sub Command1_Click() ''' 不得删除本行注释 Dim s%, i%, M%, N% M = Text1.Value N = Text2.Value s = 0
For i = M To N
s = s + i Next
Label1.Caption = s End Sub 一
-3
Private Sub Command1_Click() ''' 不得删改本行注释
Dim rs As ADODB.Recordset Dim strSQL As String
Set rs = New ADODB.Recordset
strSQL = "Select * from course where 课程编号='" & Text1.Value & "'" '本行需要补充代码 rs.Open strSQL, CurrentProject.Connection, 2, 2 ' 本行需要补充代码 If rs.EOF Then rs.AddNew
rs("课程编号") = Text1 rs("课程名称") = Text2 rs("学时") = Text3
rs("学分") = Text4 ' 本行需要补充代码 rs.Update End If rs.Close
Set rs = Nothing End Sub 二-1
Private Sub Command1_Click() ''' 不得删除本行注释 Label1.Visible = True End Sub
Private Sub Command2_Click() ''' 不得删除本行注释 Label1.Visible = False End Sub 二-2
Private Sub Command1_Click() ''' 不得删除本行注释
Dim x As Integer, y As Integer, z As Integer x = Text1.Value y = Text2.Value
If Frame1.Value = 1 Then z = x + y
ElseIf Frame1.Value = 2 Then z = x - y Else
z = x * y End If
Label6.Caption = z End Sub 二-3
Private Sub Command1_Click() ' 成绩等级评定
' *** User Code Begin *** Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset ' 本行需补充代码 rs.Open "select * from 学生", CurrentProject.Connection, 2, 2
Do While Not rs.EOF() ' 本行需补充代码 Select Case rs("综合分") Case Is >= 90
rs("等级") = "优秀" Case Is >= 80
rs("等级") = "良好" ' 本行需补充代码 Case Is >= 70
rs("等级") = "中等" Case Is >= 60
rs("等级") = "及格" Case Else
rs("等级") = "不及格" ' 本行需补充代码 End Select
rs.Update ' 本行需补充代码 rs.MoveNext Loop
rs.Close
Set rs = Nothing
' *** User Code End ***
等级评定后学生信息.Form.RecordSource = "select * from 学生" MsgBox "完成等级评定!", 0 + 64, "提示" End Sub 三
-1
Private Sub Command1_Click() ''' 不得删除本行注释
Label1.ForeColor = RGB(255, 0, 0) End Sub
Private Sub Command2_Click() ''' 不得删除本行注释
Label1.ForeColor = RGB(0, 0, 255) End Sub 三-2
Private Sub Command1_Click() ''' 不得删除本行注释
Dim a As Integer, b As Integer a = Text1.Value b = Text2.Value If a > b Then
Label1.Caption = "a>b" ElseIf a = b Then
Label1.Caption = "a=b" Else
Label1.Caption = "a
-3
Private Sub Combo1_Change() ''' 不得删改本行注释
Dim rs As ADODB.Recordset Dim strSQL As String
Set rs = New ADODB.Recordset
strSQL = "Select * From book where 书号='" & Combo1.Value & "'" ' 本行需要补充代码 rs.Open strSQL, CurrentProject.Connection, 2, 2 ' 本行需要补充代码
If Not rs.EOF() Then Text1 = rs("书名") Text2 = rs("单价") Text3 = rs("数量")
Text4 = rs("单价") * rs("数量") ' 本行需要补充代码 End If rs.Close
Set rs = Nothing End Sub 四
-1
Private Sub Command1_Click() ''' 不得删除本行注释
TxtEnabled.Enabled = True End Sub
Private Sub Command2_Click() ''' 不得删除本行注释
TxtEnabled.Enabled = False End Sub
四
-2
Private Sub Command1_Click() ' 按分段函数求y
Dim x As Single, y As Single ' *** Code Begin *** x = Text1.Value If x
y = 3 * x - 2 End If
Label3.Caption = y ' *** Code End *** End Sub 四-3
Private Sub Command1_Click() ' 按姓名查找教师信息 ' *** User Code Begin *** Dim f_mark As Boolean Dim SQLstr As String
Dim rs As ADODB.Recordset ' 本行需补充代码 Set rs = New ADODB.Recordset
SQLstr = "select 教师. 姓名, 教师. 性别, 教师. 出生日期, 教师. 职称, 专业. 专业名称 from 教师, 专业 where 教师. 专业编号=专业. 专业编号"
rs.Open SQLstr, CurrentProject.Connection, 2, 2 ' 本行需补充代码 f_mark = False
Do While Not rs.EOF() And Not f_mark
If rs("姓名") = Text1.Value Then ' 本行需补充代码 Text2.Value = rs("姓名") Text3.Value = rs("性别") Text4.Value = rs("出生日期") Text5.Value = rs("专业名称")
Select Case rs("职称") ' 本行需补充代码 Case "讲师"
Frame1.Value = 1
Case "副教授" ' 本行需补充代码 Frame1.Value = 2 Case "教授"
Frame1.Value = 3 ' 本行需补充代码
End Select f_mark = True End If
rs.MoveNext ' 本行需补充代码 Loop
If Not f_mark Then
MsgBox "查无此人!", 0 + 64, "提示" End If rs.Close
Set rs = Nothing
' *** User Code End *** End Sub 五
-1
Private Sub ComboFont_Change() ''' 不得删除本行注释
TxtTest.FontName = ComboFont.Value End Sub 五-2
Private Sub Command1_Click() ''' 不得删除本行注释 Dim x As Integer x = Text1.Value If x
Label1.Caption = "请输入一个自然数" ElseIf x Mod 2 = 0 Then
Label1.Caption = x & "是偶数" Else
Label1.Caption = x & "是奇数" End If End Sub 五
-3
Private Sub Command1_Click() Dim rs As ADODB.Recordset
Dim strSQL As String ' 用于存储SQL 语句
strSQL = "Select 姓名 From ExamStu Where 生源='" & Text1.Value & "'" ' 本行需要补充
代码
Set rs = New ADODB.Recordset ' 本行需要补充代码 rs.Open strSQL, CurrentProject.Connection, 2, 2
Do While Not rs.EOF ' 本行需要补充代码 List1.AddItem rs("姓名") rs.MoveNext Loop rs.Close
Set rs = Nothing End Sub 六
-1
Private Sub ListFontS_Click() ''' 不得删除本行注释
TxtTest.FontSize = ListFontS.Value End Sub 六-2
Private Sub Command1_Click() ' 字符串转换
' *** Code Begin ***
Dim str1 As String, str2 As String, char As String Dim n As Integer str1 = Text1.Value n = Len(str1) For i = 1 To n
char = Mid(str1, i, 1)
If Asc(char) >= Asc("a") And Asc(char)
str2 = str2 + char End If Next i
Label2.Caption = str2 ' *** Code End *** End Sub 六-3
Private Sub Command1_Click() ' 计算平均身高并筛选学生 ' *** User Code Begin *** ' 计算平均身高
Dim H_Avg As Single
Dim Avg_rs As ADODB.Recordset ' 本行需补充代码 Set Avg_rs = New ADODB.Recordset
Avg_rs.Open "select avg(身高) as 平均身高 from 学生", CurrentProject.Connection, 2, 2 ' 将平均身高值赋予变量H_Avg H_Avg = Avg_rs("平均身高")
Text1.Value = H_Avg ' 本行需补充代码 Avg_rs.Close
Set Avg_rs = Nothing ' 本行需补充代码 'Sou_rs记录集来源于' 学生' 表 Dim n As Integer
Dim Sou_rs As ADODB.Recordset Set Sou_rs = New ADODB.Recordset
Sou_rs.Open "select * from 学生", CurrentProject.Connection, 2, 2 ' 本行需补充代码 'Tar_rs记录集来源于' 符合条件学生' 表 Dim Tar_rs As ADODB.Recordset
Set Tar_rs = New ADODB.Recordset ' 本行需补充代码 Tar_rs.Open "select * from 符合条件学生", CurrentProject.Connection, 2, 2 n = 0
Do While Not Sou_rs.EOF()
If Sou_rs("身高") >= H_Avg Then
Tar_rs.AddNew ' 本行需补充代码 Tar_rs("学号") = Sou_rs("学号") Tar_rs("姓名") = Sou_rs("姓名") Tar_rs("性别") = Sou_rs("性别")
Tar_rs("出生日期") = Sou_rs("出生日期") ' 本行需补充代码 Tar_rs("生源") = Sou_rs("生源") Tar_rs("身高") = Sou_rs("身高")
n = n + 1 ' 本行需补充代码 End If
Sou_rs.MoveNext Loop
Tar_rs.Update ' 本行需补充代码 Sou_rs.Close
Set Sou_rs = Nothing Tar_rs.Close
Set Tar_rs = Nothing Text2.Value = n
' *** User Code End ***
符合条件学生信息.Form.RecordSource = "select * from 符合条件学生" MsgBox "完成筛选!", 0 + 64, "提示" End Sub 七
-1
Private Sub Command1_Click()
''' 不得删除本行注释 TxtDate.Value = Date End Sub
Private Sub Command7_Click() Text5.Value = Time End Sub 七
-2
Private Sub Command1_Click() ''' 不得删除本行注释 Dim i%, s% s = 0
For i = 100 To 200 If i Mod 2 = 1 Then s = s + i End If Next
Text1.Value = s End Sub 七-3
Private Sub Command1_Click() Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset ' 本行需补充代码 rs.Open "select * from stu", CurrentProject.Connection, 2, 2 ' 本行需补充代码 Do While Not rs.EOF
Select Case rs("综合分") Case Is >= 90
rs("等级") = "A"
Case Is >= 80 ' 本行需补充代码 rs("等级") = "B" Case Is >= 70
rs("等级") = "C" Case Is >= 60
rs("等级") = "D" Case Else
rs("等级") = "E" End Select rs.Update
rs.MoveNext ' 本行需补充代码 Loop rs.Close
Set rs = Nothing
AFT.Form.RecordSource = "select * from Stu" End Sub 八
-1
Private Sub Command1_Click() ''' 请不要删除本行注释
LblUserPassW.Caption = Trim(Text1.Value) & Trim(Text2.Value) End Sub 八-2
Private Sub Command1_Click()
' 求8个随机整数的最大数与最小数和的平均值 Dim x(8) As Integer, max As Integer, min As Integer Dim avg As Single Text1.Value = "" Randomize
' 产生8个100到200之间的随机数,并显示在文本框Text1中 For i = 1 To 8
x(i) = Round((200 - 100) * Rnd, 0) + 100 Text1.Value = Text1.Value & x(i) & " " Next i
' 查找8个随机数的最大值和最小值,分别存入max 和min max = x(1) min = x(1) For i = 2 To 8
If max
If min > x(i) Then min = x(i) End If Next i
' 计算最大值和最小值的平均值avg ,并显示在标签Label3中 avg = (max + min) / 2 Label3.Caption = avg End Sub 八-3
Private Sub Command1_Click()
' 商品销售
' *** User Code Begin ***
Dim yn As Boolean
Dim s As Single
yn = MsgBox("确定销售吗?", 1 + 32, "提示")
If yn Then
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset ' 本行需补充代码
rs.Open "select * from 商品表 where 商品编号='" + combo1 + "'", CurrentProject.Connection, 3, 3
If Val(Text5.Value) > rs("库存量") Then
MsgBox " 商品拟销售数量超过库存量, 无法完成销售!", 0 + 64, " 提示" ' 本行需补充代码
Text5.Value = 0
Text5.SetFocus
ElseIf Val(Text5.Value) = rs("库存量") Then
s = text4.Value * Text5.Value
rs.Delete ' 本行需补充代码
MsgBox "应收金额:" & s & "元, 且该商品销售后无库存, 请注意进货!", 0 + 64, "提示" ElseIf rs("库存量") - Val(Text5.Value)
rs("库存量") = rs("库存量") - Val(Text5.Value)
MsgBox "应收金额:" & s & "元, 且该商品销售后库存量不多, 请注意进货!", 0 + 64, "提示"
Else
s = text4.Value * Text5.Value
rs("库存量") = rs("库存量") - Val(Text5.Value) ' 本行需补充代码 MsgBox "应收金额:" & s & "元, 商品销售成功!", 0 + 64, "提示"
End If
rs.Update
End If
' *** User Code End ***
combo1.Value = ""
Text1.Value = ""
text2.Value = ""
text3.Value = ""
text4.Value = ""
Text5.Value = 0
rs.Close
Set rs = Nothing
End Sub
九-1
Private Sub Command1_Click()
''' 不得删除本行注释
Box1.BorderColor = RGB(0, 0, 255)
End Sub
九
-2
Private Sub Command1_Click()
''' 不得删除本行注释
If Text1.Value = "1234" Then
Label2.Caption = "欢迎进入本系统!"
Else
Label2.Caption = "密码错误,请重新输入!"
End If
End Sub
九
-3
Private Sub Command1_Click()
Dim H_Avg As Single
Dim Avg_rs As ADODB.Recordset
Set Avg_rs = New ADODB.Recordset ' 本行需补充代码
Avg_rs.Open "Select Avg(身高) as 平均身高 from stu", CurrentProject.Connection, 2, 2 ' 本行需补充代码
H_Avg = Avg_rs("平均身高")
Text1.Value = H_Avg
Avg_rs.Close
Set Avg_rs = Nothing ' 本行需补充代码 End Sub
十-1
Private Sub Frame1_Click()
''' 不得删除本行注释
Text1.Width = Frame1.Value
End Sub
Private Sub Frame2_Click()
''' 不得删除本行注释
Text1.FontSize = Frame2.Value
End Sub
十-2
Private Sub Command1_Click()
' 按指定公式计算f
' *** Code Begin ***
Dim f As Long, x As Long
n = Text1.Value
f = 0
x = 0
For I = 1 To n
x = x + I
f = f + x
Next I
Label2.Caption = f
' *** Code End ***
End Sub
十
-3
Private Sub Command1_Click()
Dim rs As adodb.Recordset ' 本行需补充代码
Set rs = New adodb.Recordset
Dim strSQL As String ' 用于存储SQL 语句
strSQL = "Select distinct 职称 from teacher" ' 本行需补充代码
rs.Open strSQL, CurrentProject.Connection, 2, 2 ' 本行需补充代码 Do While Not rs.EOF
Select Case rs("职称")
Case "教授"
Check1.Value = True
Case "副教授"
Check2.Value = True
Case "讲师"
Check3.Value = True
Case "助教"
Check4.Value = True
End Select
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub ' 本行需补充代码 ' 本行需补充代码 ' 本行需补充代码