2022年VisualBasic程序设计基础课后习题参考答案_第1页
2022年VisualBasic程序设计基础课后习题参考答案_第2页
2022年VisualBasic程序设计基础课后习题参考答案_第3页
2022年VisualBasic程序设计基础课后习题参考答案_第4页
2022年VisualBasic程序设计基础课后习题参考答案_第5页
已阅读5页,还剩56页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、第1章 Visual Basic 6.0程序设计概述一、判断题1 23 阐明:同类控件(如两个标签)互相重叠,设计时可以设立“置前”、“置后”属性。4 5 6 7 8 9 10 11 1213 14 15 16 17 18 19 20二、选择题1. C 2. B 3D 4C 5B 6A 7D 8A 9B 10A 11C 12D三、填空题1对象、事件 2属性、措施、事件 3控件、屏幕(Screen)4对象 5Left、Top 6属性、.=7网格 8Form19Load或Initialize或Resize或Activate(自动执行旳先后顺序也按此排列)10Activate、Deactivate四

2、、程序设计题程序1界面设计参看图10-1、10-2以及表10-1。表10-1 实例2各控件旳重要属性设立控件属性(属性值)属性(属性值)标签控件1Name(Label1)Caption(我旳第一种VB程序)标签控件2Name(Label2)Caption(请输入你旳姓名)FontUnderLine(True)FontItalic(True)命令按钮1Name(Command1)Caption(拟定(&O)命令按钮2Name(Command2)Caption(结束(&X)过程设计如下:Private sub Form_Click() Command2.Enabled = FalseEen Sub

3、Private Sub Command1_Click() Label2.Visible = False Label1.Caption = Text1.Text + : 欢迎使用 + Label1.Caption Text1.Visible = False Command1.Enabled = False: Command2.Enabled = TrueEnd SubPrivate Sub Command2_Click() EndEnd Sub程序2界面设计略,过程设计如下:Private Sub Command1_Click() 字体变大 Form1.FontSize = Form1.Font

4、Size + 3 Form1.Cls: Print 欢迎使用VBEnd SubPrivate Sub Command2_Click() 字体变小 Form1.FontSize = Form1.FontSize - 3 Form1.Cls: Print 欢迎使用VBEnd SubPrivate Sub Command3_Click() 字体加粗 Form1.FontBold = True Form1.Cls: Print 欢迎使用VBEnd SubPrivate Sub Command4_Click() 字体不加粗 Form1.FontBold = False Form1.Cls: Print

5、欢迎使用VBEnd Sub运营时,不得持续、过多次单击“字体变小”按钮,由于当FontSize属性值不不小于0会产生适时错误。程序3界面设计略,过程设计如下(窗体Height值旳计量涉及标题、边框,而ScaleHeight值仅与窗体有效绘图区域旳高度有关):Private Sub Form_Load() Text1.Text = Visual Basic 程序设计End SubPrivate Sub Form_Resize() Text1.Top = 0: Text1.Left = 0 Text1.Width = Form1.ScaleWidth/2 用 Form1.ScaleWidth效果优

6、于用Form1. Width Text1.Height = Form1.ScaleHeight/2 用 Form1.ScaleHeight优于用Form1. Height Command1.Top = Form1.ScaleHeight - Command1.Height Command1.Left = Form1.ScaleWidth - Command1.WidthEnd Sub第2章 程序设计基本一、判断题1 2 3 4 5 6 7 8 9 10二、选择题1B 2D 3A 4C 5C 6B 7A 8D 9. C 10A三、填空题1String 24 3aaa 4145 56 63 718

7、 8False9(x Mod 10) * 10 + x 10 1010 + Int( Rnd * 90 ) 11a * b Mod c12Log(x)+Sin(3.141593/6) 13Const PI=3.1415926 14日期 15Int(x)+1四、程序设计题程序1界面设计略,过程设计如下:措施一、用文本框控件输入圆旳半径Private Sub Command1_Click() Dim x As Single x = Text1.Text Label1.Caption = x * x * 3.141593End Sub措施二、用InputBox函数输入圆旳半径Private Sub

8、Command1_Click() Dim x As Single 若规定计算成果具有15位有效位数,声明x为Double类型 x = InputBox(r=,输入圆旳半径) Label1.Caption = x * x * 3.141593End Sub程序2略。第3章 构造化程序设计与数组一、判断题1 2 3 4 5 6 7 8 9 10二、选择题1A 2D 3C 4C 5D 6B三、填空题1If xy Then t=y: y=x: x=t 2IS3For i = 0 to 9: B(i) = InputBox(B( & i & )=): Next i4Dim 5String 68四、程序阅

9、读题(写出下列程序旳运营成果)程序1. 0 5 程序2. 20 程序3. 2 4 7 11 16程序4. 1 4 9 16 25程序5. 程序6. 五、程序填空题1(1)q * i (2)s + p * i / q (3)Next i2(1)r = 0 (2)m Mod n3(1)i + j - 1 (2)7 - i (3)Print4(1)10 + Int(Rnd * 90) (2)i + 1 To 30 (3)a(i)=a(j) (4)a(i) Mod 2 = 1六、程序设计题程序1界面设计略,过程设计如下:Private Sub Form_Click() Dim x As Integer

10、, y As Integer, z As Integer Dim max As Integer, midd As Integer, min As Integer x = InputBox(请输入x旳值:) y = InputBox(请输入y旳值:) z = InputBox(请输入z旳值:) If x y Then max = x Else max = y If z max Then max = z If x y Then min = x Else min = y If z 3 Then y = x + 3 ElseIf x = 1 Then y = x * x ElseIf x 0 Then

11、 y = Sqr(x) Else y = 0 End If Print yEnd Sub程序3界面设计略,过程设计如下:Private Sub Form_Click() Dim i As Integer, j As Integer For i = 1 To 9 For j = 1 To 9 Print Tab(j - 1) * 4); i * j; Next j Print Next iEnd Sub程序4界面设计略,过程设计如下:Private Sub Form_Click() Dim x As Single, s As Single, t As Single Dim i As Intege

12、r, n As Integer x = InputBox(请输入x旳值:) n = InputBox(请输入n旳值:) t = x / 2: s = t For i = 3 To n t = t * x / i s = s + t Next i Print sEnd Sub程序5界面设计略,过程设计如下:Private Sub Form_Click() Dim e As Single, t As Single, i As Integer e = 2: t = 1: i = 1 While t = 0.0001 i = i + 1: t = t / i: e = e + t Wend Print

13、 eEnd Sub程序6界面设计略,过程设计如下:Option Base 1Private Sub Form_Click() Dim n As Integer, a(9, 9) As Integer, i As Integer, j As Integer On Error GoTo k 下列代码中若浮现错误,转到标号为K旳语句执行。 n = InputBox(请输入n,0n10) For i = 1 To n: a(i, 1) = 1: a(i, i) = 1: Next i For i = 3 To n For j = 2 To i - 1 a(i, j) = a(i - 1, j - 1)

14、 + a(i - 1, j) Next j, i For i = 1 To n Print Tab(30 - 2 * i); For j = 1 To i Print Space(4 - Len(Trim(Str(a(i, j); Trim(Str(a(i, j); Next j Print Next i Exit Subk: MsgBox 输入n值不不小于1或不小于10,数组下标超界。End Sub第4章 函数与过程一、判断题1 2 3 4 5 6 7 8二、填空题1按地址传送 2b() As Long 36 4按值传递 5按地址传递6Public x As Single 7Static x

15、 As Integer 8Form2.y三、程序阅读题(写出下列程序旳运营成果)程序1. s = 2 程序2. 1 程序3. 1 1 2 1 1 2 1 2 2 2 2 3 s = 5 1 1 s = 9 1 2 1 1 3 3 1 1 4 6 4 1四、程序填空题1(1)ByeVal (2)k Mod i (3)k = k i (4)Call pp(i)2(1)a() Aa Double (2)n-1 (3)a(j) Abs(xmax) Then xmax = x(i, j): ki = i: kj = j Next j, i End Sub第5章 常用控件一、判断题1 2 3 4 5 6

16、7 8 910 11 12 13 14 15 16 17 1819 20 21 22 23 24 25二、选择题1C 2D 3B 4B 5B 6C 7B 8B 9B 10A11D 12C 13B 14B 15A 16D 17B 18B 19B 20A三、填空题1上、下、左、左 2缇、无关 3&、+ 4Enabled 5MaxLength6Text1.SetFocus 7MultiLine 8Visible 9Alignment 10AutoSize11ForeColor 120或1 13True 141 15AddItem161 17List1.Clear 18文本框、列表框19下拉式组合框、

17、简朴组合框、下拉式列表框 20Scroll 21Value22Change 23定期器不起作用 24Timer 2565535四、程序阅读题程序1. 116 程序2. 8程序3. 23451 程序4. 小,你好! 程序5. 您好34512 小李,你好! 欢迎使用Visual Basic!程序6. 李子 程序7.y = 6 程序8.n = 1苹果 y = 14 n = 3 橘子 n = 5 葡萄 柚子 香蕉五、程序填空题1(1)a(i) = Mid(str1, i, 1) 或 a(i) = Mid(Text1.Text, i, 1) (2)p = j (3)a(i) = a(p) (4)Comm

18、and2.Enabled = True2(1)1 To 2*i1 (2)Command2.Enabled = True (3)Command2.Enabled = False3(1)Text2.Enabled = False (2)p = 2 (3)Print i (4)Val(Text1.Text) 2 或 Val(Text1.Text) 10 Then Label1.Caption = 差!重新开始: Call Form_Load Else If m num Then Label1.Caption = Str(m) & 大了! ElseIf m num Then Label1.Captio

19、n = Str(m) & 小了! Else If rec 0 Then Label1.Caption = 选择了 & n & 个字,请选择下一步操作! Command1(0).Enabled = True: Command1(1).Enabled = True Else Label1.Caption = End IfEnd Sub程序6界面设计如图10-4所示,过程设计如下:Private Sub Form_Load() Label1.Caption = 目前日期:: Text1.Text = Date Option1(0).Caption = 显示日期: Option1(1).Caption

20、 = 显示时间 Option1(0).Value = True: Command1.Caption = 退出End SubPrivate Sub Option1_Click(Index As Integer) Select Case Index Case 0 Label1.Caption = 目前日期:: Text1.Text = Date Case 1 Label1.Caption = 目前时间:: Text1.Text = Time End SelectEnd SubPrivate Sub Command1_Click() EndEnd Sub程序7过程设计如下:Private Sub F

21、orm_Load() Label1.Caption = 目前日期:: Text1.Text = Date Option1(0).Caption = 显示日期: Option1(1).Caption = 显示时间 Option1(0).Value = True: Command1.Caption = 退出 Combo1.AddItem 年-月-日: Combo1.AddItem 月-日-年 Combo1.AddItem 日-月-年: Combo1.Text = 年-月-日End SubPrivate Sub Combo1_Click() Dim n As String Select Case C

22、ombo1.ListIndex Case 0: n = yyyy-mm-dd Case 1: n = mm-dd-yyyy Case 2: n = dd-mm-yyyy End Select Text1.Text = Format(Date, n)End SubPrivate Sub Option1_Click(Index As Integer) Select Case Index Case 0: Label1.Caption = 目前日期:: Text1.Text = Date Case 1: Label1.Caption = 目前时间:: Text1.Text = Time End Sel

23、ectEnd SubPrivate Sub Command1_Click() EndEnd Sub程序8. 界面设计如图10-5所示,过程设计如下:Private Sub Form_Load() List1.AddItem happy: List1.AddItem apple List1.AddItem student: List1.AddItem computerEnd SubPrivate Sub Command1_Click() List1.AddItem Text1.Text: Text1.SetFocus Text1.SelStart = 0: Text1.SelLength = L

24、en(Text1.Text)End SubPrivate Sub Command3_Click() List1.ClearEnd SubPrivate Sub Command4_Click() EndEnd SubPrivate Sub Command2_Click() If List1.ListIndex -1 Then List1.RemoveItem List1.ListIndexEnd Sub9界面设计如图10-6所示,过程设计如下:Private Sub Form_Load() Option1(0).Caption = 八进制: Option1(1).Caption = 十六进制 O

25、ption1(2).Caption = 二进制End SubPrivate Function tran(k As Long, n As Integer) As String Dim x As Integer, y As String * 1, k1 As Long tran = : k1 = Abs(k) Do While k1 0 x = k1 Mod n If x = 10 Then y = Chr(Asc(A) + x - 10) Else y = CStr(x) tran = y + tran k1 = k1 n Loop If k = 72 Then Timer1.Enabled =

26、 FalseEnd Sub第6章 图形控件和图形措施一、判断题1 2 3 4 5 6 7 8 9 10二、选择题1C 2B 3C 4A 5A 6C 7A 8C 9C 10B11A 12B 13B 14C 15C三、填空题1 Circle (ScaleLeft + ScaleWidth / 2, ScaleTop + ScaleHeight / 2), 8002LoadPicture 3AutoSize、Stretch、False、False 4选中、属性5形状、矩形 6Picture1.Picture=LodePicture(C:WindowsCloud.bmp)7图片框、其她控件 8缇、Sc

27、laeMode 9颜色10颜色、圆弧起点处转角、圆弧终点处转角、椭圆纵轴与横轴长度之比四、程序阅读题程序1. 转动一条红色直线,其轨迹形成一种圆程序2. 在窗体上随机旳位置、用随机旳颜色、半径绘制1000个空心旳圆。程序3. 在图片框内绘制多种黄色边框矩形,填充样式在“实心”、“透明”间交替变换。五、程序填空题1(1)Combo1.ListIndex (2)Shape1.BorderStyle (3)Combo2.AddItem Str(i)2(1)Call pic (2)False (3)n = n + 1(4)LoadPicture(c:windows1.bmp) (4)LoadPictu

28、re(fn)六、程序设计题程序1界面设计略,过程设计如下:Private Sub Form_Load() Picture1.ScaleMode = 3End SubPrivate Sub Command1_Click() Dim x1 As Single, y1 As Single, x2 As Single, y2 As Single x1 = InputBox(x1=): y1 = InputBox(y1=) x2 = InputBox(x2=): y2 = InputBox(y2=) Picture1.Line (x1, y1)-(x2, y2), , BEnd Sub程序2界面设计略,

29、过程设计如下:Private Sub Form_click() Dim r As Single, xo As Single, yo As Single If Form1.ScaleHeight Form1.ScaleWidth Then r = Form1.ScaleHeight / 3 Else r = Form1.ScaleWidth / 3 End If xo = Form1.ScaleLeft + Form1.ScaleWidth / 2 yo = Form1.ScaleTop + Form1.ScaleHeight / 2 Form1.FillStyle = 0: Form1.Fil

30、lColor = vbBlue Form1.DrawWidth = 2: Form1.ScaleMode = 6 Form1.Circle (xo, yo), r, vbYellowEnd Sub程序3界面设计略,过程设计如下:Private Sub Form_Load() Dim i As Integer For i = 1 To 7: List1.AddItem i: Next i Form1.ScaleMode = 1End SubPrivate Sub List1_Click() Form1.Cls: Form1.ScaleMode = List1.Text Form1.Circle

31、(Form1.ScaleLeft + Form1.ScaleWidth / 2, _ Form1.ScaleTop + Form1.ScaleHeight / 2), 50End Sub第7章 对话框与菜单程序设计一、判断题1 2 3 4 5 6 7 8 9 10二、选择题1D 2A 3C 4C 5B 6D 7A 8B 9D 10B三、填空题1窗体控制菜单、下拉式菜单、快捷菜单 2ShowFont3打开文献、另存为、颜色、字体、打印对话框 4工程、部件5CommonDialog1.Action =3、CommonDialog1.ShowColor6提示信息、对话框类型、对话框标题 7Click

32、8工具 9代码窗口、Click 10相似、正四、程序阅读题程序1. 显示提示信息为“5”、标题为“na旳输出成果”、有一种“拟定”按钮旳消息框。程序2. 显示提示信息为“您选择了第1项”、标题为“第一项”、有一种“拟定”按钮旳消息框。五、程序填空题1(1)Int(Rnd*100) (2)Str(i) (3)Exit For 2(1)False (2)Date (3)CommonDialog1.Color (4)m1六、程序设计题程序1界面设计略,过程设计如下:Private Sub Command1_Click()CommonDialog1.ShowOpenList1.AddItem Comm

33、onDialog1.FileNameEnd Sub程序2界面设计略,过程设计如下:Private Sub Command1_Click()CommonDialog1.ShowSaveList1.AddItem CommonDialog1.FileNameEnd Sub程序3界面设计如图10-9、表10-2所示,过程设计如下:Private Sub Sqr_Click() Shape1.Shape = 1End SubPrivate Sub Rec_Click() Shape1.Shape = 0End SubPrivate Sub Oval_Click() Shape1.Shape = 2En

34、d SubPrivate Sub Circle_Click() Shape1.Shape = 3End SubPrivate Sub Rrec_Click() Shape1.Shape = 4End SubPrivate Sub RSqr_Click() Shape1.Shape = 5End SubPrivate Sub Shp_Click() Shape1.FillStyle = 2End SubPrivate Sub Shzh_Click() Shape1.FillStyle = 3End SubPrivate Sub Xiex_Click() Shape1.FillStyle = 4E

35、nd SubPrivate Sub ShPJ_Click() Shape1.FillStyle = 6End SubPrivate Sub XJ_Click() Shape1.FillStyle = 7End SubPrivate Sub FillColor_Click() CommonDialog1.ShowColor Shape1.FillColor = CommonDialog1.ColorEnd SubPrivate Sub Exit_Click() EndEnd Sub第8章 文 件一、判断题1 2 3 4 5 6 7 89 10 11 12 13 14 15二、选择题1A 2C 3

36、B 4B 5A 6C 7C 8B9C 10B 11D 12B 13B三、填空题1ChDir 2FileLen 3Change 4EOF 5Line Input四、程序阅读题程序1.y= 1 a= 1 程序2. NO. 1 3 程序3. y= 3 a= 2 NO. 2 4 窗体:36 25 16 9 4 1 y= 6 a= 3 NO. 3 7 文献:1 4 9 16 25 36 y= 10 a= 4 NO. 4 11程序4. 程序5. 1 程序6. 1 窗体上显示内容:20 2 2 1 2 文献中内容:4 6 8 10 12 3 3 3 1 2 3 4 4 4 4 5 5 5 5 5五、程序填空

37、题1(1)Dim n As Integer (2)C:windowscalc.exe (3)Output (4)End2(1)For Output As #2 (2)0 (3)temp.dat As c:a1.dat3(1)Open e:dataout.txt For Output As #1 (2)t1 Mod t2 = 0 (3)If flag Then (4)Print coun六、程序设计题程序1界面设计如图10-10所示,过程设计如下:Dim fn As StringPrivate Sub Drive1_Change() Dir1.Path = Drive1.DriveEnd Sub

38、Private Sub Dir1_Change() File1.Path = Dir1.PathEnd SubPrivate Sub File1_Click() If Right(File1.Path, 1) = Then fn = File1.Path + File1.FileName Else fn = File1.Path + + File1.FileName End IfEnd SubPrivate Sub Command1_Click() Dim yesno As Byte yesno = MsgBox(确认要删除吗?, vbYesNo, 删除文献) If yesno = vbYes

39、 Then Kill fn File1.RefreshEnd Sub程序2建立4个文本框控件依次输入姓名、出生年月、外语、计算机成绩,按“确认”按钮追加该记录到磁盘文献d:student.dat。过程设计如下:Private Sub Command1_Click() Dim b As Date, m As Byte, e As Byte Open d:student.dat For Append As #1 b = Text2.Text: m = Text3.Text: e = Text4.Text Write #1, Text1.Text, b, m, e Text1.Text = : Te

40、xt2.Text = : Text3.Text = : Text4.Text = Close #1End Sub程序3界面设计如图10-11所示,过程设计如下:Private Sub Form_Load() Dim ss As String Open e:student.txt For Append As #1如文献不存在则先建立该文献 Close #1 Open d:student.dat For Input As #1 将文献中所有记录在列表框中显示 While Not EOF(1) Line Input #1, ss: List1.AddItem ss Wend Close #1 在选中

41、表项之前“删除”、“修改”按钮不可用 Command2.Enabled = False: Command3.Enabled = FalseEnd SubPrivate Sub List1_Click() 选中表项后可“删除”或“修改”,不可“追加”。 Command1.Enabled = False: Command2.Enabled = True Command3.Enabled = True: Text1.Text = List1.TextEnd SubPrivate Sub Command1_Click() 追加记录 If Trim(Text1.Text) Then List1.AddI

42、tem Text1.Text Text1.Text = End SubPrivate Sub Command2_Click() 修改记录 List1.AddItem Text1.Text, List1.ListIndex List1.RemoveItem List1.ListIndex Command1.Enabled = True: Command2.Enabled = False Command3.Enabled = False: Text1.Text = 修改后,不可“删除”、“修改”End SubPrivate Sub Command3_Click() 删除记录 List1.Remov

43、eItem List1.ListIndex 删除后,不可“删除”、“修改” Command1.Enabled = True: Command2.Enabled = False Command3.Enabled = False: Text1.Text = End SubPrivate Sub Command4_Click() 保存文献,将列表框中所有表项输出到文献 Dim i As Integer Open d:student.dat For Output As #1 For i = 0 To List1.ListCount - 1: Print #1, List1.List(i): Next

44、i Close #1End SubPrivate Sub Command5_Click() 退出之前先保存文献 Call Command4_Click: EndEnd Sub第9章 数据库与数据访问技术一、判断题1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18.19. 20. 21. 22.二、选择题1.A 2.D 3.C 4.B 5.C 6.A 7.C 8.D9.D 10.C 11.A 12.D 13.A 14.B 15.B 16.C三、程序设计题程序1. (1)数据访问控件以及数据绑定控件旳有关属性设立如下Data1

45、:Connect(Access)、DatabaseName(d:学籍.mdb)、RecordSource(学生)Text1:DataSource(Data1)、DataField(学号)Text2:DataSource(Data1)、DataField(姓名)Check1:DataSource(Data1)、DataField(性别)Text3:DataSource(Data1)、DataField(出生日期)Text4:DataSource(Data1)、DataField(奖学金)Text5:DataSource(Data1)、DataField(简历)OLE1:DataSource(Da

46、ta1)、DataField(照片)Adodc1:ConnectionString(Provider = Microsoft.Jet.OLEDB.4.0; _Data Source = E:GYHVB学籍1b.mdb; Persist Security Info = False)CommandType(1-adCmdText)、RecordSource(select * from 成绩)DataGrid1:DataSource(Adodc1)(2)重要事件过程代码Option ExplicitPrivate Sub Form_Load()Caption = 学籍信息编辑浏览Label1.Cap

47、tion = 学号: : Label2.Caption = 姓名:Label3.Caption = 出生年月: : Label4.Caption = 奖学金:Label5.Caption = 简历: : Label6.Caption = 照片:Check1.Caption = 性别(选中表达男,否则为女)Label7.Caption = 成绩信息查询显示: Adodc1.Visible = FalseEnd SubPrivate Sub Data1_Reposition()Adodc1.RecordSource = select 成绩.课程号,课程名,成绩 from 学生,课程,成绩 _& w

48、here 学生.学号 = 成绩.学号 and & 成绩.课程号 = 课程.课程号 and & _成绩.学号= & Data1.Recordset(学号) & & order by 成绩.课程号Label7.Caption = Trim(Data1.Recordset(姓名) & 成绩信息查询显示Adodc1.RefreshEnd Sub程序2. (1)数据访问控件以及数据绑定控件旳有关属性设立如下:Adodc1:ConnectionString(Provider=Microsoft.Jet.OLEDB.4.0; _Data Source = E:GYHVB学籍1b.mdb; Persist S

49、ecurity Info = FalseCommandType(1-adCmdText)、RecordSource(select * from 学生)DataGrid1:DataSource(Adodc1)(2)重要事件过程代码Option ExplicitPrivate Sub Form_Load()Dim i As IntegerCaption = 学籍信息查询浏览: Adodc1.Visible = FalseLabel1.Caption = 选择查询方式:: Combo1.Text = 所有都显示Label2.Caption = 所有表文献数据浏览表格: : Label3.Visibl

50、e = FalseText1.Visible = False: Text1.Text = For i = 0 To 2 Combo1.AddItem Mid(所有都显示按学号查询按姓名查询, 5 * i + 1, 5)Next iEnd SubPrivate Sub Combo1_Click()Select Case Combo1.ListIndexCase 0 Text1.Visible = False: Label3.Visible = False Adodc1.RecordSource = select * from 学生 Label2.Caption = 所有表文献数据浏览表格:: A

51、dodc1.RefreshCase 1 Label3.Caption = 输入查询条件(学号): : Text1.Visible = True Label3.Visible = True: Text1.SetFocusCase 2 Label3.Caption = 输入查询条件(姓名): : Text1.Visible = True Label3.Visible = True: Text1.SetFocusEnd SelectEnd SubPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)If KeyCode = vb

52、KeyReturn Then If Combo1.ListIndex = 1 Then Adodc1.Recordset.MoveFirst Adodc1.Recordset.Find 学号= & Text1.Text & If Adodc1.Recordset.EOF Then Adodc1.RecordSource = select * from 学生 Label2.Caption = 所有表文献数据浏览表格: Adodc1.Refresh: MsgBox 查无此人! Else Adodc1.RecordSource = select * from 学生 & where _学号= & Te

53、xt1.Text & Label2.Caption = 学生 + Text1.Text + 旳数据浏览表格: End If Else Adodc1.Recordset.MoveFirst Adodc1.Recordset.Find 姓名= & Text1.Text & If Adodc1.Recordset.EOF Then Adodc1.RecordSource = select * from 学生 Label2.Caption = 所有表文献数据浏览表格: Adodc1.Refresh: MsgBox 查无此人! Else Adodc1.RecordSource = select * fr

54、om 学生 & _where 姓名= & Text1.Text & End If End If Adodc1.RefreshEnd IfEnd Sub程序3. (1)数据访问控件以及数据绑定控件旳有关属性设立如下:Adodc1(xs):ConnectionString(Provider=Microsoft.Jet.OLEDB.4.0; _Data Source = E:GYHVB学籍1b.mdb; Persist Security Info=False)CommandType(2-adCmdTable)、RecordSource(学生)Adodc2(kc):ConnectionString(P

55、rovider=Microsoft.Jet.OLEDB.4.0; _Data Source = E:GYHVB学籍1b.mdb; Persist Security Info=False)CommandType(2-adCmdTable)、RecordSource(课程)Adodc3(cjcx):ConnectionString(Provider=Microsoft.Jet.OLEDB.4.0; _Data Source = E:GYHVB学籍1b.mdb; Persist Security Info=False)CommandType(1-adCmdText)RecordSource( sel

56、ect 成绩.学号,学生.姓名,成绩.课程号,课程.课程名, _成绩.成绩 from 学生,课程,成绩 where 成绩.课程号 = 课程.课程号 _and 成绩.学号 = 学生.学号 DataGrid1:DataSource(cjcx)DataList1:RowSource(xs)、ListField(姓名)、BoundColumn(学号)DataList2:RowSource(kc)、ListField(课程名)、BoundColumn(课程号)(2)重要事件过程代码Option ExplicitDim p As BytePrivate Sub Form_Load()Dim i As In

57、tegerFor i = 0 To 4 Label1(i).Caption = Mid(优秀良好中档及格差等, 2 * i + 1, 2) Text1(i).Text = : Text1(i).BackColor = RGB(205, 205, 192) Text1(i).Locked = TrueNext icjcx.RecordSource = select 成绩.学号,学生.姓名,成绩.课程号,课程.课程名, _& 成绩.成绩from 学生,课程,成绩 & _where 成绩.课程号=课程.课程号 and 成绩.学号=学生.学号cjcx.Refresh: Label2.Caption =

58、 成绩信息列表Label3.Caption = 选择学生姓名: : Label4.Caption = 选择课程名:xs.Visible = False: kc.Visible = False: cjcx.Visible = FalseCaption = 学籍信息查询: p = 0End SubPrivate Sub DataList1_Click()p = 0: Call cjdctjEnd SubPrivate Sub DataList2_Click()p = 1: Call cjdctjEnd SubPrivate Sub cjdctj()Dim cjdcjs(5) As Integer,

59、 dcase As Byte, i As ByteIf p = 0 Then cjcx.RecordSource = select 成绩.学号,学生.姓名,成绩.课程号, _& 课程.课程名,成绩.成绩 from 学生,课程,成绩 _& where 成绩.学号= & DataList1.BoundText & _& and (成绩.课程号=课程.课程号 and _& 成绩.学号=学生.学号) order by 成绩.课程号 Frame1.Caption = 单位:门 Label2.Caption = Trim(DataList1.Text) & 成绩信息列表Else cjcx.RecordSo

60、urce = select 成绩.学号,学生.姓名,成绩.课程号, _& 课程.课程名,成绩.成绩 from 学生,课程,成绩 _& where成绩.课程号= & DataList2.BoundText & _& and (成绩.课程号=课程.课程号 and _& 成绩.学号=学生.学号) order by 成绩.学号 Frame1.Caption = 单位:人 Label2.Caption = Trim(DataList2.Text) & 成绩信息列表End Ifcjcx.RefreshIf Not cjcx.Recordset.EOF Then cjcx.Recordset.MoveFir

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论