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 Su
3、bPrivate 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.Fon
4、tSize + 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 C
8、ommand1_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 Integer
12、, 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 As
15、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 7 8
16、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)Command2
18、.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.Caption =
19、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 Form_
21、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 Combo
22、1.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 SelectE
23、nd 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 = Len(T
24、ext1.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 = 十六进制 Optio
25、n1(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 = 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 (ScaleLe