1、FontItalic(True)命令按钮1Name(Command1)确定(&O)命令按钮2Name(Command2)结束(&X)过程设计如下:Private sub Form_Click() Command2.Enabled = FalseEen SubPrivate Sub Command1_Click() Label2.Visible = False Label1.Caption = Text1.Text + : 欢迎使用 + Label1.Caption Text1.Visible = False Command1.Enabled = False: Command2.Enabled
2、= TrueEnd SubPrivate Sub Command2_Click() End程序2界面设计略,过程设计如下:Private Sub Command1_Click() 字体变大 Form1.FontSize = Form1.FontSize + 3 Form1.Cls: Print 欢迎使用VBPrivate Sub Command2_Click() 字体变小 Form1.FontSize = Form1.FontSize - 3 Private Sub Command3_Click() 字体加粗 Form1.FontBold = TruePrivate Sub Command4_
3、Click() 字体不加粗 Form1.FontBold = False运行时,不得连续、过多次单击“字体变小”按钮,因为当FontSize属性值小于0会产生适时错误。程序3界面设计略,过程设计如下(窗体Height值的计量包括标题、边框,而ScaleHeight值仅与窗体有效绘图区域的高度有关):Private Sub Form_Load() Text1.Text = Visual Basic 程序设计Private Sub Form_Resize() Text1.Top = 0: Text1.Left = 0 Text1.Width = Form1.ScaleWidth/2 用 Form1
4、.ScaleWidth效果优于用Form1. Width Text1.Height = Form1.ScaleHeight/2 用 Form1.ScaleHeight优于用Form1. Height Command1.Top = Form1.ScaleHeight - Command1.Height Command1.Left = Form1.ScaleWidth - Command1.Width第2章 程序设计基础1 2 3 4 5 6 7 8 9 101B 2D 3A 4C 5C 6B 7A 8D 9. C 10A1String 24 3aaa 4145 56 63 718 8False9
5、(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界面设计略,过程设计如下:方法一、用文本框控件输入圆的半径 Dim x As Single x = Text1.Text Label1.Caption = x * x * 3.141593方法二、用InputBox函数输入圆的半径 Dim x As Single 若要求计算结果具有15位有效位数,声明x为Double类型 x = InputBox(r=
6、,输入圆的半径程序2略。第3章 结构化程序设计与数组 3 4 7 8 9 101A 2D 3C 4C 5D 6B1If xy Then t=y: y=x: x=t 2IS3For i = 0 to 9: B(i) = InputBox(B( & i & )=): Next i4Dim 5String 68四、程序阅读题(写出下列程序的运行结果)程序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
7、 + 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六、程序设计题Private Sub Form_Click() Dim x As Integer, y As Integer, z As Integer Dim max As Integer, midd As Integer, min As Integer请输入x的值: y = InputBox(请输入y的值: z = InputBox(请输入z的值: If x y Then max = x Else max
8、 = y If z max Then max = z If x y Then min = x Else min = y If z = 1 Then y = x * x 0 Then y = Sqr(x) Else y = 0 End If Print y程序3界面设计略,过程设计如下: 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程序4界面设计略,过程设计如下: Dim x As Single, s As Single, t As S
9、ingle Dim i As Integer, n As Integer n = InputBox(请输入n的值: t = x / 2: s = t For i = 3 To n t = t * x / i s = s + t Print s程序5界面设计略,过程设计如下: 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 e程序6界面设计略,过程设计如下:Option Base 1 Dim n As
10、 Integer, a(9, 9) As Integer, i As Integer, j As Integer On Error GoTo k 下列代码中若出现错误,转到标号为K的语句执行。请输入n,0n10 For i = 1 To n: a(i, 1) = 1: a(i, i) = 1: For j = 2 To i - 1 a(i, j) = a(i - 1, j - 1) + 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
11、(i, j); Trim(Str(a(i, j); Exit Subk: MsgBox 输入n值小于1或大于10,数组下标超界。第4章 函数与过程1 2 3 8二、填空题1按地址传送 2b() As Long 36 4按值传递 5按地址传递6Public x As Single 7Static x 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 Mo
12、d 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 End Sub第5章 常用控件 2 4 5 8 910 11 12 13 14 15 16 17 1819 20 21 22 23 24 251C 2D 3B 4B 5B 6C 7B 8B 9B 10A11D 12C 13B 14B 15A 16D 17B 18B 19B 20A1上、下、左、左 2缇、无关 3&、+ 4Enabled 5MaxLength6Text1.SetFocu
13、s 7MultiLine 8Visible 9Alignment 10AutoSize11ForeColor 120或1 13True 141 15AddItem161 17List1.Clear 18文本框、列表框19下拉式组合框、简单组合框、下拉式列表框 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
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.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差!重新开始 Ca
15、ll Form_Load If m num Then Label1.Caption = Str(m) &大了! ElseIf m 小了! If rec 5 Then 好!猜对了。还行!程序5界面设计如图10-3所示,过程设计如下: Command1(0).Enabled = False: Command1(1).Enabled = False Command1(2).Enabled = False:Private Sub Command1_Click(Index As Integer) Select Case Index Case 0 Clipboard.Clear: Clipboard.Se
16、tText Text1.SelText Text1.SelText = 请选择要粘贴的位置! Command1(2).Enabled = True Case 1 Command1(0).Enabled = False Command1(1).Enabled = False: Case Else Text1.SelText = Clipboard.GetText(): Form_Load粘贴完成! End SelectPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, _X As Single, Y As Single) Dim n As In
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1